|
| 1 | +# Release workflow — creates a git tag and GitHub Release when a PR |
| 2 | +# that changes the VERSION file is merged to main. |
| 3 | +# |
| 4 | +# HOW TO RELEASE: |
| 5 | +# 1. Bump the version in the VERSION file on your feature branch |
| 6 | +# 2. Merge the PR to main |
| 7 | +# 3. This workflow automatically creates the tag + release |
| 8 | +# |
| 9 | +# This eliminates manual tagging entirely. The VERSION file is the |
| 10 | +# single source of truth. |
| 11 | + |
| 12 | +name: Release |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: [main] |
| 17 | + paths: [VERSION] |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + release: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Read version |
| 32 | + id: version |
| 33 | + run: | |
| 34 | + VERSION=$(cat VERSION | tr -d '[:space:]') |
| 35 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 36 | + echo "tag=v${VERSION}" >> "$GITHUB_OUTPUT" |
| 37 | + echo "📦 Version: ${VERSION} → Tag: v${VERSION}" |
| 38 | +
|
| 39 | + - name: Check if tag already exists |
| 40 | + id: check |
| 41 | + run: | |
| 42 | + if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 43 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 44 | + echo "⚠️ Tag v${{ steps.version.outputs.version }} already exists — skipping" |
| 45 | + else |
| 46 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 47 | + fi |
| 48 | +
|
| 49 | + - name: Create tag |
| 50 | + if: steps.check.outputs.exists == 'false' |
| 51 | + run: | |
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 54 | + git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}" |
| 55 | + git push origin "${{ steps.version.outputs.tag }}" |
| 56 | +
|
| 57 | + - name: Generate release notes |
| 58 | + if: steps.check.outputs.exists == 'false' |
| 59 | + id: notes |
| 60 | + run: | |
| 61 | + # Get the previous tag |
| 62 | + PREV_TAG=$(git tag --sort=-version:refname | grep -v "${{ steps.version.outputs.tag }}" | head -1) |
| 63 | + echo "Previous tag: ${PREV_TAG:-none}" |
| 64 | +
|
| 65 | + if [ -n "$PREV_TAG" ]; then |
| 66 | + NOTES=$(git log "${PREV_TAG}..HEAD" --pretty=format:"- %s (%h)" --no-merges) |
| 67 | + else |
| 68 | + NOTES=$(git log --pretty=format:"- %s (%h)" --no-merges -20) |
| 69 | + fi |
| 70 | +
|
| 71 | + # Write to file to avoid escaping issues |
| 72 | + echo "$NOTES" > /tmp/release_notes.md |
| 73 | +
|
| 74 | + - name: Create GitHub Release |
| 75 | + if: steps.check.outputs.exists == 'false' |
| 76 | + uses: softprops/action-gh-release@v2 |
| 77 | + with: |
| 78 | + tag_name: ${{ steps.version.outputs.tag }} |
| 79 | + name: ${{ steps.version.outputs.tag }} |
| 80 | + body_path: /tmp/release_notes.md |
| 81 | + generate_release_notes: false |
0 commit comments