Week 4 · The Finale · Night 31 of 31
Night 31 · Halloween: Sign Off
📺 “Halloween. The big night. Thirty nights ago you had an empty folder; tonight you have a program with fifty-five monsters, three games, a crypt, a moon, a camera and a night watchman. One thing left: give it a number, write down what it does, and let it out. Then we sign off. Don’t touch that dial.”
Tonight you’ll learn
- Semantic versioning, and the module-path rule for v2
- Where a version number comes from: ldflags, build info, or “dev”
- A changelog people can read
- GoReleaser: one config, six binaries and a Homebrew cask
- A release workflow that refuses to publish without notes, or without the tap’s token
- Tagging, and why a tag is not a commit
Where we are: everything works, everything is tested, everything is pictured. Ship it.
A number
Semantic versioning: MAJOR.MINOR.PATCH. Fixes bump the patch (1.0.1), new features the minor (1.1.0), breaking changes the major. For a program people run rather than a library they import, “breaking” means a command or flag stops working the way it did.
Go adds a rule of its own: a module at v2 or later must have /v2 at the end of its module path. Without it, go install ...@latest ignores v2 tags entirely, and users get 1.x forever. So the project’s rule, in CONTRIBUTING.md and AGENTS.md: stay below 2.0.0 unless you also change the module path. It’s the kind of rule you write down because it’s surprising and it only bites once a year.
Where the number lives
There are three ways the program can learn its own version, and cmd/version.go tries them in order:
// version is set at release time by GoReleaser:
//
// -ldflags "-X github.com/hungovercoders/terminal-of-terror/cmd.version=1.0.0"
var version string
// appVersion is the version to report. Release builds carry it in version.
// Other builds use Go's build info: `go install ...@v1.0.0` reports 1.0.0,
// and a local `go build` reports a pseudo-version naming the commit. "dev"
// is the last resort when neither is available.
func appVersion() string {
if version != "" {
return strings.TrimPrefix(version, "v")
}
if info, ok := debug.ReadBuildInfo(); ok {
if v := info.Main.Version; v != "" && v != "(devel)" {
return strings.TrimPrefix(v, "v")
}
}
return "dev"
}
-X is a linker flag that sets a package-level string variable at build time, so a release build is stamped with its tag without a source change. debug.ReadBuildInfo reads what the Go toolchain embedded in the binary: for go install ...@v1.0.0 that’s the version; for a plain go build in a checkout it’s (devel). And "dev" for anything else. rootCmd.Version is set from this, which is what makes --version work; Cobra adds the flag when Version is non-empty.
Three sources, one function, and the comment explains which build gets which. Version reporting is a small feature that gets asked about in every bug report, so it’s worth doing completely.
The changelog
CHANGELOG.md follows Keep a Changelog: a section per version, newest first, headed ## [1.0.0] - 2026-10-11, with what changed grouped for the reader, not the committer. The 1.0.0 section opens with a quote from the host and is grouped under seven headings: The Creature Feature, Games, Nightly rituals, Monsters, Community packs, For scripting and contributors, and Beyond the terminal, because that’s how a player thinks of the program. git cliff can draft a section from the conventional commit messages you’ve been writing since Night 1 (feat:, fix:, docs:); then you edit it until it reads well. A generated changelog is a starting point, not a changelog.
The changelog is also enforced: the release workflow reads the section for the tag and refuses to publish without one.
GoReleaser
Building for Linux, macOS and Windows, on Intel and ARM, is six go build invocations with the right GOOS and GOARCH, six archives, a checksum file and a GitHub release with the archives attached. GoReleaser does it from one file, .goreleaser.yaml:
builds:
- main: .
binary: terminal-of-terror
env:
- CGO_ENABLED=0
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
flags:
- -trimpath
ldflags:
- -s -w -X github.com/hungovercoders/terminal-of-terror/cmd.version={{ .Version }}
mod_timestamp: "{{ .CommitTimestamp }}"
CGO_ENABLED=0 makes a static binary that runs anywhere without a C library. -s -w strips debug symbols for a smaller file; -trimpath removes the build machine’s paths; mod_timestamp makes builds reproducible, so two people building the same tag get byte-identical binaries. And there’s the -X flag with {{ .Version }} filled in from the tag.
archives:
- formats: [tar.gz]
format_overrides:
- goos: windows
formats: [zip]
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files:
- README.md
- LICENSE
- CHANGELOG.md
- man/*
- completions/*
...
changelog:
disable: true
Tarballs, except a zip for Windows, named so a user can find theirs, with the README, licence and changelog inside, plus a man page per command and shell completions for bash, zsh, fish and PowerShell. Those are generated, not committed: a before.hooks entry runs scripts/shelldocs, which writes them from the command tree, so a new command cannot ship without its page. GoReleaser’s own changelog is disabled because the notes come from CHANGELOG.md. Night 29’s fourth CI check is goreleaser check, which validates this file on every pull request, so a typo here is found before release day.
The same file publishes a Homebrew cask, so a Mac or Linux user can brew install hungovercoders/tap/terminal-of-terror:
homebrew_casks:
- name: terminal-of-terror
repository:
owner: hungovercoders
name: homebrew-tap
branch: main
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
directory: Casks
...
# Prereleases (v1.1.0-rc1) go to GitHub but not to the tap.
skip_upload: auto
binaries: [terminal-of-terror]
manpages:
- man/terminal-of-terror-countdown.1
- man/terminal-of-terror-crypt-reset.1
...
After the archives are uploaded, GoReleaser writes Casks/terminal-of-terror.rb into the tap repository, pointing at them. The cask lists the man pages one by one, where the archive used man/*, so TestCaskListsEveryManPage in scripts/shelldocs/main_test.go walks the command tree and fails when a command is added without its line. Pushing to another repository needs more than the workflow’s own token, which is the next section’s first step.
The release workflow
release.yml has two ways in: a tag push, or a button in the Actions tab that asks for a version:
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
version:
description: "Version to release, e.g. 1.1.0 (tagged as v1.1.0). Its CHANGELOG.md section must already be on main."
required: true
type: string
permissions:
contents: write
contents: write, because this one does publish. workflow_dispatch is how a workflow gets a Run button, and inputs are the form it shows; a job reads them as inputs.version. Its first step checks that the HOMEBREW_TAP_GITHUB_TOKEN secret is set, a fine-grained personal access token that can write to the tap and nothing else, and fails before anything is built or uploaded: a missing token found at the end would leave a GitHub release published and the cask unpublished. Then a checkout with fetch-depth: 0, because GoReleaser reads the tags; then the tests, then the notes:
- name: Release notes from CHANGELOG.md
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
awk -v heading="## [$VERSION]" '
index($0, heading) == 1 { found = 1; next }
found && /^## \[/ { exit }
found { print }
' CHANGELOG.md > "$RUNNER_TEMP/notes.md"
if [ ! -s "$RUNNER_TEMP/notes.md" ]; then
echo "::error::CHANGELOG.md has no '## [$VERSION]' section. Merge the changelog for $VERSION into main before releasing."
exit 1
fi
The version comes from a step before it, “Decide the version”, which takes it from the tag name on a tag push and from the button’s input otherwise, and in the button’s case refuses to go on unless the run is on main, the version is well-formed and below 2.0.0, and the tag doesn’t already exist. Then an awk program prints the lines between this version’s heading and the next one. If that’s empty, the release stops with an error that says what to do, and nothing is published: no release with no notes. Then goreleaser release --clean --release-notes notes.md does the rest with two tokens in its environment: the repository’s own GITHUB_TOKEN for the release, and HOMEBREW_TAP_GITHUB_TOKEN for the cask.
Tagging
A tag is a name for a commit. git tag v1.0.0 on the merge commit of the release preparation, then git push origin v1.0.0, and the workflow runs. Tags aren’t pushed by git push on their own, which is why the step is explicit, and why the project’s rule is that a tag is never pushed, and the Release button never pressed, without the maintainer’s go-ahead: either is publishing.
The button does the tagging itself, after the tests:
- name: Tag
if: github.event_name == 'workflow_dispatch'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "v$VERSION" -m "Terminal of Terror $VERSION"
git push origin "v$VERSION"
And here is the trap that shapes the whole file. A tag pushed with the workflow’s own GITHUB_TOKEN does not trigger other workflows; GitHub does that on purpose, so a workflow can’t start an endless chain of workflows. A “tag it” button that relied on the push: tags trigger to do the publishing would tag and then sit there. So the button’s run tags and builds and publishes, in one job, and the tag-push trigger stays for anyone who tags by hand. Whenever one workflow is meant to set off another, this rule is the first thing to check.
The CONTRIBUTING.md release checklist, in full:
- Pick the version.
git cliff --unreleased --tag v1.1.0 --prepend CHANGELOG.md, then edit.- Commit (
chore(release): prepare for v1.1.0) and merge tomain. - Actions → Release → Run workflow, on
main, with1.1.0. (Orgit tag v1.1.0 && git push origin v1.1.0from an up-to-datemain.)
Try it without publishing: goreleaser release --snapshot --clean builds everything into .goreleaser/dist/, not GoReleaser’s usual dist/, because that is where the website builds; and it touches nothing on GitHub, rendering the cask into .goreleaser/dist/homebrew/Casks/ instead of pushing it.
Run it
go build -o terminal-of-terror . && ./terminal-of-terror --version
go install github.com/hungovercoders/terminal-of-terror@latest && terminal-of-terror --version
The first says dev (or a pseudo-version); the second, the tagged release. Then the last command of the course:
terminal-of-terror monster
Watch the static. Read the greeting. It’s yours.
Try it
- Run
goreleaser release --snapshot --cleanand look in.goreleaser/dist/. Unpack the Windows zip on a Mac. It’s just files. Then read the cask it rendered. - Change
formats: [tar.gz]to addzipfor everyone. Some users prefer it. - Make the changelog check also require a date in the heading.
💀 Terrifying fact
go install github.com/hungovercoders/terminal-of-terror@latest doesn’t ask GitHub; it asks the Go module proxy, which caches modules and never forgets a version. Once a tag has been fetched through the proxy, deleting or moving the tag on GitHub doesn’t remove it: users will keep getting the original. A published version is immutable in practice, which is why the release rules are strict, and why a mistake is fixed by publishing 1.0.1, never by re-tagging 1.0.0.
🕯️ Before dawn
Thirty-one nights. Here’s what you built, in the order you built it: a module and a command; a data vault with tests; a search; a styled list and a card; an interactive explorer with pages, scrolling and search; a host and an intro; a silent-film mode; a gallery; a question generator and two games; saved progress, captures and badges; a fight simulator; a moon; three rituals; JSON and seeds and packs from disk; a test suite that runs on three operating systems; a camera; and a release.
The techniques are the point: Cobra commands, embedded data, the Elm architecture, Lip Gloss layout, table-driven tests, seeded randomness, atomic writes, a CI matrix, GoReleaser. None of them is about monsters. All of them are yours for the next program.
Your homework is a program of your own, on any subject, hosted by anyone you like. Thirty-one nights from now, tag it v1.0.0.
📺 “That’s all for tonight, and that’s all for the course. Sleep tight, check under the bed, and keep your garlic fresh. From all of us at Channel 13: Happy Halloween, creatures of the night. Count Cathode, signing off.”