Skip to content

Commit 84e6ebf

Browse files
committed
Go: When go.mod version is above maxGoVersion request go.mod version
1 parent b756a08 commit 84e6ebf

3 files changed

Lines changed: 53 additions & 47 deletions

File tree

go/extractor/autobuilder/build-environment.go

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,55 +83,58 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg string, version util
8383
func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg string, version util.SemVer) {
8484
if v.goEnvVersion == nil {
8585
// The version in the `go.mod` file is above the supported range. There is no Go version
86-
// installed. We install the maximum supported version as a best effort.
86+
// installed. We install the the version from the `go.mod` file as a best effort.
8787
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
8888
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
89-
"). No version of Go installed. Requesting the maximum supported version of Go (" +
90-
maxGoVersion.String() + ")."
91-
version = maxGoVersion
89+
"). No version of Go installed. Requesting the version of Go from the `go.mod` file (" +
90+
v.goModVersion.String() + ")."
91+
version = v.goModVersion
9292
diagnostics.EmitGoModVersionTooHighAndNoGoEnv(msg)
93-
} else if aboveSupportedRange(v.goEnvVersion) {
93+
} else if !outsideSupportedRange(v.goEnvVersion) {
9494
// The version in the `go.mod` file is above the supported range. The version of Go that
95-
// is installed is above the supported range. We do not install a version of Go.
95+
// is installed is in the supported range. We install the the version from the `go.mod`
96+
// file as a best effort.
9697
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
9798
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
9899
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
99-
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
100-
"). Not requesting any version of Go."
101-
version = nil
102-
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHigh(msg)
100+
") is inside the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
101+
"). Requesting the version of Go from the `go.mod` file (" + v.goModVersion.String() + ")."
102+
version = v.goModVersion
103+
diagnostics.EmitGoModVersionTooHighAndEnvVersionSupported(msg)
103104
} else if belowSupportedRange(v.goEnvVersion) {
104105
// The version in the `go.mod` file is above the supported range. The version of Go that
105-
// is installed is below the supported range. We install the maximum supported version as
106-
// a best effort.
106+
// is installed is below the supported range. We install the the version from the `go.mod`
107+
// file as a best effort.
107108
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
108109
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
109110
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
110111
") is below the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
111-
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
112-
version = maxGoVersion
112+
"). Requesting the version of Go from the `go.mod` file (" + v.goModVersion.String() + ")."
113+
version = v.goModVersion
113114
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooLow(msg)
114-
} else if maxGoVersion.IsNewerThan(v.goEnvVersion) {
115+
} else if v.goModVersion.IsNewerThan(v.goEnvVersion) {
115116
// The version in the `go.mod` file is above the supported range. The version of Go that
116-
// is installed is supported and below the maximum supported version. We install the
117-
// maximum supported version as a best effort.
117+
// is installed is also above the supported range, but older. We install the the version
118+
// from the `go.mod` file as a best effort.
118119
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
119120
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
120121
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
121-
") is below the maximum supported version (" + maxGoVersion.String() +
122-
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
123-
version = maxGoVersion
124-
diagnostics.EmitGoModVersionTooHighAndEnvVersionBelowMax(msg)
122+
") is also above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
123+
") but older. Requesting the version of Go from the `go.mod` file (" + v.goModVersion.String() +
124+
")."
125+
version = v.goModVersion
126+
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHighButOlder(msg)
125127
} else {
126128
// The version in the `go.mod` file is above the supported range. The version of Go that
127-
// is installed is the maximum supported version. We do not install a version of Go.
129+
// is installed is also above the supported range, but newer or equal. We do not install
130+
// a version of Go.
128131
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
129132
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
130133
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
131-
") is the maximum supported version (" + maxGoVersion.String() +
134+
") is also above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
132135
"). Not requesting any version of Go."
133136
version = nil
134-
diagnostics.EmitGoModVersionTooHighAndEnvVersionMax(msg)
137+
diagnostics.EmitGoModVersionTooHighAndEnvTooHigh(msg)
135138
}
136139

137140
return msg, version
@@ -218,17 +221,16 @@ func getVersionWhenGoModVersionSupported(v versionInfo) (msg string, version uti
218221

219222
// Check the versions of Go found in the environment and in the `go.mod` file, and return a
220223
// version to install. If the version is the empty string then no installation is required.
221-
// We never return a version of Go that is outside of the supported range.
222224
//
223-
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
224-
// | Found in go.mod > | *None* | *Below min supported* | *In supported range* | *Above max supported |
225-
// | Installed \/ | | | | |
226-
// |-----------------------|-----------------------|-----------------------|-----------------------------------------------------|------------------------------------------------|
227-
// | *None* | Install max supported | Install min supported | Install version from go.mod | Install max supported |
228-
// | *Below min supported* | Install max supported | Install min supported | Install version from go.mod | Install max supported |
229-
// | *In supported range* | No action | No action | Install version from go.mod if newer than installed | Install max supported if newer than installed |
230-
// | *Above max supported* | Install max supported | Install min supported | Install version from go.mod | No action |
231-
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
225+
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+-----------------------------------------------------+
226+
// | Found in go.mod > | *None* | *Below min supported* | *In supported range* | *Above max supported |
227+
// | Installed \/ | | | | |
228+
// |-----------------------|-----------------------|-----------------------|-----------------------------------------------------|-----------------------------------------------------|
229+
// | *None* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
230+
// | *Below min supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
231+
// | *In supported range* | No action | No action | Install version from go.mod if newer than installed | Install version from go.mod |
232+
// | *Above max supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod if newer than installed |
233+
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+-----------------------------------------------------+
232234
func getVersionToInstall(v versionInfo) (msg string, version util.SemVer) {
233235
if v.goModVersion == nil {
234236
return getVersionWhenGoModVersionNotFound(v)

go/extractor/autobuilder/build-environment_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ func TestGetVersionToInstall(t *testing.T) {
2020
{"", "1.20.3"}: "",
2121

2222
// getVersionWhenGoModVersionTooHigh()
23-
{"9999.0", ""}: maxGoVersion.String(),
23+
{"9999.0", ""}: "9999.0",
2424
{"9999.0", "9999.0.1"}: "",
25-
{"9999.0", "1.1"}: maxGoVersion.String(),
26-
{"9999.0", minGoVersion.String()}: maxGoVersion.String(),
27-
{"9999.0", maxGoVersion.String()}: "",
25+
{"9999.0", "1.1"}: "9999.0",
26+
{"9999.0", minGoVersion.String()}: "9999.0",
27+
{"9999.0", maxGoVersion.String()}: "9999.0",
28+
{"9999.1", "9999.0"}: "9999.1",
29+
{"9999.0", "9999.1"}: "",
30+
{"9999.0", "9999.0"}: "",
31+
{"9999.0rc2", ""}: "v9999.0.0-rc2",
2832

2933
// getVersionWhenGoModVersionTooLow()
3034
{"0.0", ""}: minGoVersion.String(),

go/extractor/diagnostics/diagnostics.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ func EmitGoModVersionTooHighAndNoGoEnv(msg string) {
422422
)
423423
}
424424

425-
func EmitGoModVersionTooHighAndEnvVersionTooHigh(msg string) {
425+
func EmitGoModVersionTooHighAndEnvVersionSupported(msg string) {
426426
emitDiagnostic(
427-
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high",
428-
"Go version in `go.mod` file above supported range and Go version in environment above supported range",
427+
"go/autobuilder/env-go-mod-version-too-high-go-env-supported",
428+
"Go version in `go.mod` file above supported range and Go version in environment is supported",
429429
msg,
430430
severityNote,
431431
telemetryOnly,
@@ -444,21 +444,21 @@ func EmitGoModVersionTooHighAndEnvVersionTooLow(msg string) {
444444
)
445445
}
446446

447-
func EmitGoModVersionTooHighAndEnvVersionBelowMax(msg string) {
447+
func EmitGoModVersionTooHighAndEnvVersionTooHighButOlder(msg string) {
448448
emitDiagnostic(
449-
"go/autobuilder/env-go-mod-version-too-high-go-env-below-max",
450-
"Go version in `go.mod` file above supported range and Go version in environment is supported and below the maximum supported version",
449+
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high-but-older",
450+
"Go version in `go.mod` file above supported range and Go version in environment is above supported range but older",
451451
msg,
452452
severityNote,
453453
telemetryOnly,
454454
noLocation,
455455
)
456456
}
457457

458-
func EmitGoModVersionTooHighAndEnvVersionMax(msg string) {
458+
func EmitGoModVersionTooHighAndEnvTooHigh(msg string) {
459459
emitDiagnostic(
460-
"go/autobuilder/env-go-mod-version-too-high-go-env-max",
461-
"Go version in `go.mod` file above supported range and Go version in environment is the maximum supported version",
460+
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high",
461+
"Go version in `go.mod` file above supported range and Go version in environment is above supported range",
462462
msg,
463463
severityNote,
464464
telemetryOnly,

0 commit comments

Comments
 (0)