A Go pipeline automates the same steps you run locally: download modules, check formatting, vet, test with the race detector, build, and package. Because the go tool is one self-contained binary with built-in testing, vetting and cross-compilation, a CI/CD pipeline for Go is short and fast. A typical flow runs on every push and, after tests pass, builds a versioned artifact and deploys it.
The examples below use GitHub Actions, but the same commands work in GitLab CI, Jenkins, Buildkite or any other runner.
| Stage | Command | Purpose |
|---|---|---|
| Dependencies | go mod download and go mod verify | Fetch modules and check checksums |
| Format | gofmt -l . | Fail when files are not formatted |
| Static checks | go vet ./... | Catch suspicious code |
| Lint | golangci-lint run | Run many linters in one pass |
| Test | go test -race -cover ./... | Unit tests, race detector, coverage |
| Vulnerabilities | govulncheck ./... | Report known vulnerabilities your code calls |
| Build | go build -trimpath ./... | Produce the binary |
| Package and deploy | Docker build, release upload, rollout | Ship the artifact |
Order cheap checks first so failures appear in seconds.
Place this file at .github/workflows/ci.yml.
go-version-file: go.mod keeps CI on the same Go version as the project, and cache: true caches the module and build caches between runs. Check the current major versions of the actions you use, because they are updated regularly.
Make tests deterministic so they are safe to run in CI.
-race to catch data races. It needs cgo on most platforms and slows tests, but it is worth it.-count=1 to bypass the test cache when you must always re-run.-short and build tags such as //go:build integration to separate slow integration tests.-shuffle=on to expose order dependencies.t.TempDir() and httptest instead of shared files and real network calls.Coverage output can be converted to a report with go tool cover -func=coverage.out.
Build once, then promote the same artifact through environments. Embed the version at link time so a running binary can report what it is.
Cross-compile in a matrix with GOOS and GOARCH to publish binaries for several platforms.
For services, build a small container image from a multi-stage Dockerfile, push it with the commit SHA as the tag, and let the deploy stage reference that immutable tag.
From there deployment depends on your platform: update a Kubernetes manifest or Helm value, trigger a GitOps tool such as Argo CD, or run a rollout command. Keep credentials in the CI secret store and prefer short-lived OIDC federation over long-lived cloud keys.
For libraries, the release step is just pushing a semantic version tag, because the module proxy serves it from the repository.
go.sum.golangci-lint, so results do not change unexpectedly.go mod tidy drift with go mod tidy && git diff --exit-code go.mod go.sum.Any of them. Go needs only the toolchain, so GitHub Actions, GitLab CI, CircleCI and Jenkins all work. Choose the one that sits next to your repository.
Yes. go vet is built in and cheap, while golangci-lint adds many more checks. Run both and pin versions.
Split test levels and use required status checks, so unit tests gate merges and slower integration tests gate releases. Do not silence real failures with retries.
Build a static binary with CGO_ENABLED=0, copy it to the server over SSH or an artifact store, and restart a systemd service. Keep the previous binary for fast rollback.
A Go pipeline is a short list of standard commands: verify modules, format check, vet, test with -race, scan for vulnerabilities, build with embedded version data and package the result. Build the artifact once, tag it immutably, and promote it through environments. Caching and parallel jobs keep feedback fast.