This commit is contained in:
Dwi Siswanto 2026-06-23 13:21:23 -04:00 committed by GitHub
commit 894036fb2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 61 additions and 21 deletions

23
dist/setup/index.js vendored
View file

@ -52663,26 +52663,33 @@ function makeSemver(version) {
return fullVersion;
}
function parseGoVersionFile(versionFilePath) {
const moduleOrWorkspaceDirective = /^\s*go\s+(\d+(?:\.\d+)*)/m;
const toolchainDirective = /^\s*toolchain\s+go(1\.\d+(?:\.\d+|rc\d+)?)/m;
const moduleDeclaration = /^\s*module\s+\S+/m;
const workspaceUseDirective = /^\s*use(?:\s+\S+|\s*\()/m;
const contents = fs_1.default.readFileSync(versionFilePath).toString();
if (path.basename(versionFilePath) === 'go.mod' ||
path.basename(versionFilePath) === 'go.work') {
const fileName = path.basename(versionFilePath);
const isGoModOrWorkFileName = fileName === 'go.mod' || fileName === 'go.work';
const isGoModuleOrWorkspaceLike = moduleOrWorkspaceDirective.test(contents) &&
(moduleDeclaration.test(contents) || workspaceUseDirective.test(contents));
if (fileName === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
return match ? match[1].trim() : '';
}
if (isGoModOrWorkFileName || isGoModuleOrWorkspaceLike) {
// for backwards compatibility: use version from go directive if
// 'GOTOOLCHAIN' has been explicitly set
if (process.env[exports.GOTOOLCHAIN_ENV_VAR] !== exports.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(toolchainDirective);
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(moduleOrWorkspaceDirective);
return matchGo ? matchGo[1] : '';
}
else if (path.basename(versionFilePath) === '.tool-versions') {
const match = contents.match(/^golang\s+([^\n#]+)/m);
return match ? match[1].trim() : '';
}
return contents.trim();
}
function resolveStableVersionDist(versionSpec, arch) {