Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Set up your GitHub Actions workflow with a specific version of Go

License

NotificationsYou must be signed in to change notification settings

actions/setup-go

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Basic validationValidate 'setup-go'

This action sets up a go environment for use in actions by:

  • Optionally downloading and caching a version of Go by version and adding toPATH.
  • Registering problem matchers for error output.

Breaking changes in V6

  • 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

V5

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

Usage

Seeaction.yml

Basic

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

Check latest version

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.

Settingcheck-latest totrue has 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

Using stable/oldstable aliases

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

Caching dependency files and build outputs:

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

Getting go version from the go.mod file

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 thetoolchain directive, if there is one, otherwise
  • The version from thego directive

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 thego.mod file 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).

Matrix testing

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

Supported version syntax

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.

Usingsetup-go on GHES

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.

Recommended permissions

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

License

The scripts and documentation in this project are released under theMIT License

Contributions

Contributions are welcome! SeeContributor's Guide

Code of Conduct

👋 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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp