Skip to content
Latchkey

Go "go generate: no such tool" - Fix in CI

A //go:generate line shells out to whatever command it names. When that command is not installed or not on PATH in the runner, generate aborts before producing any output.

What this error means

Running go generate ./... in CI fails with no such tool or executable file not found in $PATH. Locally the generator was installed; the runner has a clean PATH and never received it.

go
app/models.go:3: running "stringer": exec: "stringer": executable file not found in $PATH
go generate: no such tool "stringer"

Common causes

Generator never installed in CI

The tool was on your local machine but the workflow never ran go install for it, so the runner PATH has nothing to exec.

GOBIN not on PATH

go install placed the binary in GOBIN/GOPATH/bin, but that directory was not added to PATH, so the directive cannot find it.

How to fix it

Install the generator before generate

  1. Add a step that go installs each tool the directives invoke.
  2. Run go generate after the install so the binaries exist on PATH.
.github/workflows/ci.yml
- run: go install golang.org/x/tools/cmd/stringer@latest
- run: go generate ./...

Pin tools in a tools.go file

  1. Track generators as build constraints so versions are pinned in go.mod.
  2. Install them from the module before generating.
tools.go
//go:build tools
package tools

import _ "golang.org/x/tools/cmd/stringer"

How to prevent it

  • Pin generators in a tools.go build-tagged file so versions never drift.
  • Install every generator in CI before running go generate.
  • Add GOBIN (or $(go env GOPATH)/bin) to PATH in the workflow.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →