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@v7

Inputs

NameRequiredDefaultDescription
go-versionNononeThe 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-fileNononePath to the go.mod, go.work, .go-version, or .tool-versions file.
check-latestNofalseSet this option to true if you want the action to always check for the latest available version that satisfies the version spec
tokenNo${{ 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.
cacheNotrueUsed to specify whether caching is needed. Set to true, if you'd like to enable caching.
cache-dependency-pathNononeUsed to specify the path to a dependency file (e.g., go.mod, go.sum)
architectureNononeTarget architecture for Go to use. Examples: x86, x64. Will use system architecture by default.
go-download-base-urlNononeCustom 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

NameDescription
go-versionThe installed Go version. Useful when given a version range as input.
cache-hitA boolean value to indicate if a cache was hit
GOPATHThe value of `go env GOPATH`.
GOBINThe value of `go env GOBIN`.
go-bin-pathThe base Go binary directory: the `GOBIN` value, otherwise `bin` under the first `GOPATH` entry when `GOBIN` is empty.
GOROOTThe value of `go env GOROOT`.
GOCACHEThe value of `go env GOCACHE`, the build cache directory.
GOMODCACHEThe value of `go env GOMODCACHE`, the module cache directory.
GOOSThe value of `go env GOOS`, the target OS in Go notation (linux, darwin, windows).
GOARCHThe value of `go env GOARCH`, the target architecture in Go notation (amd64, arm64).
GOTOOLDIRThe 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.