mirror of
https://github.com/actions/setup-go.git
synced 2025-08-01 04:03:48 +00:00
Merge 145e58d96c
into dca8468d37
This commit is contained in:
commit
10f5df1b29
4 changed files with 118 additions and 9 deletions
|
@ -460,8 +460,15 @@ 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] : '';
|
||||
// toolchain directive: https://go.dev/ref/mod#go-mod-file-toolchain
|
||||
const matchToolchain = contents.match(/^toolchain go(\d+(\.\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
|
@ -11,6 +11,7 @@ import os from 'os';
|
|||
|
||||
export async function run() {
|
||||
try {
|
||||
setToolchain();
|
||||
//
|
||||
// versionSpec is optional. If supplied, install / use from the tool cache
|
||||
// If not supplied then problem matchers will still be setup. Useful for self-hosted.
|
||||
|
@ -160,3 +161,20 @@ function resolveVersionInput(): string {
|
|||
|
||||
return version;
|
||||
}
|
||||
|
||||
function setToolchain() {
|
||||
// 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
|
||||
const toolchain = 'local';
|
||||
const toolchainVar = 'GOTOOLCHAIN';
|
||||
|
||||
// set the value in process env so any `go` commands run as child-process
|
||||
// don't cause toolchain downloads
|
||||
process.env[toolchainVar] = toolchain;
|
||||
// and in the runner env so e.g. a user running `go mod tidy` won't cause it
|
||||
core.exportVariable(toolchainVar, toolchain);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue