mirror of
https://github.com/actions/setup-go.git
synced 2025-09-08 11:13:38 -06:00
Merge branch 'actions:main' into restore-only
This commit is contained in:
commit
65d092b907
24 changed files with 3282 additions and 372 deletions
|
@ -8,6 +8,8 @@ import fs from 'fs';
|
|||
import os from 'os';
|
||||
import {StableReleaseAlias, isSelfHosted} from './utils';
|
||||
|
||||
export const GOTOOLCHAIN_ENV_VAR = 'GOTOOLCHAIN';
|
||||
export const GOTOOLCHAIN_LOCAL_VAL = 'local';
|
||||
const MANIFEST_REPO_OWNER = 'actions';
|
||||
const MANIFEST_REPO_NAME = 'go-versions';
|
||||
const MANIFEST_REPO_BRANCH = 'main';
|
||||
|
@ -495,8 +497,21 @@ export function parseGoVersionFile(versionFilePath: string): string {
|
|||
path.basename(versionFilePath) === 'go.mod' ||
|
||||
path.basename(versionFilePath) === 'go.work'
|
||||
) {
|
||||
const match = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return match ? match[1] : '';
|
||||
// for backwards compatibility: use version from go directive if
|
||||
// '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
|
||||
);
|
||||
if (matchToolchain) {
|
||||
return matchToolchain[1];
|
||||
}
|
||||
}
|
||||
|
||||
// go directive: https://go.dev/ref/mod#go-mod-file-go
|
||||
const matchGo = contents.match(/^go (\d+(\.\d+)*)/m);
|
||||
return matchGo ? matchGo[1] : '';
|
||||
}
|
||||
|
||||
return contents.trim();
|
||||
|
|
18
src/main.ts
18
src/main.ts
|
@ -16,6 +16,7 @@ export async function run() {
|
|||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||
//
|
||||
const versionSpec = resolveVersionInput();
|
||||
setGoToolchain();
|
||||
|
||||
const cache = core.getBooleanInput('cache');
|
||||
core.info(`Setup go version spec ${versionSpec}`);
|
||||
|
@ -160,3 +161,20 @@ function resolveVersionInput(): string {
|
|||
|
||||
return version;
|
||||
}
|
||||
|
||||
function setGoToolchain() {
|
||||
// docs: https://go.dev/doc/toolchain
|
||||
// "local indicates the bundled Go toolchain (the one that shipped with the go command being run)"
|
||||
// this is so any 'go' command is run with the selected Go version
|
||||
// and doesn't trigger a toolchain download and run commands with that
|
||||
// see e.g. issue #424
|
||||
// and a similar discussion: https://github.com/docker-library/golang/issues/472.
|
||||
// Set the value in process env so any `go` commands run as child-process
|
||||
// don't cause toolchain downloads
|
||||
process.env[installer.GOTOOLCHAIN_ENV_VAR] = installer.GOTOOLCHAIN_LOCAL_VAL;
|
||||
// and in the runner env so e.g. a user running `go mod tidy` won't cause it
|
||||
core.exportVariable(
|
||||
installer.GOTOOLCHAIN_ENV_VAR,
|
||||
installer.GOTOOLCHAIN_LOCAL_VAL
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue