Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork12
A GitHub Action to automatically update a "Keep a Changelog" CHANGELOG with the latest release notes.
License
stefanzweifel/changelog-updater-action
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A GitHub Action to update a changelog with the latest release notes.
The Action …
- adds a new second level heading for the new release
- pastes your release notes in the appropriate place in
CHANGELOG.md
If your changelog follows the"Keep a Changelog" format and contains an "Unreleased"-heading, the Action will update the heading to point to the compare view between the latest version andHEAD. (Read more about thishere)
Don't want to use GitHub Actions? Checkout thechangelog-updater CLI that powers this Action.Want to learn more about this Action? Read myintroduction blog post.
The Action is best used in a Workflow that listens to therelease-event and the typereleased. This way, the name and body of your release will be added to the CHANGELOG.
The following is an example Workflow ready to be used.
The Workflow checks outthe target branch of the release, updates the./CHANGELOG.md-file with the name and the contents of the just released release and commits the changes back to your repository usinggit-auto-commit.
# .github/workflows/update-changelog.yamlname:"Update Changelog"on:release:types:[released]jobs:update:runs-on:ubuntu-latestpermissions:# Give the default GITHUB_TOKEN write permission to commit and push the# updated CHANGELOG back to the repository.# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/contents:writesteps: -name:Checkout codeuses:actions/checkout@v4with:ref:${{ github.event.release.target_commitish }} -name:Update Changeloguses:stefanzweifel/changelog-updater-action@v1with:latest-version:${{ github.event.release.tag_name }}release-notes:${{ github.event.release.body }} -name:Commit updated CHANGELOGuses:stefanzweifel/git-auto-commit-action@v5with:branch:${{ github.event.release.target_commitish }}commit_message:Update CHANGELOGfile_pattern:CHANGELOG.md
To generate the release notes automatically for you, I can recommend using therelease-drafter Action.
Note
When you use thepublish-input ofrelease-drafter to immediately create the release, therelease-event is probably not triggered due to a limitation of GitHub Actions.
Please create a personal access token, add it as a secret to your repository and pass the token to therelease-drafter/release-drafter-Action.Seethis discussion for more details.
The following workflow is a bit more advanced. It …
- extracts the exact release date from the git tag
- optionally, uses the target branch of the release in the "Unreleased" compare URL
- pushes the created commit to the target branch of the commit
Warning
DO NOT enable thecompare-url-target-revisionoption, if the target of your releases is the default branch (ref/heads/mainormain).The action would otherwise receiverefs/heads/mainas the target revision value and will generate invalid compare URLs.
Show update-changelog.yaml
# .github/workflows/update-changelog.yamlname:"Update Changelog"on:release:types:[released]jobs:update:runs-on:ubuntu-latestpermissions:# Give the default GITHUB_TOKEN write permission to commit and push the# updated CHANGELOG back to the repository.# https://github.blog/changelog/2023-02-02-github-actions-updating-the-default-github_token-permissions-to-read-only/contents:writesteps: -name:Checkout codeuses:actions/checkout@v4with:# Fetch entire history of repository to ensure release date can be# extracted from commit of the given tag.fetch-depth:0# Checkout target branch of this release. Ensures that the CHANGELOG# is not out of date.ref:${{ github.event.release.target_commitish }} -name:Extract release date from git tagid:release_daterun:| echo "date=$(git log -1 --date=short --format=%ad '${{ github.event.release.tag_name }}')" >> $GITHUB_OUTPUT; -name:Update Changeloguses:stefanzweifel/changelog-updater-action@v1with:# Pass extracted release date, release notes and version to the Action.release-date:${{ steps.release_date.outputs.date }}release-notes:${{ github.event.release.body }}latest-version:${{ github.event.release.tag_name }}# Optional# If your project keeps separate branches for major releases, and you want to point the compare URL# in the "Unreleased"-heading to the corresponding major release branch (eg. `2.x`), then enable the option# below.# `compare-url-target-revision` will change how the compare URL is composed and will replace# `v2.0.1...HEAD` with `v2.0.1...2.x`.# WARNING: When you select `main` when creating a new release, the value `refs/heads/main`# is passed to the Action which will generate an invalid compare URL.# compare-url-target-revision: ${{ github.event.release.target_commitish }} -name:Commit updated CHANGELOGuses:stefanzweifel/git-auto-commit-action@v5with:# Push updated CHANGELOG to release target branch.branch:${{ github.event.release.target_commitish }}commit_message:Update CHANGELOGfile_pattern:CHANGELOG.md
HannesWell uses the Action in a worfklow triggered by theworkflow_dispatch:See workflow.
The workflow …
- is manually triggered
- builds a Java project
- uses the content between the Unreleased and Previous Release heading as release notes and updates the CHANGELOG.md
- commits the changes and pushes them to GitHub
- creates a new GitHub release and points in the release notes to the right heading for the just released version
This workflow uses the output variables generated by this Action to accomplish this task.
Checkoutaction.yml for a full list of supported inputs.Check the README of theunderlying CLI to learn more about them.
At minimum, the Action requires an emptyCHANGELOG.md file to exist in your repository.When executed, the Action will place the release notes at the bottom of the document.If your changelog already contains asecond level heading, the Action will put the release notes above previous release notes in the document.
Your changelog will look something like this:
#Changelog##v1.1.0 - 2021-02-01###Added- New Feature A##v1.0.0 - 2021-01-01- Initial Release
If you want to learn more on how the Action determines the place for the release notes, read thenotes in the README of the CLI that powers this Action.
The Action exposes some outputs you can further use in your workflow. The Action currently supports the following outputs:
The generated compare URL for the just created release. For examplehttps://github.com/org/repo/compare/v1.0.0...v1.1.0.The value is only available, if the Action could generate a compare URL based on the available CHANGELOG data.
The URL fragment for the just created release. For example '#v100---2021-02-01'. You can use this to generate URLs that point to the newly created release in your CHANGELOG.
The generated compare URL between the latest version and the target revision. For examplehttps://github.com/org/repo/compare/v1.0.0...HEAD.The value is only available, if the Action could generate a compare URL based on the available CHANGELOG data.
Seeaction.yml for details.
See workflow below on how to use these output values in your workflow.
-name:Update Changeloguses:stefanzweifel/changelog-updater-action@v1id:"changelog-updater"with:# Pass extracted release date, release notes and version to the Action.release-date:${{ steps.release_date.outputs.date }}release-notes:${{ github.event.release.body }}latest-version:${{ github.event.release.tag_name }}compare-url-target-revision:${{ github.event.release.target_commitish }}-name:"release_compare_url"# https://github.com/org/repo/compare/v1.0.0...v1.1.0run:"echo ${{ steps.changelog-updater.outputs.release_compare_url }}"-name:"release_url_fragment"# #v100---2021-02-01run:"echo ${{ steps.changelog-updater.outputs.release_url_fragment }}"-name:"unreleased_compare_url"# https://github.com/org/repo/compare/v1.0.0...HEADrun:"echo ${{ steps.changelog-updater.outputs.unreleased_compare_url }}"
We useSemVer for versioning. For the versions available, see thetags on this repository.
We also provide major version tags to make it easier to always use the latest release of a major version. For example you can usestefanzweifel/changelog-updater-action@v1 to always use the latest release of the current major version.(More information about thishere.)
This project is licensed under the MIT License - see theLICENSE file for details.
About
A GitHub Action to automatically update a "Keep a Changelog" CHANGELOG with the latest release notes.
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.