- Notifications
You must be signed in to change notification settings - Fork613
Set up your GitHub Actions workflow with a specific version of Go
License
actions/setup-go
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This action sets up a go environment for use in actions by:
- Optionally downloading and caching a version of Go by version and adding to
PATH. - Registering problem matchers for error output.
- Improve toolchain handling to ensure more reliable and consistent toolchain selection and management.
- Upgraded 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
For more details, see the full release notes on thereleases page
The V5 edition of the action offers:
- Upgraded Node.js runtime from node16 to node20
See full release notes on thereleases page.
The action will first check the local cache for a version match. If a version is not found locally, it will pull it fromthemain branch of thego-versionsrepository. On miss or failure, it will fall back to downloading directlyfromgo dist. To change the default behavior, please usethecheck-latest input.
Note: Thesetup-go action uses executable binaries which are built by Golang side. The action does not buildgolang from source code.
Matching bysemver spec:
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'^1.13.1'# The Go version to download (if necessary) and use. -run:go version
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'>=1.17.0' -run:go version
Note: Due to the peculiarities of YAML parsing, it is recommended to wrap the version in single quotation marks:
go-version:'1.20'The recommendation is based on the YAML parser's behavior, which interprets non-wrapped values as numbers and, in the case of version 1.20, trims it down to 1.2, which may not be very obvious.
Matching an unstable pre-release:
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'1.18.0-rc.1'# The Go version to download (if necessary) and use. -run:go version
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'1.16.0-beta.1'# The Go version to download (if necessary) and use. -run:go version
Seeaction.yml
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'1.16.1'# The Go version to download (if necessary) and use. -run:go run hello.go
Thecheck-latest flag defaults tofalse. Use the default or setcheck-latest tofalse if you prefer stabilityand if you want to ensure a specific Go version is always used.
Ifcheck-latest is set totrue, the action first checks if the cached version is the latest one. If the locallycached version is not the most up-to-date, a Go version will then be downloaded. Setcheck-latest totrue if youwant the most up-to-date Go version to always be used.
Setting
check-latesttotruehas performance implications as downloading Go versions is slower than using cachedversions.
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'1.14'check-latest:true -run:go run hello.go
Ifstable is provided, action will get the latest stable version fromthego-versions repository manifest.
Ifoldstable is provided, when current release is 1.19.x, action will resolve version as 1.18.x, where x is the latestpatch release.
Note: using these aliases will result in same version as using corresponding minor release withcheck-latest inputset totrue
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'stable' -run:go run hello.go
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'oldstable' -run:go run hello.go
The action has a built-in functionality for caching and restoring go modules and build outputs. Itusestoolkit/cache under the hood but requires less configuration settings.Thecache input is optional, and caching is turned on by default.
The action defaults to search for the dependency file - go.sum in the repository root, and uses its hash as a part ofthe cache key. Usecache-dependency-path input for cases when multiple dependency files are used, or they are locatedin different subdirectories. The input supports glob patterns.
If some problem that prevents success caching happens then the action issues the warning in the log and continues the execution of the pipeline.
Caching in monorepos
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version:'1.17'check-latest:truecache-dependency-path:| subdir/go.sum tools/go.sum# cache-dependency-path: "**/*.sum" -run:go run hello.go
Thego-version-file input accepts a path to ago.mod file,.tool-versions file or ago.workfile that contains the version of Go to be used by a project. The version takenfrom thils file will be:
- The version from the
toolchaindirective, if there is one, otherwise - The version from the
godirective
The version can specify a patch version or omit it altogether (e.g.,go 1.22.0 orgo 1.22).
If a patch version is specified, that specific patch version will be used.
If no patch version is specified, it will search for the latest available patch version in the cache,versions-manifest.json, and theofficial Go language website, in that order.
If both thego-version and thego-version-file inputs are provided then thego-version input is used.
The action will search for the
go.modfile relative to the repository root
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version-file:'path/to/go.mod' -run:go version
steps: -uses:actions/checkout@v5 -uses:actions/setup-go@v6with:go-version-file:'.tool-versions' -run:go version
The.tool-versions file supports version specifications in accordance with asdf standards, adhering to Semantic Versioning (semver).
jobs:build:runs-on:ubuntu-lateststrategy:matrix:go:[ '1.14', '1.13' ]name:Go ${{ matrix.go }} samplesteps: -uses:actions/checkout@v5 -name:Setup gouses:actions/setup-go@v6with:go-version:${{ matrix.go }} -run:go run hello.go
Thego-version input supports the following syntax:
- Specific versions:
1.15,1.16.1,1.17.0-rc.2,1.16.0-beta.1 - SemVer's version range syntax:
^1.13.1,>=1.18.0-rc.1
For more information about semantic versioning, please refer tosemverdocumentation.
setup-go comes pre-installed on the appliance with GHES if Actions is enabled.When dynamically downloading Go distributions,setup-go downloads distributions fromactions/go-versions on github.com (outside of the appliance).
These calls toactions/go-versions are made via unauthenticated requests, which are limited to60 requests per hour per IP.If more requests are made within the time frame, then the action leverages theraw API to retrieve the version-manifest. This approach does not impose a rate limit and hence facilitates unrestricted consumption. This is particularly beneficial for GHES runners, which often share the same IP, to avoid the quick exhaustion of the unauthenticated rate limit.If that fails as well the action will try to download versions directly fromhttps://go.dev/dl.
If that fails as well you can get a higher rate limit withgenerating a personal access token on github.com and passing it as thetoken input to the action:
uses:actions/setup-go@v6with:token:${{ secrets.GH_DOTCOM_TOKEN }}go-version:'1.18'
If the runner is not able to access github.com, any Go versions requested during a workflow run must come from the runner's tool cache.See "Setting up the tool cache on self-hosted runners without internet access"for more information.
When using thesetup-go action in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:
permissions:contents:read# access to check out code and install dependencies
The scripts and documentation in this project are released under theMIT License
Contributions are welcome! SeeContributor's Guide
👋 Be nice. Seeour code of conduct
About
Set up your GitHub Actions workflow with a specific version of Go
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.