Merge branch 'actions:main' into restore-only

This commit is contained in:
Antoine Toulme 2025-09-02 16:14:23 -07:00 committed by GitHub
commit 65d092b907
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 3282 additions and 372 deletions

View file

@ -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();

View file

@ -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
);
}