How do I distribute a Go CLI to multiple platforms with GoReleaser and Homebrew?
Question
We have a Go CLI tool (say, CommitBrief). I want both macOS (M1/M2/Intel) and Linux users to install it easily with `brew install`. Using GoReleaser in GitHub Actions, how do I set up a CI/CD flow that builds binaries on every tag, uploads them to GitHub Releases, and auto-updates a private Homebrew Tap repo?
Answer
Short answer: this is exactly the problem GoReleaser solves — a .goreleaser.yaml plus a single tag-triggered workflow handles cross-compilation, the GitHub Release, and the Homebrew tap formula automatically.
All you really do is let go of the packaging chain; GoReleaser owns the rest.
- Define the build matrix in
.goreleaser.yaml. Targetdarwin/arm64,darwin/amd64,linux/amd64,linux/arm64. If you want, useuniversal_binariesto produce a single universal macOS artifact; the M1/M2/Intel split disappears for the user. - Set up a tag-triggered GitHub Actions workflow. With
on: push: tags: ['v*'], rungoreleaser release: it cross-compiles, builds archives + checksums, and publishes the GitHub Release. - Auto-update the tap formula with a
brews:block. This block commits the formula to a separatehomebrew-taprepo. Users thenbrew install yourname/tap/cli. What you need: a PAT scoped to push to the tap repo (the defaultGITHUB_TOKENcan’t write to another repo, so a separate token is required). - Stamp the version into the binary and validate the config in CI. Use
ldflagsto stamp version/commit/date socli --versionreports correctly. Addgoreleaser checkto the pipeline — if the config is broken you catch it in the PR, not at release time.
Bottom line: push a tag and let GoReleaser do the rest — Releases + tap formula ship from one command, and manual packaging is gone. This is the de facto standard in the Go ecosystem; set up tag discipline and a separate tap token, and the flow runs itself. I cover the broader picture of packaging and distributing a CLI in the hub post; fit that distribution model onto this workflow.
Comments
Sign in with your GitHub account to join the discussion. Comments are stored in GitHub Discussions.