In a Go project the build pipeline compiles and packages the code, the test pipeline checks that it is correct, and the release pipeline versions it and publishes it where users or servers can get it. They are usually stages of one CI/CD workflow, run in that order, and each one gates the next.
Splitting them keeps feedback fast, makes failures easy to locate, and ensures the exact artifact that passed the tests is the one that gets released.
The build stage turns source into an artifact and proves the module is consistent. It downloads dependencies, compiles every package and produces binaries, optionally for several operating systems and architectures.
Key points for a robust build:
go build ./... fails fast on compile errors in any package.go mod verify checks that downloaded modules match the checksums in go.sum.-trimpath and a pinned Go version give reproducible binaries.-ldflags "-X main.version=..." embeds the version so the binary can report it.GOMODCACHE and the build cache between runs makes CI much faster.The test stage verifies behaviour and code quality. It should run on every push and pull request, before anything is released.
| Check | Purpose |
|---|---|
gofmt or go fmt | Keeps formatting consistent |
go vet | Finds suspicious constructs such as wrong printf verbs |
go test -race | Runs tests with the race detector to catch data races |
-cover and -coverprofile | Measures test coverage |
govulncheck | Reports known vulnerabilities that your code actually calls |
Linters such as golangci-lint | Add stricter static analysis |
Integration tests that need a database or other services can run in a separate job using service containers, and can be selected with build tags or -short. A test written for this pipeline looks like any other.
The release stage runs only after build and test succeed, typically when you push a version tag. It assigns the version, builds the final artifacts, publishes them and often triggers deployment.
Go modules use semantic versions with a leading v, and the tag is what go get example.com/[email protected] resolves. For a major version 2 or higher, the module path must end in /v2, /v3 and so on.
A tag-triggered job commonly does the following:
Action versions change over time, so check the current major versions in each project's documentation before copying this.
| Aspect | Build | Test | Release |
|---|---|---|---|
| Question answered | Does it compile? | Is it correct? | Can users get it? |
| Trigger | Every push | Every push and pull request | Version tag or manual approval |
| Main commands | go build, go mod | go test, go vet, govulncheck | git tag, GoReleaser, image push |
| Output | Binaries | Pass or fail, coverage | Versioned artifacts and images |
| Failure means | Fix the code | Fix the code or tests | Fix packaging or credentials |
go and toolchain lines in go.mod, and use go-version-file in CI.They can be separate jobs in one workflow. Separate jobs run in parallel and show clearly which stage failed, while the release job depends on both.
Yes, it compiles each package and its tests, but it does not produce your release binary. A separate build step creates the shipped artifact.
Use semantic version git tags such as v1.4.0. Go modules resolve versions from those tags, and major versions 2 and above need a /vN suffix in the module path.
No. It is a convenience tool. You can build, archive and upload with plain scripts.
The build pipeline compiles and packages, the test pipeline proves the code is correct and secure, and the release pipeline versions, publishes and ships the verified artifact. Run them in order, make each gate the next, pin your toolchain, and release from tags so every published version can be traced to the exact commit.