Go "go generate" Failures in CI - Fix Generator Errors
go generate runs the tools named in //go:generate directives. It fails when a generator binary is not installed on the runner, or when a CI freshness check finds the committed generated files no longer match their source.
What this error means
A go generate ./... step fails with executable file not found in $PATH for a generator (mockgen, stringer, protoc-gen-go), or a follow-up git diff step fails because regeneration changed committed files.
app/store.go:3: running "mockgen": exec: "mockgen":
executable file not found in $PATH
# or, the freshness check:
generated files are out of date; run 'go generate ./...'Common causes
A generator tool not installed on the runner
The //go:generate directive invokes a binary (mockgen, stringer, protoc plugins) that is not on the CI runner’s PATH.
Generated files committed stale
Source changed but go generate was not re-run before committing, so a CI check that regenerates and diffs finds drift.
How to fix it
Install the generator tools
Install the exact tool versions the directives use before running generate.
go install github.com/golang/mock/mockgen@v1.6.0
go install golang.org/x/tools/cmd/stringer@latest
go generate ./...Pin tools in a tools.go file
Track generator dependencies in the module so versions are reproducible.
//go:build tools
package tools
import (
_ "github.com/golang/mock/mockgen"
_ "golang.org/x/tools/cmd/stringer"
)Enforce generated-file freshness in CI
go generate ./...
git diff --exit-codeHow to prevent it
- Pin generator tools via a
tools.goand install them in CI. - Re-run
go generate ./...and commit before pushing. - Add a
git diff --exit-codefreshness check after generate.