|
| 1 | +name: Release and Changelog |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [created] |
| 6 | + workflow_dispatch: |
| 7 | + push: |
| 8 | + tags: |
| 9 | + - '[0-9]+.[0-9]+.[0-9]+' |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Git |
| 23 | + run: | |
| 24 | + git config user.name "github-actions[bot]" |
| 25 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 26 | +
|
| 27 | + - name: Get tag name |
| 28 | + id: tag |
| 29 | + run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 30 | + |
| 31 | + - name: Generate release notes |
| 32 | + id: release_notes |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const tag = process.env.GITHUB_REF_NAME; |
| 37 | + const { data: commits } = await github.rest.repos.listCommits({ |
| 38 | + owner: context.repo.owner, |
| 39 | + repo: context.repo.repo, |
| 40 | + per_page: 20, |
| 41 | + }); |
| 42 | +
|
| 43 | + const notes = commits.map(c => `- ${c.commit.message.split('\n')[0]}`).join('\n'); |
| 44 | + return notes; |
| 45 | +
|
| 46 | + - name: Create GitHub Release |
| 47 | + uses: softprops/action-gh-release@v2 |
| 48 | + with: |
| 49 | + tag_name: ${{ steps.tag.outputs.tag }} |
| 50 | + name: Release ${{ steps.tag.outputs.tag }} |
| 51 | + body: ${{ steps.release_notes.outputs.result }} |
| 52 | + |
| 53 | + - name: Update CHANGELOG.md |
| 54 | + run: | |
| 55 | + echo "## ${{ steps.tag.outputs.tag }}" >> CHANGELOG.md |
| 56 | + echo "" >> CHANGELOG.md |
| 57 | + echo "${{ steps.release_notes.outputs.result }}" >> CHANGELOG.md |
| 58 | + echo "" >> CHANGELOG.md |
| 59 | + git add CHANGELOG.md |
| 60 | + git commit -m "docs: update CHANGELOG for ${{ steps.tag.outputs.tag }}" |
| 61 | + git push origin HEAD |
0 commit comments