Skip to content

Merge pull request #32 from guimou/guimou-patch-1 #18

Merge pull request #32 from guimou/guimou-patch-1

Merge pull request #32 from guimou/guimou-patch-1 #18

Workflow file for this run

name: Release
on:
push:
branches: [main]
paths:
- 'CLAUDE_VERSION'
- 'Dockerfile'
- 'os-packages.txt'
- 'firewall-domains.txt'
- 'init-firewall.sh'
- 'ccbox'
jobs:
compute-tag:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
tag: ${{ steps.tag.outputs.tag }}
image_tag: ${{ steps.tag.outputs.image_tag }}
version: ${{ steps.tag.outputs.version }}
skip: ${{ steps.tag.outputs.skip }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine release tag
id: tag
run: |
VERSION=$(cat CLAUDE_VERSION | tr -d '[:space:]')
echo "version=${VERSION}" >> $GITHUB_OUTPUT
# Check if CLAUDE_VERSION was changed in this commit
if git diff HEAD~1 HEAD -- CLAUDE_VERSION | grep -q '^[+-][0-9]'; then
TAG="v${VERSION}"
IMAGE_TAG="${VERSION}"
else
# Find the highest existing suffix for this version
ESCAPED_VERSION=$(echo "$VERSION" | sed 's/\./\\./g')
LAST=$(git tag --list "v${VERSION}-*" | sed "s/v${ESCAPED_VERSION}-//" | sort -n | tail -1)
if [ -z "$LAST" ]; then
N=1
else
N=$((LAST + 1))
fi
TAG="v${VERSION}-${N}"
IMAGE_TAG="${VERSION}-${N}"
fi
echo "tag=${TAG}" >> $GITHUB_OUTPUT
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_OUTPUT
# Check if the tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "Tag ${TAG} already exists, skipping release"
else
echo "skip=false" >> $GITHUB_OUTPUT
echo "Will create release ${TAG} with image tag ${IMAGE_TAG}"
fi
build:
needs: compute-tag
if: needs.compute-tag.outputs.skip != 'true'
uses: ./.github/workflows/build-and-push.yml
with:
image_tag: ${{ needs.compute-tag.outputs.image_tag }}
secrets: inherit
release:
needs: [compute-tag, build]
if: needs.compute-tag.outputs.skip != 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ needs.compute-tag.outputs.tag }}"
IMAGE_TAG="${{ needs.compute-tag.outputs.image_tag }}"
# Find previous release tag for changelog range
PREV_TAG=$(git tag --list 'v*' --sort=-version:refname | head -1)
# Build release notes with PR-style content
NOTES="Container image: \`quay.io/guimou/ccbox:${IMAGE_TAG}\`"
NOTES="${NOTES}"$'\n\n'"## Changes"$'\n'
if [ -n "$PREV_TAG" ]; then
NOTES="${NOTES}$(git log "${PREV_TAG}..HEAD" --pretty=format:'- %s (%h)' --reverse)"
else
NOTES="${NOTES}$(git log --pretty=format:'- %s (%h)' --reverse)"
fi
gh release create "$TAG" \
--title "$TAG" \
--notes "$NOTES" \
--target "${{ github.sha }}"