Skip to content

Commit 9334cfb

Browse files
committed
Change logic when go mod version above max supported version
1 parent 9c5fc97 commit 9334cfb

File tree

2 files changed

+100
-11
lines changed

2 files changed

+100
-11
lines changed

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

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -773,15 +773,60 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg, version string) {
773773
}
774774

775775
// Assuming `v.goModVersion` is above the supported range, emit a diagnostic and return the
776-
// empty string to indicate that we should not attempt to install a version of Go.
776+
// version to install, or the empty string if we should not attempt to install a version of Go.
777777
func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg, version string) {
778-
// The project is intended to be built with a version of Go that is above the supported
779-
// range. We do not install a version of Go.
780-
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
781-
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
782-
"). Not requesting any version of Go."
783-
version = ""
784-
diagnostics.EmitGoModVersionTooHigh(msg)
778+
if !v.goEnvVersionFound {
779+
// The version in the `go.mod` file is above the supported range. There is no Go version
780+
// installed. We install the maximum supported version as a best effort.
781+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
782+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
783+
"). No version of Go installed. Requesting the maximum supported version of Go (" +
784+
maxGoVersion + ")."
785+
version = maxGoVersion
786+
diagnostics.EmitGoModVersionTooHighAndNoGoEnv(msg)
787+
} else if aboveSupportedRange(v.goEnvVersion) {
788+
// The version in the `go.mod` file is above the supported range. The version of Go that
789+
// is installed is above the supported range. We do not install a version of Go.
790+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
791+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
792+
"). The version of Go installed in the environment (" + v.goEnvVersion +
793+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
794+
"). Not requesting any version of Go."
795+
version = ""
796+
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHigh(msg)
797+
} else if belowSupportedRange(v.goEnvVersion) {
798+
// The version in the `go.mod` file is above the supported range. The version of Go that
799+
// is installed is below the supported range. We install the maximum supported version as
800+
// a best effort.
801+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
802+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
803+
"). The version of Go installed in the environment (" + v.goEnvVersion +
804+
") is below the supported range (" + minGoVersion + "-" + maxGoVersion +
805+
"). Requesting the maximum supported version of Go (" + maxGoVersion + ")."
806+
version = maxGoVersion
807+
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooLow(msg)
808+
} else if semver.Compare("v"+maxGoVersion, "v"+v.goEnvVersion) > 0 {
809+
// The version in the `go.mod` file is above the supported range. The version of Go that
810+
// is installed is supported and below the maximum supported version. We install the
811+
// maximum supported version as a best effort.
812+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
813+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
814+
"). The version of Go installed in the environment (" + v.goEnvVersion +
815+
") is below the maximum supported version (" + maxGoVersion +
816+
"). Requesting the maximum supported version of Go (" + maxGoVersion + ")."
817+
version = maxGoVersion
818+
diagnostics.EmitGoModVersionTooHighAndEnvVersionBelowMax(msg)
819+
} else {
820+
// The version in the `go.mod` file is above the supported range. The version of Go that
821+
// is installed is the maximum supported version. We do not install a version of Go.
822+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion +
823+
") is above the supported range (" + minGoVersion + "-" + maxGoVersion +
824+
"). The version of Go installed in the environment (" + v.goEnvVersion +
825+
") is the maximum supported version (" + maxGoVersion +
826+
"). Not requesting any version of Go."
827+
version = ""
828+
diagnostics.EmitGoModVersionTooHighAndEnvVersionMax(msg)
829+
}
785830

786831
return msg, version
787832
}

go/extractor/diagnostics/diagnostics.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,54 @@ func EmitNoGoModAndGoEnvSupported(msg string) {
227227
)
228228
}
229229

230-
func EmitGoModVersionTooHigh(msg string) {
230+
func EmitGoModVersionTooHighAndNoGoEnv(msg string) {
231231
emitDiagnostic(
232-
"go/autobuilder/env-go-mod-version-too-high",
233-
"Go version in `go.mod` file above supported range",
232+
"go/autobuilder/env-go-mod-version-too-high-no-go-env",
233+
"Go version in `go.mod` file above supported range and no Go version in environment",
234+
msg,
235+
severityNote,
236+
telemetryOnly,
237+
noLocation,
238+
)
239+
}
240+
241+
func EmitGoModVersionTooHighAndEnvVersionTooHigh(msg string) {
242+
emitDiagnostic(
243+
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high",
244+
"Go version in `go.mod` file above supported range and Go version in environment above supported range",
245+
msg,
246+
severityNote,
247+
telemetryOnly,
248+
noLocation,
249+
)
250+
}
251+
252+
func EmitGoModVersionTooHighAndEnvVersionTooLow(msg string) {
253+
emitDiagnostic(
254+
"go/autobuilder/env-go-mod-version-too-high-go-env-too-low",
255+
"Go version in `go.mod` file above supported range and Go version in environment below supported range",
256+
msg,
257+
severityNote,
258+
telemetryOnly,
259+
noLocation,
260+
)
261+
}
262+
263+
func EmitGoModVersionTooHighAndEnvVersionBelowMax(msg string) {
264+
emitDiagnostic(
265+
"go/autobuilder/env-go-mod-version-too-high-go-env-below-max",
266+
"Go version in `go.mod` file above supported range and Go version in environment is supported and below the maximum supported version",
267+
msg,
268+
severityNote,
269+
telemetryOnly,
270+
noLocation,
271+
)
272+
}
273+
274+
func EmitGoModVersionTooHighAndEnvVersionMax(msg string) {
275+
emitDiagnostic(
276+
"go/autobuilder/env-go-mod-version-too-high-go-env-max",
277+
"Go version in `go.mod` file above supported range and Go version in environment is the maximum supported version",
234278
msg,
235279
severityNote,
236280
telemetryOnly,

0 commit comments

Comments
 (0)