Versioning and releases with semantic versioning, git tags and generated changelogs
A beginner friendly walk through semantic versioning, annotated git tags and conventional commits on the shorty app, then release-please and GoReleaser to cut releases and changelogs, and Docker image tags that follow the version.
Sooner or later someone asks "which version is running in prod?" and the honest answer is a git SHA. That's fine for machines. It's not great for humans, for changelogs, or for anyone who wants to know whether an upgrade will break them.
In this blog we will look at giving shorty (the URL shortener from the earlier tutorials) real versions: semantic versioning, annotated git tags, conventional commit messages, and then two tools that do the boring parts, release-please and GoReleaser. At the end the Docker image gets version tags next to its SHA tag. This is a beginner post in the series that started with CI/CD explained. You need git and a GitHub repository, and it helps to have read build once, deploy many, since versions sit on top of the SHA tags from there.
I used git 2.50, Go 1.27.3, GoReleaser 2.20.2, actionlint 1.7.12, and release-please-action v5 (release-please 17).
💻 The full code for this tutorial is on GitHub: FenixAra/tutorials/CI-CD/General/versioning-and-releases-with-semantic-versioning-git-tags-and-generated-changelogs. Clone it and run each step yourself.
Semantic versioning in two minutes
A version is MAJOR.MINOR.PATCH, like 1.4.2.
- PATCH goes up for bug fixes that change nothing else.
- MINOR goes up when you add something, and old callers still work.
- MAJOR goes up when you break something that worked before.
Before 1.0.0 the rules are loose: 0.x means "this can still change under you". shorty is at 0.2.0 in this post, and I'd keep it below 1.0 until its HTTP API settles down.
Go adds one rule. Tags are v + the version (v0.2.0), and a Go library at v2 or above needs /v2 at the end of its module path. shorty is an app, nobody imports it, so that part doesn't matter here. But if you tag a library v2.0.0 without changing the module path, go get won't pick it up the way you expect.
Tags, and the kind that matters
A release is a tag on a commit. Git has two kinds of tags and they don't behave the same.
git tag -a v0.1.0 -m "v0.1.0" # annotated: has a tagger, a date and a message
git tag v0.2.0-light # lightweight: just a name for a commit
I set up a scratch copy of shorty with an annotated v0.1.0, three commits after it, and then a lightweight tag on the last commit. Look at what git describe did:
$ git describe
v0.1.0-3-g8d44670
$ git describe --tags
v0.2.0-light
Plain git describe actually ignored the lightweight tag completely. It only counts annotated tags unless you pass --tags. Plenty of build scripts use plain git describe, so a lightweight release tag quietly gives you the wrong version string. Use annotated tags for releases, every time.
v0.1.0-3-g8d44670 reads as "3 commits after v0.1.0, at commit 8d44670". With --dirty it also says when the working tree has changes. shorty's Dockerfile already takes a VERSION build arg and passes it to -X main.version, so you can feed it this string:
go build -ldflags "-X main.version=$(git describe --tags --always --dirty)" -o shorty ./cmd/shorty
./shorty version
v0.1.0-3-g8d44670
There's a second place the version ends up, and it quite surprised me. Since Go 1.24, go build stamps the main module's version from the git tag into the binary's build info. When I later scanned shorty's image with Syft (more on SBOMs in a later post), it reported the module as v0.2.0+dirty. Dirty? I hadn't changed a file. go version -m showed it:
$ go version -m shorty | grep -E "mod\s|vcs.modified"
mod github.com/fenixara/shorty v0.2.0+dirty
build vcs.modified=true
GoReleaser had left a dist/ folder in the repo, and an untracked folder counts as a modified tree. Adding dist/ to .gitignore and tagging again gave a clean v0.2.1 with vcs.modified=false. Small thing, but a +dirty in a release binary makes people nervous for no reason.
Conventional commits
To work out the next version automatically, a tool has to know what each commit did. Conventional commits put that in the first line of the message:
feat(links): add DELETE /links/{code} -> minor
fix(api): return 422 for a bad custom code -> patch
docs: explain REDIS_URL -> no release
feat!: drop the /api prefix -> major (or a footer "BREAKING CHANGE: ...")
The type is the part that counts (feat, fix, docs, chore, perf, test...). The scope in brackets is optional. That's basically all there is to format. The hard part is getting everyone to write it, and the easiest fix is to squash merge pull requests and make the PR title follow the format, since that title becomes the commit message on main.
release-please: versions and changelog from commits
release-please reads the conventional commits since the last release and keeps a release pull request open. That PR bumps the version and updates CHANGELOG.md. When you merge it, release-please tags the commit and creates the GitHub release. Nobody types a version number.
It needs two files in the repo. The config:
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"packages": {
".": {
"release-type": "go",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": false,
"changelog-sections": [
{ "type": "feat", "section": "Features" },
{ "type": "fix", "section": "Bug fixes" },
{ "type": "perf", "section": "Performance" },
{ "type": "docs", "section": "Docs", "hidden": true },
{ "type": "chore", "section": "Chores", "hidden": true }
]
}
}
}
And the manifest, which holds the current version:
{
".": "0.2.0"
}
bump-minor-pre-major means a breaking change before 1.0 bumps the minor (0.2.0 to 0.3.0) instead of jumping to 1.0.0. I didn't want a stray feat! to declare shorty stable by accident.
My first version of the config had a "package-name": "shorty" line copied from an old example. I couldn't run release-please itself on my Mac (it's a Node tool and I don't have Node here), so I checked the file against the official JSON schema with a small Go validator instead:
curl -sL -o rp-schema.json https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json
go install github.com/santhosh-tekuri/jsonschema/cmd/jv@latest
jv rp-schema.json release-please-config.json
It said ok either way, because the package options allow unknown keys. But package-name isn't in the schema at all, so the line did nothing. I removed it. Worth knowing that a passing schema check doesn't mean every key is used.
GoReleaser: binaries, archives and a changelog
release-please decides the version. GoReleaser builds things for a version: binaries for each OS and CPU, archives, checksums, and a changelog grouped from the commits. Here is shorty's .goreleaser.yaml:
version: 2
project_name: shorty
before:
hooks:
- go mod tidy
- go test ./...
builds:
- id: shorty
main: ./cmd/shorty
binary: shorty
env:
- CGO_ENABLED=0
goos: [linux, darwin]
goarch: [amd64, arm64]
flags: [-trimpath]
ldflags:
- -s -w -X main.version={{ .Version }}
archives:
- formats: [tar.gz]
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
checksum:
name_template: checksums.txt
snapshot:
version_template: "{{ incpatch .Version }}-next"
changelog:
use: git
sort: asc
groups:
- title: Features
regexp: '^.*?feat(\(.+\))??!?:.+$'
order: 0
- title: Bug fixes
regexp: '^.*?fix(\(.+\))??!?:.+$'
order: 1
- title: Other
order: 999
filters:
exclude:
- '^docs:'
- '^chore:'
- '^test:'
goreleaser check failed the first time:
⨯ .goreleaser.yaml error=configuration is invalid: scm releases: no remote configured to list refs from
See, my scratch repo had no remote, I had never needed one. GoReleaser wants to know where it would publish, even just to check the file. After git remote add origin https://github.com/fenixara/shorty.git (nothing gets pushed) it said 1 configuration file(s) validated.
Then a snapshot build, which builds everything but publishes nothing:
goreleaser release --snapshot --clean
• building snapshot... version=0.1.1-next
• archiving name=dist/shorty_0.1.1-next_darwin_amd64.tar.gz
...
• release succeeded after 19s
Notice the version: 0.1.1-next. There was a feat commit after v0.1.0, so the next release should be 0.2.0. GoReleaser doesn't care, it doesn't read commit types to pick a version, it builds whatever tag you give it. That's the split: release-please (or you) decides the number, GoReleaser builds it.
So I tagged v0.2.0 and ran a real release with publishing turned off:
git tag -a v0.2.0 -m "v0.2.0"
goreleaser release --clean --skip=publish,announce,before
cat dist/CHANGELOG.md
## Changelog
### Features
* f1b26af8a5f5c5f6c03db11534b40f417d08ee42 feat(links): add DELETE /links/{code}
### Bug fixes
* 8de5e6241b85232cde247da8c2011982eaf29d4f fix(api): return 422 for a bad custom code
The docs: commit was filtered out and the rest landed in the right groups. dist/shorty_darwin_arm64_v8.0/shorty version printed 0.2.0.
Putting it together in GitHub Actions
Here is the workflow. On every push to main, release-please updates its PR. When the release PR is merged, the same run builds the binaries and the image:
name: release
on:
push:
branches: [main]
permissions:
contents: write
pull-requests: write
issues: write
packages: write
jobs:
release-please:
runs-on: ubuntu-latest
outputs:
created: ${{ steps.rp.outputs.release_created }}
tag: ${{ steps.rp.outputs.tag_name }}
version: ${{ steps.rp.outputs.version }}
steps:
- uses: googleapis/release-please-action@v5
id: rp
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
binaries:
needs: release-please
if: needs.release-please.outputs.created == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-go@v7
with:
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@v7
with:
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
image:
needs: release-please
if: needs.release-please.outputs.created == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.release-please.outputs.tag }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.release-please.outputs.tag }}
type=sha,format=long,prefix=
- uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ needs.release-please.outputs.version }}
Why not a separate workflow that runs on: push: tags? Because tags and releases created with the default GITHUB_TOKEN don't trigger other workflows. GitHub does that on purpose to stop loops. release-please creates the tag with that token, so a tag workflow would simply never start. Either use a separate token (a GitHub App token is nicer than a personal one) or keep everything in one workflow like above. I went with one workflow.
GoReleaser finds the release that release-please already created and adds the archives to it. Its default release mode keeps the existing release notes, so release-please's changelog stays as the description.
The image ends up with three tags: 0.2.0, 0.2 and the full commit SHA (the empty prefix= drops the default sha- in front, so it matches the SHA tags from the build once post). The SHA tag stays the one you deploy (by digest, as in the build once post). 0.2.0 is for humans, and 0.2 is a moving tag for people who want the latest patch. If you push to ECR with immutable tags, drop the 0.2 one, since it has to move. actionlint was clean on the file.
A few habits that help
Protect your tags. In GitHub, a tag ruleset on v* stops anyone from deleting or moving a release tag. A version that points at different code on different days is worse than no version.
Don't edit CHANGELOG.md by hand on main, edit the release PR instead, or the next run will fight you.
And don't bother versioning things nobody consumes by version. An internal service that's always deployed from main might be fine with SHAs only. Versions pay off once someone outside the repo needs to know what changed.
That's it. Annotated tags, commits a tool can read, and let release-please pick the number while GoReleaser and the image build follow it.