setup-go
Описание
Set up your GitHub Actions workflow with a specific version of Go
Языки
- TypeScript99,6%
- Shell0,2%
- JavaScript0,2%
setup-go
This action sets up a Go environment for use in GitHub Actions by:
- Optionally downloading and caching a version of Go by version and adding it to the PATH
- Optionally caching Go modules and build outputs
- Registering problem matchers for error output
Breaking changes in V6
The V6 edition of the action includes:
-
Upgraded Node.js runtime from node20 to node24
Make sure your runner is on version v2.327.1 or later to ensure compatibility with this release. See Release Notes
-
Go toolchain
- Supports both
andgodirectives intoolchain. If thego.moddirective is present, its version is used; otherwise, the action falls back to thetoolchaindirective.go
- Supports both
-
Cache key update
- By default, the cache key for Go modules is based on
. To usego.mod, configure thego.suminput.cache-dependency-path
- By default, the cache key for Go modules is based on
See full release notes on the releases page.
Usage
See action.yml.
Basic:
Version resolution behavior:
The action resolves the requested version in the following order:
- Local cache - Checks the local tool cache for a matching semver version.
- go-versions repository - If the requested version isn’t available in the tool cache, it pulls the version manifest from the
branch of the go-versions repository.main - Direct download - If that lookup misses or fails, it will fall back to downloading directly from the official Go distribution site.
To change the default behavior, please use the check-latest input.
Note: The
action uses executable binaries built by the Go team and does not build Go binaries from source code.setup-go
Supported version syntax
The input supports the following syntax:
- Specific versions:
,1.25,1.24.11,1.24.0-rc.11.23.0-beta.1 - SemVer version range syntax:
,^1.25.1,~1.24.1,>=1.25.0-rc.1,<1.25.0>=1.22.0 <1.24.0 - Aliases:
,stableoldstable - Wildcards:
,1.25.x1.x
For details on Semantic Versioning, see the semver package documentation.
Note: Due to the peculiarities of YAML parsing, it is recommended to wrap the version in single quotation marks:
The recommendation is based on the YAML parser's behavior, which interprets non-wrapped values as numbers and, in the case of version
, trims it down to1.20, which may not be very obvious.1.2
For more usage examples, please refer to the section: Using go-version input of the Advanced usage guide.
Recommended permissions
When using the action in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:
Caching dependency files and build outputs
The action includes built-in caching and restoration for Go modules and build outputs. It uses
toolkit/cache under the hood, but requires less configuration.
The input is optional, and caching is enabled by default. To disable caching, set .
By default, the action looks for in the repository root and uses its hash as part of the cache key. Use the input when you have multiple dependency files, or when they’re located in different subdirectories. This input supports glob patterns.
If caching cannot be performed for any reason, the action logs a warning and continues workflow execution.
For examples of using , see the Caching section of the Advanced usage guide.
Advanced usage
- Using the go-version input
- Using the go-version-file input
- Check latest version
- Caching
- Outputs
- Custom download URL
- Using
on GHESsetup-go
License
The scripts and documentation in this project are released under the MIT License.
Contributions
Contributions are welcome! See our Contributor's Guide.
Code of Conduct
👋 Be nice. See our code of conduct