Skip to content

Commit d9bd547

Browse files
authored
Merge pull request #16216 from github/mbg/go/respect-gotoolchain
Go: Respect `GOTOOLCHAIN` in `GetEnvGoVersion` if already set
2 parents ce73c29 + c0d2b89 commit d9bd547

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

go/extractor/toolchain/toolchain.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ func GetEnvGoVersion() string {
3636
// being told what's already in 'go.mod'. Setting 'GOTOOLCHAIN' to 'local' will force it
3737
// to use the local Go toolchain instead.
3838
cmd := Version()
39-
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")
39+
40+
// If 'GOTOOLCHAIN' is already set, then leave it as is. This allows us to force a specific
41+
// Go version in tests and also allows users to override the system default more generally.
42+
_, hasToolchainVar := os.LookupEnv("GOTOOLCHAIN")
43+
if !hasToolchainVar {
44+
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")
45+
}
46+
4047
out, err := cmd.CombinedOutput()
4148

4249
if err != nil {

0 commit comments

Comments
 (0)