Skip to content

Commit

Permalink
Merge pull request #16216 from github/mbg/go/respect-gotoolchain
Browse files Browse the repository at this point in the history
Go: Respect `GOTOOLCHAIN` in `GetEnvGoVersion` if already set
  • Loading branch information
mbg authored Apr 15, 2024
2 parents ce73c29 + c0d2b89 commit d9bd547
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/extractor/toolchain/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ func GetEnvGoVersion() string {
// being told what's already in 'go.mod'. Setting 'GOTOOLCHAIN' to 'local' will force it
// to use the local Go toolchain instead.
cmd := Version()
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")

// If 'GOTOOLCHAIN' is already set, then leave it as is. This allows us to force a specific
// Go version in tests and also allows users to override the system default more generally.
_, hasToolchainVar := os.LookupEnv("GOTOOLCHAIN")
if !hasToolchainVar {
cmd.Env = append(os.Environ(), "GOTOOLCHAIN=local")
}

out, err := cmd.CombinedOutput()

if err != nil {
Expand Down

0 comments on commit d9bd547

Please sign in to comment.