Sub topic 18
A release workflow that holds up over time
This chapter assumes you can create, push and delete tags, and that you have created a GitHub Release with gh. Here you combine those pieces into a routine that stays safe as a project grows.
Principles
A release workflow lasts when each step is predictable and hard to undo by accident. Four rules cover most of the risk:
- Tag only commits that are already on the release branch and have passed checks.
- Use annotated tags (or signed ones) for releases, so each tag records who made it and when.
- Never move or delete a tag after you have pushed it. Publish a new patch version instead.
- Let automation build the release from the tag, so the same steps run every time.
The flow
A routine you can repeat
Run these steps from an up-to-date main:
# Start from the latest main, with a clean tree
git switch main
git pull
git status
# Create a signed, annotated tag (use -a instead of -s if you do not sign)
git tag -s v1.3.0 -m "Release 1.3.0"
git tag -v v1.3.0
# Push only this tag
git push origin v1.3.0Pushing the tag starts the Actions workflow from the previous chapter. It packages the code and runs gh release create with generated notes. You never build files by hand on your own machine, so the release does not depend on what is installed there.
Handling mistakes
If a release is wrong, do not rewrite the tag. People may have already downloaded it, and anyone who fetched it keeps the old target. Fix the problem on a new commit and publish the next version.
# v1.3.0 shipped with a bug. Fix it, then tag a patch release.
git switch main
git pull
git tag -a v1.3.1 -m "Release 1.3.1: fix crash on empty input"
git push origin v1.3.1Then edit the notes of v1.3.0 on GitHub to point readers to v1.3.1. Editing notes does not change the tag.
If the mistake is caught before anyone could have used the tag, for example while a release is still a draft, deleting the tag is acceptable. Delete it locally and on the remote, then recreate it.
Keeping it consistent
| Habit | Why it helps |
|---|---|
| Follow Semantic Versioning (`MAJOR.MINOR.PATCH`) | Version numbers tell users how risky an upgrade is |
| Use one tag pattern, such as `v*` | The workflow trigger matches every release and nothing else |
| Use `--draft` or `--prerelease` for risky builds | You can inspect the result before users see it |
| Give the workflow only `contents: write` | A bug in the workflow has a small blast radius |
Exercise
You pushed tag v2.0.0 and then notice the release contains a bug. A teammate suggests moving the tag to the fixed commit. What do you do instead, and why?
Show answer
Fix the bug on a new commit, tag it as v2.0.1, and push that tag. Users who already fetched v2.0.0 would keep the old target, so moving the tag would leave different people with different code under the same name. Add a note to the v2.0.0 release that points to v2.0.1.