Sub topic 11
Fully automated versioning with release-please
This chapter assumes you can read workflow YAML, know how permissions scopes the GITHUB_TOKEN, and have read the chapters on semantic versioning and Conventional Commits. Here you will let a tool choose the next version for you.
What release-please does
In the tag-driven workflow, a person decides the version and pushes the tag. release-please moves that decision into the commit history. It reads the Conventional Commits merged since the last release, works out the next version number, and keeps a release pull request open with the result.
Merging that pull request is the release step. release-please then creates the tag and the GitHub Release.
| Commit on `main` | Version bump |
|---|---|
| `fix: handle empty config file` | Patch |
| `feat: add --dry-run option` | Minor |
| `feat!: drop support for Node 16` | Major |
| `docs: clarify install steps` | None by itself |
fix: handle empty config file
feat: add --dry-run option
feat!: drop support for Node 16
docs: clarify install stepsThe ! after the type, or a BREAKING CHANGE footer, marks a breaking change. The highest bump among the unreleased commits wins. If a fix and a feat are both pending, the release is a minor one.
The workflow
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: simpleThe workflow runs on every push to main. It needs contents: write to create tags and releases. It needs pull-requests: write to open and update the release pull request. Nothing else is granted.
The release-type input tells release-please how your project stores its version. The simple type keeps a version.txt file and a CHANGELOG.md. Other types, such as node or python, also update the version in package.json or pyproject.toml.
The release cycle
Each push to main updates the same pull request. It collects changes until you are ready. The pull request holds a version bump and a new CHANGELOG.md section. You can edit the changelog text in the pull request before merging.
Triggers and the token
By default, the action uses the GITHUB_TOKEN. Events created with that token do not start other workflows. This is the limit covered in the previous chapter. Two effects follow:
- A tag or release created by release-please will not trigger a separate
on: push: tagsoron: releaseworkflow. - Checks may not run on the release pull request itself.
There are two ways to deal with this. You can do the build and upload work in the same workflow, using the action's outputs. Or you can pass a personal access token or GitHub App token through the action's token input. Events made with that token do start workflows.
Common errors
- No release pull request appears. The commits since the last release have no releasable types. Only
fix,feat, and breaking changes count by default. - Permission error on opening the pull request. In repository settings under Actions, allow workflows to create pull requests, and check that
pull-requests: writeis set. - Wrong version jump. A commit message was not in Conventional Commit form, or a
!was left in by mistake.
Exercise
Your repository has these unreleased commits on main: "fix: trim whitespace in names", "docs: update README", and "feat: support YAML input". The last release was v1.4.2. What version will release-please propose, and why?
Show answer
v1.5.0. The feat commit requires a minor bump, and that is the highest bump among the pending commits. The fix would only be a patch, and docs does not trigger a release by itself.
Exercise
A workflow with on: push: tags: ['v*'] builds your binaries. After you adopt release-please, it stops running. Why, and what are two fixes?
Show answer
release-please creates the tag with the default GITHUB_TOKEN, and events made by that token do not trigger other workflows. Fix it by doing the build in the release-please workflow (using its outputs), or by giving the action a personal access token or GitHub App token through its token input.