How to Generate a Changelog With conventional-changelog in GitHub Actions
The conventional-changelog CLI reads commits since the last tag and prepends a new release section to CHANGELOG.md using a preset such as angular.
Run npx conventional-changelog-cli -p angular -i CHANGELOG.md -s after tagging, then commit the updated file or include it in the release body.
Steps
- Check out with full history so all tags are visible.
- Run the CLI with
-p angular -i CHANGELOG.md -sto update in place. - Commit the changed file with a bot identity, or attach it to the release.
Workflow
.github/workflows/release.yml
on:
push:
tags: ['v*.*.*']
permissions:
contents: write
jobs:
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20
- run: npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -r 0
- run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -am "docs: update changelog" && git pushGotchas
-srewrites the file in place;-r 0regenerates every release section instead of just the latest.- The preset must match your commit convention or sections come out empty.
Related guides
How to Generate a Changelog With git-cliff in GitHub ActionsGenerate a changelog from Conventional Commits in GitHub Actions with orhun/git-cliff-action, driven by a cli…
How to Automate Releases With semantic-release in GitHub ActionsAutomate version bumps, tags, changelogs, and a GitHub Release in GitHub Actions with semantic-release, which…