actions/setup-go
Install a specific Go version with module and build caching enabled by default.
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
| Input | Description | Default | Required |
|---|---|---|---|
go-version | Version spec, e.g. 1.22 or 1.22.x. | - | No |
go-version-file | Read the version from go.mod or a .go-version file. | - | No |
cache | Enable module/build caching. | true | No |
cache-dependency-path | Path to go.sum for the cache key. | go.sum | No |
Outputs
| Output | Description |
|---|---|
go-version | The version that was installed. |
cache-hit | true 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.sumappears in modules with no dependencies. It is harmless, or setcache: 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.