Skip to content

Commit 3f7a230

Browse files
committed
Sometimes install Go version even when one exists
1 parent 7323d4e commit 3f7a230

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,6 @@ func checkForUnsupportedVersions(v versionInfo) (msg, version string) {
737737
"). Writing an environment file not specifying any version of Go."
738738
version = ""
739739
diagnostics.EmitUnsupportedVersionGoMod(msg)
740-
} else if v.goEnvVersionFound && outsideSupportedRange(v.goEnvVersion) {
741-
msg = "The version of Go installed in the environment (" + v.goEnvVersion +
742-
") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion +
743-
"). Writing an environment file not specifying any version of Go."
744-
version = ""
745-
diagnostics.EmitUnsupportedVersionEnvironment(msg)
746740
}
747741

748742
return msg, version
@@ -768,10 +762,20 @@ func checkForVersionsNotFound(v versionInfo) (msg, version string) {
768762
}
769763

770764
if v.goEnvVersionFound && !v.goModVersionFound {
771-
msg = "No `go.mod` file found. Version " + v.goEnvVersion + " installed in the " +
772-
"environment. Writing an environment file not specifying any version of Go."
773-
version = ""
774-
diagnostics.EmitNoGoMod(msg)
765+
if outsideSupportedRange(v.goEnvVersion) {
766+
msg = "No `go.mod` file found. The version of Go installed in the environment (" +
767+
v.goEnvVersion + ") is outside of the supported range (" + minGoVersion + "-" +
768+
maxGoVersion + "). Writing an environment file specifying the maximum supported " +
769+
"version of Go (" + maxGoVersion + ")."
770+
version = maxGoVersion
771+
diagnostics.EmitNoGoModAndGoEnvUnsupported(msg)
772+
} else {
773+
msg = "No `go.mod` file found. Version " + v.goEnvVersion + " installed in the " +
774+
"environment is supported. Writing an environment file not specifying any " +
775+
"version of Go."
776+
version = ""
777+
diagnostics.EmitNoGoModAndGoEnvSupported(msg)
778+
}
775779
}
776780

777781
return msg, version
@@ -789,10 +793,18 @@ func compareVersions(v versionInfo) (msg, version string) {
789793
"file (" + v.goModVersion + ")."
790794
version = v.goModVersion
791795
diagnostics.EmitVersionGoModHigherVersionEnvironment(msg)
796+
} else if outsideSupportedRange(v.goEnvVersion) {
797+
msg = "The version of Go installed in the environment (" + v.goEnvVersion +
798+
") is outside of the supported range (" + minGoVersion + "-" + maxGoVersion + "). " +
799+
"Writing an environment file specifying the version of Go from the `go.mod` file (" +
800+
v.goModVersion + ")."
801+
version = v.goModVersion
802+
diagnostics.EmitVersionGoModSupportedAndGoEnvUnsupported(msg)
792803
} else {
804+
793805
msg = "The version of Go installed in the environment (" + v.goEnvVersion +
794-
") is high enough for the version found in the `go.mod` file (" + v.goModVersion +
795-
"). Writing an environment file not specifying any version of Go."
806+
") is supported and is high enough for the version found in the `go.mod` file (" +
807+
v.goModVersion + "). Writing an environment file not specifying any version of Go."
796808
version = ""
797809
diagnostics.EmitVersionGoModNotHigherVersionEnvironment(msg)
798810
}

go/extractor/cli/go-autobuilder/go-autobuilder_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ func TestGetVersionToInstall(t *testing.T) {
4949
{"9999.0", true, "1.1", true}: "",
5050
{"9999.0", true, "", false}: "",
5151
// Go installation found with version below minGoVersion
52-
{"1.20", true, "1.2.2", true}: "",
53-
{"1.11", true, "1.2.2", true}: "",
54-
{"", false, "1.2.2", true}: "",
52+
{"1.20", true, "1.2.2", true}: "1.20",
53+
{"1.11", true, "1.2.2", true}: "1.11",
54+
{"", false, "1.2.2", true}: maxGoVersion,
5555
// Go installation found with version above maxGoVersion
56-
{"1.20", true, "9999.0.1", true}: "",
57-
{"1.11", true, "9999.0.1", true}: "",
58-
{"", false, "9999.0.1", true}: "",
56+
{"1.20", true, "9999.0.1", true}: "1.20",
57+
{"1.11", true, "9999.0.1", true}: "1.11",
58+
{"", false, "9999.0.1", true}: maxGoVersion,
5959

6060
// checkForVersionsNotFound()
6161

go/extractor/diagnostics/diagnostics.go

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,43 +205,43 @@ func EmitUnsupportedVersionGoMod(msg string) {
205205
)
206206
}
207207

208-
func EmitUnsupportedVersionEnvironment(msg string) {
208+
func EmitNoGoModAndNoGoEnv(msg string) {
209209
emitDiagnostic(
210-
"go/autobuilder/env-unsupported-version-in-environment",
211-
"Unsupported Go version in environment",
210+
"go/autobuilder/env-no-go-mod-and-no-go-env",
211+
"No `go.mod` file found and no Go version in environment",
212212
msg,
213213
severityNote,
214214
telemetryOnly,
215215
noLocation,
216216
)
217217
}
218218

219-
func EmitNoGoModAndNoGoEnv(msg string) {
219+
func EmitNoGoEnv(msg string) {
220220
emitDiagnostic(
221-
"go/autobuilder/env-no-go-mod-and-no-go-env",
222-
"No `go.mod` file found and no Go version in environment",
221+
"go/autobuilder/env-no-go-env",
222+
"No Go version in environment",
223223
msg,
224224
severityNote,
225225
telemetryOnly,
226226
noLocation,
227227
)
228228
}
229229

230-
func EmitNoGoEnv(msg string) {
230+
func EmitNoGoModAndGoEnvUnsupported(msg string) {
231231
emitDiagnostic(
232-
"go/autobuilder/env-no-go-env",
233-
"No Go version in environment",
232+
"go/autobuilder/env-no-go-mod-go-env-unsupported",
233+
"No `go.mod` file found and Go version in environment is unsupported",
234234
msg,
235235
severityNote,
236236
telemetryOnly,
237237
noLocation,
238238
)
239239
}
240240

241-
func EmitNoGoMod(msg string) {
241+
func EmitNoGoModAndGoEnvSupported(msg string) {
242242
emitDiagnostic(
243-
"go/autobuilder/env-no-go-mod",
244-
"No `go.mod` file found",
243+
"go/autobuilder/env-no-go-mod-go-env-supported",
244+
"No `go.mod` file found and Go version in environment is supported",
245245
msg,
246246
severityNote,
247247
telemetryOnly,
@@ -260,6 +260,17 @@ func EmitVersionGoModHigherVersionEnvironment(msg string) {
260260
)
261261
}
262262

263+
func EmitVersionGoModSupportedAndGoEnvUnsupported(msg string) {
264+
emitDiagnostic(
265+
"go/autobuilder/env-version-go-mod-higher-than-go-env",
266+
"The Go version in `go.mod` file is higher than the Go version in environment",
267+
msg,
268+
severityNote,
269+
telemetryOnly,
270+
noLocation,
271+
)
272+
}
273+
263274
func EmitVersionGoModNotHigherVersionEnvironment(msg string) {
264275
emitDiagnostic(
265276
"go/autobuilder/env-version-go-mod-lower-than-or-equal-to-go-env",

0 commit comments

Comments
 (0)