actions/setup-go@v7
Setup a Go environment and add it to the PATH
At a glance
- Latest major
v7- Repository
- actions/setup-go
- Inputs
- 8 (0 required)
- Outputs
- 11
- Runs using
node24- License
- MIT
- Last checked
Inputs and outputs come straight from the action's official action.yml. See our editorial standards.
Usage
- uses: actions/setup-go@v7Inputs
| Name | Required | Default | Description |
|---|---|---|---|
go-version | No | none | The Go version to download (if necessary) and use. Supports native Go versions (e.g. go1.21.5), semver specs and ranges. Be sure to enclose this option in single quotation marks. |
go-version-file | No | none | Path to the go.mod, go.work, .go-version, or .tool-versions file. |
check-latest | No | false | Set this option to true if you want the action to always check for the latest available version that satisfies the version spec |
token | No | ${{ github.server_url == 'https://github.com' && github.token || '' }} | Used to pull Go distributions from go-versions. Since there's a default, this is typically not supplied by the user. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting. |
cache | No | true | Used to specify whether caching is needed. Set to true, if you'd like to enable caching. |
cache-dependency-path | No | none | Used to specify the path to a dependency file (e.g., go.mod, go.sum) |
architecture | No | none | Target architecture for Go to use. Examples: x86, x64. Will use system architecture by default. |
go-download-base-url | No | none | Custom base URL for downloading Go distributions. Use this to download Go from a mirror or custom source. Defaults to "https://go.dev/dl". Can also be set via the GO_DOWNLOAD_BASE_URL environment variable. The input takes precedence over the environment variable. |
Outputs
| Name | Description |
|---|---|
go-version | The installed Go version. Useful when given a version range as input. |
cache-hit | A boolean value to indicate if a cache was hit |
GOPATH | The value of `go env GOPATH`. |
GOBIN | The value of `go env GOBIN`. |
go-bin-path | The base Go binary directory: the `GOBIN` value, otherwise `bin` under the first `GOPATH` entry when `GOBIN` is empty. |
GOROOT | The value of `go env GOROOT`. |
GOCACHE | The value of `go env GOCACHE`, the build cache directory. |
GOMODCACHE | The value of `go env GOMODCACHE`, the module cache directory. |
GOOS | The value of `go env GOOS`, the target OS in Go notation (linux, darwin, windows). |
GOARCH | The value of `go env GOARCH`, the target architecture in Go notation (amd64, arm64). |
GOTOOLDIR | The value of `go env GOTOOLDIR`, the directory holding the toolchain binaries. |
Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.
Examples
Go from go.mod
Use the version declared in go.mod so CI and local builds agree.
name: Example
on:
push:
branches: [main]
permissions:
contents: read
jobs:
example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Setup Go environment
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache: true
- run: go build ./...
- run: go test ./...Each example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.
Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.