File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -61,11 +61,19 @@ var goVersion = ""
61
61
// Returns the current Go version as returned by 'go version', e.g. go1.14.4
62
62
func getEnvGoVersion () string {
63
63
if goVersion == "" {
64
- gover , err := exec .Command ("go" , "version" ).CombinedOutput ()
64
+ // Since Go 1.21, running 'go version' in a directory with a 'go.mod' file will attempt to
65
+ // download the version of Go specified in there. That may either fail or result in us just
66
+ // being told what's already in 'go.mod'. Setting 'GOTOOLCHAIN' to 'local' will force it
67
+ // to use the local Go toolchain instead.
68
+ cmd := exec .Command ("go" , "version" )
69
+ cmd .Env = append (os .Environ (), "GOTOOLCHAIN=local" )
70
+ out , err := cmd .CombinedOutput ()
71
+
65
72
if err != nil {
66
73
log .Fatalf ("Unable to run the go command, is it installed?\n Error: %s" , err .Error ())
67
74
}
68
- goVersion = parseGoVersion (string (gover ))
75
+
76
+ goVersion = parseGoVersion (string (out ))
69
77
}
70
78
return goVersion
71
79
}
You can’t perform that action at this time.
0 commit comments