Skip to content
Latchkey

actions/setup-go

Install a specific Go version with module and build caching enabled by default.

Official actionCategory: Language & Toolchain SetupLatest v5View on GitHub

What it does

actions/setup-go installs a Go toolchain and, since v4, caches the module and build cache automatically based on your go.sum.

Read the version from go.mod with go-version-file so CI tracks the version your project declares.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-go@v5
    with:
      go-version-file: 'go.mod'
  - run: go test ./...

Inputs

InputDescriptionDefaultRequired
go-versionVersion spec, e.g. 1.22 or 1.22.x.-No
go-version-fileRead the version from go.mod or a .go-version file.-No
cacheEnable module/build caching.trueNo
cache-dependency-pathPath to go.sum for the cache key.go.sumNo

Outputs

OutputDescription
go-versionThe version that was installed.
cache-hittrue if an exact cache was restored.

Notes

Caching is on by default in v4+. Set cache: false only if you manage caching yourself.

Common errors

  • A cache warning about a missing go.sum appears in modules with no dependencies. It is harmless, or set cache: false.

Security and pinning

  • Pin setup-go to a commit SHA.

Frequently asked questions

Do I need a separate cache step for Go?
No. setup-go v4+ caches the module and build cache automatically from go.sum.

References

Running actions/setup-go? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card