|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + release: |
| 13 | + name: Generate changelog and publish release |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
| 21 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 22 | + |
| 23 | + # Generate the full CHANGELOG.md (all releases, written to file) |
| 24 | + - name: Generate full CHANGELOG.md |
| 25 | + uses: orhun/git-cliff-action@v4 |
| 26 | + with: |
| 27 | + config: cliff.toml |
| 28 | + args: --verbose |
| 29 | + env: |
| 30 | + OUTPUT: CHANGELOG.md |
| 31 | + GITHUB_REPO: ${{ github.repository }} |
| 32 | + |
| 33 | + # Generate release-only notes for the GitHub Release body |
| 34 | + - name: Generate release notes for this tag |
| 35 | + id: cliff |
| 36 | + uses: orhun/git-cliff-action@v4 |
| 37 | + with: |
| 38 | + config: cliff.toml |
| 39 | + args: --latest --strip all |
| 40 | + env: |
| 41 | + OUTPUT: /tmp/release-notes.md |
| 42 | + GITHUB_REPO: ${{ github.repository }} |
| 43 | + |
| 44 | + # Commit the updated CHANGELOG.md back to the default branch |
| 45 | + - name: Commit CHANGELOG.md |
| 46 | + run: | |
| 47 | + git config user.name "github-actions[bot]" |
| 48 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 49 | + git add CHANGELOG.md |
| 50 | + # Only commit if there are changes |
| 51 | + if ! git diff --cached --quiet; then |
| 52 | + git commit -m "chore(release): update CHANGELOG.md for ${{ github.ref_name }}" |
| 53 | + git push origin HEAD:refs/heads/main |
| 54 | + fi |
| 55 | +
|
| 56 | + # Create the GitHub Release with the generated notes |
| 57 | + - name: Create GitHub Release |
| 58 | + uses: softprops/action-gh-release@v2 |
| 59 | + with: |
| 60 | + name: ${{ github.ref_name }} |
| 61 | + tag_name: ${{ github.ref_name }} |
| 62 | + body_path: /tmp/release-notes.md |
| 63 | + draft: false |
| 64 | + prerelease: ${{ contains(github.ref_name, '-') }} |
0 commit comments