|
| 1 | +# .github/workflows/update-changelog.yaml |
| 2 | +name: "Update Changelog" |
| 3 | + |
| 4 | +on: |
| 5 | + release: |
| 6 | + types: [released] |
| 7 | + |
| 8 | +jobs: |
| 9 | + update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + permissions: |
| 13 | + # Give the default GITHUB_TOKEN write permission to commit and push the |
| 14 | + # updated CHANGELOG back to the repository. |
| 15 | + # https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/ |
| 16 | + contents: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v6 |
| 21 | + with: |
| 22 | + # Fetch entire history of repository to ensure release date can be |
| 23 | + # extracted from commit of the given tag. |
| 24 | + fetch-depth: 0 |
| 25 | + # Checkout target branch of this release. Ensures that the CHANGELOG |
| 26 | + # is not out of date. |
| 27 | + ref: ${{ github.event.release.target_commitish }} |
| 28 | + |
| 29 | + - name: Extract release date from git tag |
| 30 | + id: release_date |
| 31 | + run: | |
| 32 | + echo "date=$(git log -1 --date=short --format=%ad '${{ github.event.release.tag_name }}')" >> $GITHUB_OUTPUT; |
| 33 | +
|
| 34 | + - name: Update Changelog |
| 35 | + uses: stefanzweifel/changelog-updater-action@v1 |
| 36 | + with: |
| 37 | + # Pass extracted release date, release notes and version to the Action. |
| 38 | + release-date: ${{ steps.release_date.outputs.date }} |
| 39 | + release-notes: ${{ github.event.release.body }} |
| 40 | + latest-version: ${{ github.event.release.tag_name }} |
| 41 | + compare-url-target-revision: ${{ github.event.release.target_commitish }} |
| 42 | + |
| 43 | + # Optional |
| 44 | + # If your project keeps separate branches for major releases, and you want to point the compare URL |
| 45 | + # in the "Unreleased"-heading to the corresponding major release branch (eg. `2.x`), then enable the option |
| 46 | + # below. |
| 47 | + # `compare-url-target-revision` will change how the compare URL is composed and will replace |
| 48 | + # `v2.0.1...HEAD` with `v2.0.1...2.x`. |
| 49 | + # WARNING: When you select `main` when creating a new release, the value `refs/heads/main` |
| 50 | + # is passed to the Action which will generate an invalid compare URL. |
| 51 | + # compare-url-target-revision: ${{ github.event.release.target_commitish }} |
| 52 | + |
| 53 | + - name: "release_compare_url" |
| 54 | + # https://github.com/org/repo/compare/v1.0.0...v1.1.0 |
| 55 | + run: "echo ${{ steps.changelog-updater.outputs.release_compare_url }}" |
| 56 | + |
| 57 | + - name: "release_url_fragment" |
| 58 | + # #v100---2021-02-01 |
| 59 | + run: "echo ${{ steps.changelog-updater.outputs.release_url_fragment }}" |
| 60 | + |
| 61 | + - name: "unreleased_compare_url" |
| 62 | + # https://github.com/org/repo/compare/v1.0.0...HEAD |
| 63 | + run: "echo ${{ steps.changelog-updater.outputs.unreleased_compare_url }}" |
| 64 | + |
| 65 | + - name: Commit updated CHANGELOG |
| 66 | + uses: stefanzweifel/git-auto-commit-action@v7 |
| 67 | + with: |
| 68 | + # Push updated CHANGELOG to release target branch. |
| 69 | + branch: ${{ github.event.release.target_commitish }} |
| 70 | + commit_message: Update CHANGELOG |
| 71 | + file_pattern: CHANGELOG.md |
0 commit comments