Compare commits

...
Author SHA1 Message Date
dependabot[bot] 802e89cd73 chore(deps-dev): bump handlebars from 4.7.9 to 4.7.10 (#802)
Bumps [handlebars](https://github.com/handlebars-lang/handlebars.js) from 4.7.9 to 4.7.10.
- [Release notes](https://github.com/handlebars-lang/handlebars.js/releases)
- [Changelog](https://github.com/handlebars-lang/handlebars.js/blob/v4.7.10/release-notes.md)
- [Commits](https://github.com/handlebars-lang/handlebars.js/compare/v4.7.9...v4.7.10)

---
updated-dependencies:
- dependency-name: handlebars
  dependency-version: 4.7.10
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-11-05 17:01:42 -06:00
Arne Jørgensen 7d2730e317 Add support for rc and beta versions in go.mod file (#701)
* Add support for rc and beta versions in go.mod file

The regex in `parseGoVersionFile()` didn't consider rc and beta
versions. The regex has been extended.

In `findMatch()` the match is checked using `semver.satisfies()`. But
`semver.satisfies()` doesn't no about Go's non-semver rc and beta
version formats (1.16c1 instead of 1.16.0-rc.1).

We cannot use `makeSemver()` on `versionSpec` and compare the result
using `semver.satisfies()` because `versionSpec` could be, well, a
spec. Instead we first check if there is a strict match between the
candidate version and the versionSpec.

Fixes #525.

* Add support for beta versions in go.mod toolchain directive

* Support prerelease versions in the toolchain cache
2026-11-03 14:14:03 -06:00
v-mahabaleshwarsandmahabaleshwars b2a9ab24f0 Clarify description of go-bin-path output and its fallback behavior (#803)
* docs: clarify description of go-bin-path output and its fallback behavior

* fix: add newline at end of action.yml for proper formatting

* fix: remove unnecessary newline in action.yml

* fix: add missing newline at end of action.yml

---------

Co-authored-by: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com>
2026-11-02 14:43:35 -06:00
v-jitenderpalsingh 3c1b57c66a Add support for native Go version syntax in go-version input (#804)
* Add support for native Go version syntax in go-version input

* Enhance Go-native version handling and update tests and documentation

* Update docs
2026-11-02 12:49:42 -06:00
9 changed files with 520 additions and 26 deletions
+1
View File
@@ -94,6 +94,7 @@ the [check-latest input](docs/advanced-usage.md#check-latest-version).
The `go-version` input supports the following syntax:
- Specific versions: `1.25`, `1.24.11`, `1.24.0-rc.1`, `1.23.0-beta.1`
- Native Go versions: `go1.21`, `go1.21.5`, `go1.18beta2`, `go1.21rc2`. `go1.21` resolves to exactly `1.21.0`, unlike `1.21`, which matches patch releases.
- 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: `stable`, `oldstable`
- Wildcards: `1.25.x`, `1.x`
+177
View File
@@ -1,4 +1,181 @@
[
{
"version": "go1.18beta2",
"stable": false,
"files": [
{
"filename": "go1.18beta2.src.tar.gz",
"os": "",
"arch": "",
"version": "go1.18beta2",
"sha256": "3cb14e2c82da366f7393c988f1f3fc2c16b71a5492bd3d49d35886cdf27a9d13",
"size": 22816245,
"kind": "source"
},
{
"filename": "go1.18beta2.darwin-amd64.tar.gz",
"os": "darwin",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "83fa94b3101d1a00dc5685645e4b49809a5dad18ce19ab449392806a85c05125",
"size": 143466224,
"kind": "archive"
},
{
"filename": "go1.18beta2.darwin-amd64.pkg",
"os": "darwin",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "fcab5fbe2b9a78bd677c008914df4ee1079178e1c96592b85fa0bd04e2e8e099",
"size": 143951639,
"kind": "installer"
},
{
"filename": "go1.18beta2.darwin-arm64.tar.gz",
"os": "darwin",
"arch": "arm64",
"version": "go1.18beta2",
"sha256": "b442585cbd50759bd11d7a9971e02ec3b2e8cfc1ff1094fa23afadc9e3889689",
"size": 137682754,
"kind": "archive"
},
{
"filename": "go1.18beta2.darwin-arm64.pkg",
"os": "darwin",
"arch": "arm64",
"version": "go1.18beta2",
"sha256": "61425e05dfffce91066bf3625d945baa377c13c659b4ca6fded39bcb391ef2c7",
"size": 138172943,
"kind": "installer"
},
{
"filename": "go1.18beta2.freebsd-386.tar.gz",
"os": "freebsd",
"arch": "386",
"version": "go1.18beta2",
"sha256": "f45899dcc440c9943b3af11a2856959e1ffd9fb11d0dbdbe6398615a96715751",
"size": 112424968,
"kind": "archive"
},
{
"filename": "go1.18beta2.freebsd-amd64.tar.gz",
"os": "freebsd",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "f5688d21a0e02991445b7992f01fc5fda459c84a1812b3b08c2ada4a98e74b5e",
"size": 141351456,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-386.tar.gz",
"os": "linux",
"arch": "386",
"version": "go1.18beta2",
"sha256": "74ac524d7d17df606cc74059bf30efce35bb6930f950110dd79cc58ba057f186",
"size": 112609338,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-amd64.tar.gz",
"os": "linux",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "b5dacafa59737cfb0d657902b70c2ad1b6bb4ed15e85ea2806f72ce3d4824688",
"size": 141429704,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-arm64.tar.gz",
"os": "linux",
"arch": "arm64",
"version": "go1.18beta2",
"sha256": "21e4248594401568c2e8704b9d26c6185a61f46b4f17e1a628bf1b5d9a010503",
"size": 108461508,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-armv6l.tar.gz",
"os": "linux",
"arch": "armv6l",
"version": "go1.18beta2",
"sha256": "bc958a63b51c44762ec026ab587b0261e94cf6337613bfbbcfbd0414fb95f7b6",
"size": 109806288,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-ppc64le.tar.gz",
"os": "linux",
"arch": "ppc64le",
"version": "go1.18beta2",
"sha256": "573916974201745360883102c80482e1d6730683d1a4a6bb4b469978d4f99d30",
"size": 108654946,
"kind": "archive"
},
{
"filename": "go1.18beta2.linux-s390x.tar.gz",
"os": "linux",
"arch": "s390x",
"version": "go1.18beta2",
"sha256": "860ee3e5cd68fd36d3d49654adc37b9450584d07f0745f7f461080d9cc7749e1",
"size": 111316368,
"kind": "archive"
},
{
"filename": "go1.18beta2.windows-386.zip",
"os": "windows",
"arch": "386",
"version": "go1.18beta2",
"sha256": "666b808f6835f928aa9d8ffa065304af61540b579b4d0eb5c55b7f2a7ec9fff2",
"size": 128931729,
"kind": "archive"
},
{
"filename": "go1.18beta2.windows-386.msi",
"os": "windows",
"arch": "386",
"version": "go1.18beta2",
"sha256": "b3ea5bb064c87e47871488cd15bc99ebd0919529acc97a684e44ef683e459acb",
"size": 113459200,
"kind": "installer"
},
{
"filename": "go1.18beta2.windows-amd64.zip",
"os": "windows",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "e2a3e0ee984205be36d59f333a7e327ab14517b7c3a11d9b8651e02895ced69a",
"size": 157785083,
"kind": "archive"
},
{
"filename": "go1.18beta2.windows-amd64.msi",
"os": "windows",
"arch": "amd64",
"version": "go1.18beta2",
"sha256": "36df8cad76eff69033b748cf71343c8d3f73b72067d57be52ec4996eb05539e4",
"size": 138551296,
"kind": "installer"
},
{
"filename": "go1.18beta2.windows-arm64.zip",
"os": "windows",
"arch": "arm64",
"version": "go1.18beta2",
"sha256": "9ed027803361cab0b8c338e698e16586d83d973f01815e17d2ab2990e29b8c66",
"size": 123458965,
"kind": "archive"
},
{
"filename": "go1.18beta2.windows-arm64.msi",
"os": "windows",
"arch": "arm64",
"version": "go1.18beta2",
"sha256": "cfbe500daed74dd26e556619a9f0e0b3d20f8a4cf31b48618c4285f47dca1f0c",
"size": 108797952,
"kind": "installer"
}
]
},
{
"version": "go1.13.7",
"stable": true,
+246 -3
View File
@@ -343,11 +343,11 @@ describe('setup-go', () => {
expect(fileName).toBe('go1.13.7.windows-386.zip');
});
it('finds unstable pre-release version', async () => {
it('finds unstable release candidate', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.14, stable=false => go1.14rc1
// spec: 1.14.0-rc.1, stable=false => go1.14rc1
const match: IGoVersion | undefined = await im.findMatch('1.14.0-rc.1');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
@@ -356,6 +356,46 @@ describe('setup-go', () => {
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
});
it('finds unstable beta version', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.18.0-beta.2, stable=false => go1.18beta2
const match: im.IGoVersion | undefined =
await im.findMatch('1.18.0-beta.2');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.18beta2');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.18beta2.linux-amd64.tar.gz');
});
it('finds unstable release candidate (go version format)', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.14rc1, stable=false => go1.14rc1
const match: im.IGoVersion | undefined = await im.findMatch('1.14rc1');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.14rc1');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.14rc1.linux-amd64.tar.gz');
});
it('finds unstable beta version (go version format)', async () => {
os.platform = 'linux';
os.arch = 'x64';
// spec: 1.18beta2, stable=false => go1.18beta2
const match: im.IGoVersion | undefined = await im.findMatch('1.18beta2');
expect(match).toBeDefined();
const version: string = match ? match.version : '';
expect(version).toBe('go1.18beta2');
const fileName = match ? match.files[0].filename : '';
expect(fileName).toBe('go1.18beta2.linux-amd64.tar.gz');
});
it('evaluates to stable with input as true', async () => {
inputs['go-version'] = '1.13.0';
inputs.stable = 'true';
@@ -431,6 +471,26 @@ describe('setup-go', () => {
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('finds a rc version of go already in the cache', async () => {
inputs['go-version'] = '1.14rc1';
const toolPath = path.normalize('/cache/go/1.14.0rc.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
expect(logSpy).toHaveBeenCalledWith(`Found in cache @ ${toolPath}`);
});
it('finds a rc version in the cache and adds it to the path', async () => {
inputs['go-version'] = '1.14rc1';
const toolPath = path.normalize('/cache/go/1.14.0.rc.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
const expPath = path.join(toolPath, 'bin');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('handles unhandled error and reports error', async () => {
const errMsg = 'unhandled error message';
inputs['go-version'] = '1.13.0';
@@ -487,6 +547,51 @@ describe('setup-go', () => {
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('downloads a rc version not in the cache', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = '1.14rc1';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => '/some/temp/path');
const toolPath = path.normalize('/cache/go/1.14.0-rc.1/x64');
extractTarSpy.mockImplementation(() => '/some/other/temp/path');
cacheSpy.mockImplementation(() => toolPath);
await main.run();
const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(extractTarSpy).toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('downloads a rc version not in the cache (windows)', async () => {
os.platform = 'win32';
os.arch = 'x64';
inputs['go-version'] = '1.14rc1';
process.env['RUNNER_TEMP'] = 'C:\\temp\\';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(() => 'C:\\temp\\some\\path');
extractZipSpy.mockImplementation(() => 'C:\\temp\\some\\other\\path');
const toolPath = path.normalize('C:\\cache\\go\\1.21.0-rc.2\\x64');
cacheSpy.mockImplementation(() => toolPath);
await main.run();
const expPath = path.win32.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalledWith(
'https://go.dev/dl/go1.14rc1.windows-amd64.zip',
'C:\\temp\\go1.14rc1.windows-amd64.zip',
undefined
);
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('does not find a version that does not exist', async () => {
os.platform = 'linux';
os.arch = 'x64';
@@ -866,6 +971,11 @@ describe('setup-go', () => {
expect(im.makeSemver('1.10rc1')).toBe('1.10.0-rc.1');
});
it('preserves already-normalized prerelease versions', () => {
expect(im.makeSemver('1.18.0-beta.2')).toBe('1.18.0-beta.2');
expect(im.makeSemver('1.21.0-rc.2')).toBe('1.21.0-rc.2');
});
it('converts dot zero versions', async () => {
expect(im.makeSemver('1.13')).toBe('1.13.0');
});
@@ -874,6 +984,102 @@ describe('setup-go', () => {
expect(im.makeSemver('1.13.1')).toBe('1.13.1');
});
it('isGoNativeVersion accepts supported Go-native version formats', () => {
expect(im.isGoNativeVersion('go1.21')).toBe(true);
expect(im.isGoNativeVersion('go1.21.5')).toBe(true);
expect(im.isGoNativeVersion('go1.18beta2')).toBe(true);
expect(im.isGoNativeVersion('go1.21rc2')).toBe(true);
expect(im.isGoNativeVersion('go1.21.x')).toBe(false);
expect(im.isGoNativeVersion('go^1.21')).toBe(false);
expect(im.isGoNativeVersion('1.21')).toBe(false);
expect(im.isGoNativeVersion('go1')).toBe(false);
expect(im.isGoNativeVersion('go1.21.5beta1')).toBe(false);
expect(im.isGoNativeVersion('go1.21.0rc1')).toBe(false);
});
it('accepts a Go-native go-version input and normalizes it', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'go1.21';
findSpy.mockImplementation(() => path.normalize('/cache/go/1.21.0/x64'));
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec go1.21');
expect(findSpy).toHaveBeenCalledWith('go', '1.21.0', 'x64');
expect(logSpy).toHaveBeenCalledWith(
'Successfully set up Go version go1.21'
);
});
it('rejects a malformed Go-native go-version input', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'go1.21.x';
await main.run();
expect(cnSpy).toHaveBeenCalledWith(
expect.stringContaining('Invalid Go version "go1.21.x"')
);
});
it('accepts a Go-native go-version input with beta suffix and normalizes it', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'go1.18beta2';
findSpy.mockImplementation(() =>
path.normalize('/cache/go/1.18.0-beta.2/x64')
);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec go1.18beta2');
expect(findSpy).toHaveBeenCalledWith('go', '1.18.0-beta.2', 'x64');
expect(logSpy).toHaveBeenCalledWith(
'Successfully set up Go version go1.18beta2'
);
});
it('accepts a Go-native go-version input with rc suffix and normalizes it', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'go1.21rc2';
findSpy.mockImplementation(() =>
path.normalize('/cache/go/1.21.0-rc.2/x64')
);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Setup go version spec go1.21rc2');
expect(findSpy).toHaveBeenCalledWith('go', '1.21.0-rc.2', 'x64');
expect(logSpy).toHaveBeenCalledWith(
'Successfully set up Go version go1.21rc2'
);
});
it('downloads a normalized Go-native version on cache miss', async () => {
os.platform = 'linux';
os.arch = 'x64';
inputs['go-version'] = 'go1.13';
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () =>
path.normalize('/cache/go/1.13.0/x64')
);
await main.run();
expect(logSpy).toHaveBeenCalledWith('Attempting to download 1.13.0...');
expect(dlSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
'Successfully set up Go version go1.13'
);
});
describe('check-latest flag', () => {
it("use local version and don't check manifest if check-latest is not specified", async () => {
os.platform = 'linux';
@@ -1197,7 +1403,7 @@ use .
});
describe('go-version-file-toolchain', () => {
const goVersions = ['1.22.0', '1.21rc2', '1.18'];
const goVersions = ['1.22.0', '1.21rc2', '1.18', '1.18beta2'];
const placeholderVersion = '1.19';
const buildGoMod = (
goVersion: string,
@@ -1297,6 +1503,43 @@ use .
});
describe('go-download-base-url', () => {
it('normalizes native versions but preserves custom download filenames', async () => {
os.platform = 'linux';
os.arch = 'x64';
const versionSpec = 'go1.21rc2';
const customBaseUrl = 'https://example.com/golang';
const toolName = im.customToolCacheName(customBaseUrl);
const toolPath = path.normalize(`/cache/${toolName}/1.21.0-rc.2/x64`);
inputs['go-version'] = versionSpec;
inputs['go-download-base-url'] = customBaseUrl;
getSpy.mockImplementationOnce(() => {
throw new Error('Not a JSON endpoint');
});
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
extractTarSpy.mockImplementation(async () => '/some/other/temp/path');
execFileSpy.mockImplementation(() => 'go version go1.21rc2 linux/amd64');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
expect(findSpy).toHaveBeenCalledWith(toolName, '1.21.0-rc.2', 'x64');
expect(getSpy).toHaveBeenCalledWith(
`${customBaseUrl}/?mode=json&include=all`
);
expect(dlSpy).toHaveBeenCalledWith(
`${customBaseUrl}/go1.21rc2.linux-amd64.tar.gz`,
undefined,
undefined
);
expect(cnSpy).toHaveBeenCalledWith(
`::add-path::${path.join(toolPath, 'bin')}${osm.EOL}`
);
});
it('downloads a version from custom base URL using version listing', async () => {
os.platform = 'linux';
os.arch = 'x64';
+2 -2
View File
@@ -3,7 +3,7 @@ description: 'Setup a Go environment and add it to the PATH'
author: 'GitHub'
inputs:
go-version:
description: 'The Go version to download (if necessary) and use. Supports semver spec and ranges. Be sure to enclose this option in single quotation marks.'
description: '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:
description: 'Path to the go.mod, go.work, .go-version, or .tool-versions file.'
check-latest:
@@ -31,7 +31,7 @@ outputs:
GOBIN:
description: 'The value of `go env GOBIN`.'
go-bin-path:
description: 'The base Go binary directory: `GOBIN`, otherwise `bin` under the first `GOPATH` entry.'
description: 'The base Go binary directory: the `GOBIN` value, otherwise `bin` under the first `GOPATH` entry when `GOBIN` is empty.'
GOROOT:
description: 'The value of `go env GOROOT`.'
GOCACHE:
+32 -8
View File
@@ -41969,6 +41969,10 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default(
let manifest;
const osPlat = external_os_default().platform();
const customBaseUrl = goDownloadBaseUrl?.replace(/\/+$/, '');
const originalVersionSpec = versionSpec;
if (isGoNativeVersion(versionSpec)) {
versionSpec = makeSemver(versionSpec);
}
if (versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable) {
if (customBaseUrl) {
@@ -42006,8 +42010,12 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default(
const toolCacheName = customBaseUrl
? customToolCacheName(customBaseUrl)
: 'go';
// Convert prerelease specs (1.21rc2) to semver (1.21.0-rc.2).
const cacheSpec = /^\d+\.\d+(\.\d+)?(beta|rc)\d+$/.test(versionSpec)
? makeSemver(versionSpec)
: versionSpec;
// check cache
const toolPath = find(toolCacheName, versionSpec, arch);
const toolPath = find(toolCacheName, cacheSpec, arch);
// If not found in cache, download
if (toolPath) {
core_info(`Found in cache @ ${toolPath}`);
@@ -42023,7 +42031,7 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default(
const skipVersionListing = NO_VERSION_LISTING_BASE_URLS.some(url => customBaseUrl.toLowerCase() === url.toLowerCase());
if (skipVersionListing) {
core_info('Skipping version listing for known direct-download URL. Constructing download URL directly.');
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
info = getInfoFromDirectDownload(originalVersionSpec, arch, customBaseUrl);
}
else {
try {
@@ -42033,7 +42041,7 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default(
core_info('Version listing not available from custom URL. Constructing download URL directly.');
}
if (!info) {
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
info = getInfoFromDirectDownload(originalVersionSpec, arch, customBaseUrl);
}
}
try {
@@ -42043,10 +42051,10 @@ async function getGo(versionSpec, checkLatest, auth, arch = external_os_default(
catch (err) {
const downloadUrl = info?.downloadUrl || customBaseUrl;
if (err instanceof HTTPError && err.httpStatusCode === 404) {
throw new Error(`The requested Go version ${versionSpec} is not available for platform ${osPlat}/${arch}. ` +
throw new Error(`The requested Go version ${originalVersionSpec} is not available for platform ${osPlat}/${arch}. ` +
`Download URL returned HTTP 404: ${downloadUrl}`, { cause: err });
}
throw new Error(`Failed to download Go ${versionSpec} for platform ${osPlat}/${arch} ` +
throw new Error(`Failed to download Go ${originalVersionSpec} for platform ${osPlat}/${arch} ` +
`from ${downloadUrl}: ${err}`, { cause: err });
}
}
@@ -42316,7 +42324,8 @@ async function findMatch(versionSpec, arch = external_os_default().arch(), dlUrl
const candidate = candidates[i];
const version = makeSemver(candidate.version);
core_debug(`check ${version} satisfies ${versionSpec}`);
if (node_modules_semver.satisfies(version, versionSpec)) {
if (candidate.version.replace(/^go/, '') === versionSpec ||
node_modules_semver.satisfies(version, versionSpec)) {
goFile = candidate.files.find(file => {
core_debug(`${file.arch}===${archFilter} && ${file.os}===${platFilter}`);
return file.arch === archFilter && file.os === platFilter;
@@ -42335,6 +42344,10 @@ async function findMatch(versionSpec, arch = external_os_default().arch(), dlUrl
}
return result;
}
function isGoNativeVersion(version) {
const expression = /^go[1-9]\d*\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)|(?:beta|rc)[1-9]\d*)?$/;
return expression.test(version);
}
//
// Convert the go version syntax into semver for semver matching
// 1.13.1 => 1.13.1
@@ -42342,6 +42355,10 @@ async function findMatch(versionSpec, arch = external_os_default().arch(), dlUrl
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
function makeSemver(version) {
const validVersion = node_modules_semver.valid(version);
if (validVersion) {
return validVersion;
}
version = version.replace('go', '');
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
const parts = version.split('-');
@@ -42366,13 +42383,13 @@ function parseGoVersionFile(versionFilePath) {
// 'GOTOOLCHAIN' has been explicitly set
if (process.env[GOTOOLCHAIN_ENV_VAR] !== GOTOOLCHAIN_LOCAL_VAL) {
// toolchain directive: https://go.dev/ref/mod#go-mod-file-toolchain
const matchToolchain = contents.match(/^toolchain go(1\.\d+(?:\.\d+|rc\d+)?)/m);
const matchToolchain = contents.match(/^toolchain go(1\.\d+(?:\.\d+|(beta|rc)\d+)?)/m);
if (matchToolchain) {
return matchToolchain[1];
}
}
// go directive: https://go.dev/ref/mod#go-mod-file-go
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
const matchGo = contents.match(/^go (\d+(\.\d+)*(?:\.\d+|(beta|rc)\d+)?)/m);
return matchGo ? matchGo[1] : '';
}
else if (external_path_namespaceObject.basename(versionFilePath) === '.tool-versions') {
@@ -97835,6 +97852,13 @@ function resolveVersionInput() {
warning('Both go-version and go-version-file inputs are specified, only go-version will be used');
}
if (version) {
const customBaseUrl = getInput('go-download-base-url') ||
process.env['GO_DOWNLOAD_BASE_URL'];
if (version.startsWith('go') &&
!customBaseUrl &&
!isGoNativeVersion(version)) {
throw new Error(`Invalid Go version "${version}". Go-native versions must look like go1.21, go1.21.5, go1.18beta2, or go1.21rc2. For version ranges, use SemVer syntax (e.g. ~1.21, ^1.21).`);
}
return version;
}
if (versionFilePath) {
+7 -1
View File
@@ -50,9 +50,13 @@ steps:
- The preinstalled patch version is generally the latest available. When a new patch is released, it replaces the previously preinstalled version on the runner.
- Using the most recent patch version speeds up setup because the required Go version is already installed on the runner and no download is needed.
The `go-version` input also accepts native Go version strings: `go1.21.5`, `go1.18beta2`, and `go1.21rc2` normalize to `1.21.5`, `1.18.0-beta.2`, and `1.21.0-rc.2`, respectively. `go1.21` resolves to exactly `1.21.0`; use `1.21` for matching patch releases. For ranges and wildcards, use SemVer syntax such as `~1.21` or `1.21.x`, not `go1.21.x`.
To try a **pre-release**:
Download and use beta or RC Go versions as needed.
The `go-version` input also accepts native Go version strings: `go1.21.5`, `go1.18beta2`, and `go1.21rc2` normalize to `1.21.5`, `1.18.0-beta.2`, and `1.21.0-rc.2`, respectively. `go1.21` resolves to exactly `1.21.0`; use `1.21` for matching patch releases. For ranges and wildcards, use SemVer syntax such as `~1.21` or `1.21.x`, not `go1.21.x`.
```yaml
# RC version
steps:
@@ -431,7 +435,7 @@ Once Go is on the `PATH`, the action exposes the most commonly needed `go env` v
| --- | --- |
| `GOPATH` | Go workspace root; `bin` and `pkg/mod` live under it |
| `GOBIN` | Go 1.27+ reports an implicit `$GOPATH/bin` default; earlier releases are empty unless `GOBIN` is set |
| `go-bin-path` | The base Go binary directory (`GOBIN` or `$GOPATH/bin`), using the first `GOPATH` entry. Cross-compiled binaries go one level deeper, in `$GOPATH/bin/$GOOS_$GOARCH` |
| `go-bin-path` | Uses `GOBIN`, or falls back to `bin` under the first `GOPATH` entry when `GOBIN` is empty. It normally matches `GOBIN` on Go 1.27+; the fallback is a convenience for earlier releases. When `GOBIN` is not explicitly set (in the environment or via `go env -w`), cross-compiled binaries go one level deeper, in `$GOPATH/bin/${GOOS}_${GOARCH}` |
| `GOROOT` | Installation directory of the Go toolchain in use |
| `GOCACHE` | Build cache directory |
| `GOMODCACHE` | Module cache directory |
@@ -459,6 +463,8 @@ The `go-download-base-url` input lets you download Go from a mirror or alternati
When a custom base URL is provided, the action skips the `actions/go-versions` manifest lookup and downloads directly from the specified URL.
> **Note:** When constructing direct-download filenames, the original version string is preserved; native Go version normalization is used only for matching and tool cache lookups.
**Using the [Microsoft build of Go](https://github.com/microsoft/go):**
```yaml
+4 -4
View File
@@ -3890,13 +3890,13 @@
"license": "ISC"
},
"node_modules/handlebars": {
"version": "4.7.9",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz",
"integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==",
"version": "4.7.10",
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.10.tgz",
"integrity": "sha512-P5VJMVM7qgBn6vjXMw8WG9uVI+ncf2pi72j4de4yz5ZULLj2RGqLYaKOYGsgyrViQ0tePOVlN1tDCCXXtFqXKg==",
"dev": true,
"license": "MIT",
"dependencies": {
"minimist": "^1.2.5",
"minimist": "^1.2.8",
"neo-async": "^2.6.2",
"source-map": "^0.6.1",
"wordwrap": "^1.0.0"
+39 -8
View File
@@ -60,6 +60,11 @@ export async function getGo(
const osPlat: string = os.platform();
const customBaseUrl = goDownloadBaseUrl?.replace(/\/+$/, '');
const originalVersionSpec = versionSpec;
if (isGoNativeVersion(versionSpec)) {
versionSpec = makeSemver(versionSpec);
}
if (
versionSpec === StableReleaseAlias.Stable ||
versionSpec === StableReleaseAlias.OldStable
@@ -123,8 +128,13 @@ export async function getGo(
? customToolCacheName(customBaseUrl)
: 'go';
// Convert prerelease specs (1.21rc2) to semver (1.21.0-rc.2).
const cacheSpec = /^\d+\.\d+(\.\d+)?(beta|rc)\d+$/.test(versionSpec)
? makeSemver(versionSpec)
: versionSpec;
// check cache
const toolPath = tc.find(toolCacheName, versionSpec, arch);
const toolPath = tc.find(toolCacheName, cacheSpec, arch);
// If not found in cache, download
if (toolPath) {
core.info(`Found in cache @ ${toolPath}`);
@@ -146,7 +156,11 @@ export async function getGo(
core.info(
'Skipping version listing for known direct-download URL. Constructing download URL directly.'
);
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
info = getInfoFromDirectDownload(
originalVersionSpec,
arch,
customBaseUrl
);
} else {
try {
info = await getInfoFromDist(versionSpec, arch, customBaseUrl);
@@ -156,7 +170,11 @@ export async function getGo(
);
}
if (!info) {
info = getInfoFromDirectDownload(versionSpec, arch, customBaseUrl);
info = getInfoFromDirectDownload(
originalVersionSpec,
arch,
customBaseUrl
);
}
}
@@ -167,13 +185,13 @@ export async function getGo(
const downloadUrl = info?.downloadUrl || customBaseUrl;
if (err instanceof tc.HTTPError && err.httpStatusCode === 404) {
throw new Error(
`The requested Go version ${versionSpec} is not available for platform ${osPlat}/${arch}. ` +
`The requested Go version ${originalVersionSpec} is not available for platform ${osPlat}/${arch}. ` +
`Download URL returned HTTP 404: ${downloadUrl}`,
{cause: err}
);
}
throw new Error(
`Failed to download Go ${versionSpec} for platform ${osPlat}/${arch} ` +
`Failed to download Go ${originalVersionSpec} for platform ${osPlat}/${arch} ` +
`from ${downloadUrl}: ${err}`,
{cause: err}
);
@@ -585,7 +603,10 @@ export async function findMatch(
const version = makeSemver(candidate.version);
core.debug(`check ${version} satisfies ${versionSpec}`);
if (semver.satisfies(version, versionSpec)) {
if (
candidate.version.replace(/^go/, '') === versionSpec ||
semver.satisfies(version, versionSpec)
) {
goFile = candidate.files.find(file => {
core.debug(
`${file.arch}===${archFilter} && ${file.os}===${platFilter}`
@@ -610,6 +631,12 @@ export async function findMatch(
return result;
}
export function isGoNativeVersion(version: string): boolean {
const expression =
/^go[1-9]\d*\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*)|(?:beta|rc)[1-9]\d*)?$/;
return expression.test(version);
}
//
// Convert the go version syntax into semver for semver matching
// 1.13.1 => 1.13.1
@@ -617,6 +644,10 @@ export async function findMatch(
// 1.10beta1 => 1.10.0-beta.1, 1.10rc1 => 1.10.0-rc.1
// 1.8.5beta1 => 1.8.5-beta.1, 1.8.5rc1 => 1.8.5-rc.1
export function makeSemver(version: string): string {
const validVersion = semver.valid(version);
if (validVersion) {
return validVersion;
}
version = version.replace('go', '');
version = version.replace('beta', '-beta.').replace('rc', '-rc.');
const parts = version.split('-');
@@ -654,7 +685,7 @@ export function parseGoVersionFile(versionFilePath: string): string {
if (process.env[GOTOOLCHAIN_ENV_VAR] !== GOTOOLCHAIN_LOCAL_VAL) {
// toolchain directive: https://go.dev/ref/mod#go-mod-file-toolchain
const matchToolchain = contents.match(
/^toolchain go(1\.\d+(?:\.\d+|rc\d+)?)/m
/^toolchain go(1\.\d+(?:\.\d+|(beta|rc)\d+)?)/m
);
if (matchToolchain) {
return matchToolchain[1];
@@ -662,7 +693,7 @@ export function parseGoVersionFile(versionFilePath: string): string {
}
// go directive: https://go.dev/ref/mod#go-mod-file-go
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
const matchGo = contents.match(/^go (\d+(\.\d+)*(?:\.\d+|(beta|rc)\d+)?)/m);
return matchGo ? matchGo[1] : '';
} else if (path.basename(versionFilePath) === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
+12
View File
@@ -215,6 +215,18 @@ function resolveVersionInput(): string {
}
if (version) {
const customBaseUrl =
core.getInput('go-download-base-url') ||
process.env['GO_DOWNLOAD_BASE_URL'];
if (
version.startsWith('go') &&
!customBaseUrl &&
!installer.isGoNativeVersion(version)
) {
throw new Error(
`Invalid Go version "${version}". Go-native versions must look like go1.21, go1.21.5, go1.18beta2, or go1.21rc2. For version ranges, use SemVer syntax (e.g. ~1.21, ^1.21).`
);
}
return version;
}