Sub topic 12
Generating changelogs and releases from history
This chapter assumes you can write Conventional Commits (type, scope, description, body, footers), that you know how ! and BREAKING CHANGE mark breaking changes, and that you know how types map to MAJOR, MINOR and PATCH. It also assumes you can read a short shell script and a YAML file.
Earlier chapters showed that a structured message is easy for people to scan. This chapter covers the other benefit: a program can read the same messages. Release tooling uses them to choose the next version number, write release notes, and publish a release without anyone editing a changelog by hand.
What the tools read
A tool that works from Conventional Commits does four things:
- It finds the last release, usually the newest Git tag such as
v1.4.2. - It lists the commits made since that tag.
- It parses each commit subject, body and footers into a type, scope, description and breaking-change flag.
- It applies rules to decide the next version, then renders the notes.
The version decision uses the highest-impact commit in the range. If 30 commits are fix: and one is feat:, the result is a MINOR bump. If one commit has a BREAKING CHANGE: footer, the result is MAJOR, whatever else is in the range.
A hand-rolled changelog with plain Git
You can see the idea without installing anything. The consistent prefix from the earlier git log --grep examples is enough to group commits by type.
#!/bin/sh
# changelog.sh: print commits since the last tag, grouped by type.
# Usage: ./changelog.sh [range] e.g. ./changelog.sh v1.4.2..HEAD
last=$(git describe --tags --abbrev=0 2>/dev/null)
default_range=${last:+$last..HEAD}
range=${1:-${default_range:-HEAD}}
echo "# Changes in $range"
echo
section() {
title=$1
pattern=$2
lines=$(git log "$range" --no-merges -E --grep="$pattern" --format='- %s (%h)')
if [ -n "$lines" ]; then
echo "## $title"
echo "$lines"
echo
fi
}
section "Breaking changes" '^BREAKING CHANGE:|^[a-z]+(\([^)]+\))?!: '
section "Features" '^feat(\([^)]+\))?!?: '
section "Fixes" '^fix(\([^)]+\))?!?: '
section "Performance" '^perf(\([^)]+\))?!?: 'This script has real limits. It matches lines anywhere in the message, so a body line that starts with fix: also matches. It prints raw subjects, and it cannot decide the version. A dedicated tool handles those cases, but the script shows that no hidden data is involved. The tools read the same text you can read with git log.
Choosing a tool
The tools differ mainly in when they act and how much they decide for you.
| Tool | How it runs | What it produces | Typical fit |
|---|---|---|---|
| semantic-release | Runs in CI on every push to a release branch | Version, tag, notes, optional changelog file and package publish, with no human step | Libraries that release on every qualifying merge |
| release-please | GitHub Action that keeps a "release PR" open and updated | A PR that edits `CHANGELOG.md` and the version file. Merging it creates the tag and release | Teams that want a human to approve each release |
| git-cliff | Command-line tool you run locally or in CI | A changelog rendered from a template (`cliff.toml`) | Projects that want control over changelog layout and no publishing logic |
| conventional-changelog | Command-line tool and library | Changelog text from a preset | Scripts that only need changelog generation |
The older standard-version tool did this job too, but it is no longer maintained. Prefer one of the tools above for new projects.
Fully automatic: semantic-release
semantic-release is built from plugins. The commit analyzer decides the bump, the notes generator writes the text, and other plugins write the changelog file and publish.
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
["@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" }],
"@semantic-release/github"
]
}Save this as .releaserc.json. The default analyzer rules follow the mapping you already know: a breaking change gives MAJOR, feat gives MINOR, and fix and perf give PATCH. A revert also gives PATCH. Types such as docs, style, test and chore trigger no release by default. If a push contains only those types, nothing is published.
The tool is normally run in CI with a token. Running npx semantic-release --dry-run prints the version it would choose without publishing, which is the safest way to test your configuration.
Human in the loop: release-please
release-please avoids releasing on every merge. After each merge to main, it opens or updates a pull request titled something like "chore(main): release 1.5.0". The PR contains the new changelog entries and the version change. Nothing is tagged until a person merges that PR.
name: release-please
on:
push:
branches: [main]
permissions:
contents: write
pull-requests: write
jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: googleapis/release-please-action@v4
with:
release-type: nodeThis gives you a review point. You can read the proposed notes, wait until several changes have accumulated, or hold a release until a deadline. The cost is one extra PR to merge per release.
Template control: git-cliff
git-cliff only generates text. You run it, and it reads the history and renders your template.
git cliff --init # writes a starter cliff.toml
git cliff --unreleased # preview notes for commits since the last tag
git cliff --output CHANGELOG.md # write the full changelogUse it when you want to decide yourself how sections are named and ordered, and you want to run tagging and publishing separately.
What ends up in the notes
Tools do not put every commit in the changelog. By default they show breaking changes, features and fixes. Types such as chore, test and ci are usually hidden. Most tools let you change this. For example, you can show docs or refactor as their own sections, or group entries by scope so that all parser changes appear together.
A breaking change gets its own prominent section. The text comes from the BREAKING CHANGE: footer when there is one. For that reason, write the footer as a sentence aimed at the person upgrading, such as "clients must call /v2/users instead", and not as a note to yourself.
Most generators also turn issue references into links. A footer like Refs: #482 often becomes a link to that issue, and the short hash becomes a link to the commit. This is one reason to keep footers in token: value form.
Squash merges decide what the tool sees
The tool reads the commits on the release branch. With a squash merge, each PR becomes exactly one commit on main, and its message is the PR title plus a description. So under squash merging:
- The PR title must be a valid conventional commit subject, such as
feat(parser): add array literals. A title like "Update stuff" produces a commit the tool ignores. - The individual commits inside the PR, however tidy, never reach the release tool.
- A breaking change must appear in the squashed message. If the footer stays only in an intermediate commit, it is lost.
Check what your hosting platform uses as the default squash message. Some use the PR title and description, while others concatenate all the commit messages. Many teams add a CI check that lints the PR title, since the title is what the release tool will read.
Common failure modes
- Silent skipping. A commit that does not match the format does not cause an error in release tools. It is ignored. A user-facing fix with the subject
Fixed login bugnever appears in the notes and never triggers a PATCH release. Enforcement with a hook or commitlint prevents this. - Wrong type, wrong bump. A new capability committed as
fix:ships as a PATCH. A removal committed asrefactor:with no breaking marker ships without a MAJOR bump. The tool cannot judge intent, so a reviewer has to check the type. - No baseline tag. On a repository with no tags, the tool treats the whole history as unreleased. semantic-release starts at
1.0.0for the first release. If you already ship version0.9.0, create a tag for it first so the tool counts from there. - Pre-1.0 versions. Under Semantic Versioning,
0.y.zis for initial development, and tools differ in how they bump it. release-please, for instance, has options such asbump-minor-pre-majorto keep breaking changes from jumping to1.0.0. Check your tool's setting before the first release. - Rewritten history after a tag. Rebasing or amending commits that are already tagged changes their hashes. The tool may then compute the wrong range or list a commit twice.
- Raw subjects read badly. A subject written for developers, such as
fix(db): handle null in row mapper, may mean nothing to a user. Treat generated notes as a draft. Release PRs and--dry-runoutput give you a chance to review them.
Exercises
Exercise
A repository's latest tag is v2.3.1. Since that tag, main has these squash-merged commits: docs: fix typo in README, fix(auth): reject expired tokens, feat(search): add fuzzy matching, chore: bump dev dependencies. What version does a default semantic-release setup choose, and which commits appear in the notes?
Show answer
The version is 2.4.0. The highest-impact commit is feat, which gives a MINOR bump, and it outranks the fix. The notes list the feat(search) entry under features and the fix(auth) entry under fixes. The docs and chore commits trigger no release on their own and are not shown by default.
Exercise
Your team squash-merges a PR whose title is "Remove old export API". Inside the PR, one commit has the footer BREAKING CHANGE: the export() function was removed. What does the release tool do, and how do you prevent this?
Show answer
The squashed commit on main has the PR title as its subject, "Remove old export API", which is not a conventional commit. If the footer is not carried into the squashed message, the tool does not see the breaking change, and it either skips the commit or does not bump MAJOR. Prevent this by requiring the PR title to be a valid conventional commit, for example feat(export)!: remove the old export API, and by making sure the squash message includes the BREAKING CHANGE: footer. Linting PR titles in CI enforces the first rule.