Sub topic 6
Shaping release notes with categories and exclusions
GitHub can generate release notes from the pull requests merged since the previous release. By default the notes are a flat list. This chapter shows how to group that list into sections and leave out noise, using a file in your repository.
This chapter assumes you can read YAML, you know how labels work on pull requests, and you have the tag-triggered workflow from the earlier chapter, where gh release create runs with --generate-notes.
How the configuration is found
GitHub reads a file named .github/release.yml from the repository when it generates notes. The file is not a workflow. It does not go in .github/workflows/, and it needs no trigger or permissions. It changes only how the generated notes are laid out.
The same settings apply wherever notes are generated: the "Generate release notes" button in the web interface, the API, and gh release create --generate-notes. The workflow itself needs no change.
A working configuration
Save this as .github/release.yml:
changelog:
exclude:
labels:
- ignore-for-release
authors:
- dependabot
categories:
- title: Breaking Changes
labels:
- breaking-change
- title: New Features
labels:
- enhancement
- title: Bug Fixes
labels:
- bug
- title: Other Changes
labels:
- "*"The file has two parts under changelog.
Exclusions
exclude removes pull requests from the notes entirely. It accepts two lists:
labels: any pull request with one of these labels is left out.authors: any pull request opened by one of these users or bots is left out.
In the example, a pull request labeled ignore-for-release never appears. Pull requests from Dependabot are also dropped, so version bumps of dependencies do not clutter the notes.
Categories
categories is an ordered list of sections. Each has a title and a list of labels. A pull request goes into the first category whose labels match one of its labels. A pull request appears in only one section.
Two details matter in practice:
- Order decides placement. A pull request labeled both
breaking-changeandbuglands under Breaking Changes, because that category comes first. - The
"*"label is a catch-all. It collects every pull request that matched no earlier category. Keep it last, and quote it in YAML, because an unquoted*is parsed as an alias marker and makes the file invalid.
Sections that end up with no pull requests are not shown.
Worked example
Suppose three pull requests were merged since v1.1.0:
| Pull request | Labels | Result in notes |
|---|---|---|
| Add `--dry-run` option | `enhancement` | New Features |
| Fix crash on empty config | `bug` | Bug Fixes |
| Bump a dependency | `dependencies`, from Dependabot | Excluded |
If you also merge a documentation pull request with the label documentation, it appears under Other Changes through the catch-all.
Common errors
- Everything lands in one section. Pull requests have no labels. Labels are what the configuration matches on, so apply them before merging, or add a workflow or team habit that enforces it.
- The file is ignored. It must be named
release.yml(orrelease.yaml) in.github/on the branch the release is created from. Check the path and spelling. - A category never fills. The label name must match exactly, including case and hyphens.
- A pull request is missing. It may match an
excluderule. Exclusions are checked before categories.
Exercise
A pull request carries the labels bug and enhancement. Using the example configuration, which section does it appear in, and why? What would change if the "Other Changes" category were moved to the top of the list?
Show answer
It appears under New Features, because that category is listed before Bug Fixes and a pull request is placed in the first matching category. If "Other Changes" with the "*" catch-all came first, it would match every pull request, so all pull requests would land there and the later categories would stay empty.