Skip to content

Commit fa16417

Browse files
Copilotjketema
andauthored
Request project Go version above supported range
Co-authored-by: jketema <93738568+jketema@users.noreply.github.com>
1 parent e6f6f7a commit fa16417

3 files changed

Lines changed: 45 additions & 29 deletions

File tree

go/extractor/autobuilder/build-environment.go

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,54 +83,63 @@ 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 request the version required by the project.
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 required by the project (" +
90+
v.goModVersion.String() + ")."
91+
version = v.goModVersion
9292
diagnostics.EmitGoModVersionTooHighAndNoGoEnv(msg)
93-
} else if aboveSupportedRange(v.goEnvVersion) {
93+
} else if !v.goModVersion.IsNewerThan(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 high enough for the project. We do not install a version of Go.
9696
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
9797
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
9898
"). 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."
99+
") is high enough for the version required by the project. Not requesting any version of Go."
101100
version = nil
102101
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHigh(msg)
102+
} else if aboveSupportedRange(v.goEnvVersion) {
103+
// The installed version is above the supported range, but lower than the version required
104+
// by the project. We request the version required by the project.
105+
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
106+
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
107+
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
108+
") is lower than the version required by the project. Requesting the version required by the project (" +
109+
v.goModVersion.String() + ")."
110+
version = v.goModVersion
111+
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHigh(msg)
103112
} else if belowSupportedRange(v.goEnvVersion) {
104113
// 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.
114+
// is installed is below the supported range. We request the version required by the project.
107115
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
108116
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
109117
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
110118
") is below the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
111-
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
112-
version = maxGoVersion
119+
"). Requesting the version required by the project (" + v.goModVersion.String() + ")."
120+
version = v.goModVersion
113121
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooLow(msg)
114122
} else if maxGoVersion.IsNewerThan(v.goEnvVersion) {
115123
// 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.
124+
// is installed is supported and below the maximum supported version. We request the version
125+
// required by the project.
118126
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
119127
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
120128
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
121129
") is below the maximum supported version (" + maxGoVersion.String() +
122-
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
123-
version = maxGoVersion
130+
"). Requesting the version required by the project (" + v.goModVersion.String() + ")."
131+
version = v.goModVersion
124132
diagnostics.EmitGoModVersionTooHighAndEnvVersionBelowMax(msg)
125133
} else {
126134
// 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.
135+
// is installed is the maximum supported version. We request the version required by the
136+
// project.
128137
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
129138
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
130139
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
131140
") is the maximum supported version (" + maxGoVersion.String() +
132-
"). Not requesting any version of Go."
133-
version = nil
141+
"). Requesting the version required by the project (" + v.goModVersion.String() + ")."
142+
version = v.goModVersion
134143
diagnostics.EmitGoModVersionTooHighAndEnvVersionMax(msg)
135144
}
136145

@@ -218,16 +227,17 @@ func getVersionWhenGoModVersionSupported(v versionInfo) (msg string, version uti
218227

219228
// Check the versions of Go found in the environment and in the `go.mod` file, and return a
220229
// 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.
230+
// If the version required by the project is above the supported range, we return that version when
231+
// it is newer than the installed version.
222232
//
223233
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
224234
// | Found in go.mod > | *None* | *Below min supported* | *In supported range* | *Above max supported |
225235
// | Installed \/ | | | | |
226236
// |-----------------------|-----------------------|-----------------------|-----------------------------------------------------|------------------------------------------------|
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 |
237+
// | *None* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
238+
// | *Below min supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
239+
// | *In supported range* | No action | No action | Install version from go.mod if newer than installed | Install version from go.mod |
240+
// | *Above max supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod if newer than installed |
231241
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
232242
func getVersionToInstall(v versionInfo) (msg string, version util.SemVer) {
233243
if v.goModVersion == nil {

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+
{"1.28", ""}: "1.28",
24+
{"1.28", "1.1"}: "1.28",
25+
{"1.28", "1.20"}: "1.28",
26+
{"1.28", maxGoVersion.String()}: "1.28",
27+
{"1.29", "1.28"}: "1.29",
28+
{"1.28", "1.28"}: "",
29+
{"1.28", "1.29"}: "",
2430
{"9999.0", "9999.0.1"}: "",
25-
{"9999.0", "1.1"}: maxGoVersion.String(),
26-
{"9999.0", minGoVersion.String()}: maxGoVersion.String(),
27-
{"9999.0", maxGoVersion.String()}: "",
31+
{"9999.0", minGoVersion.String()}: "9999.0",
2832

2933
// getVersionWhenGoModVersionTooLow()
3034
{"0.0", ""}: minGoVersion.String(),
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"configuration" : {
3-
"go" : { }
3+
"go" : {
4+
"version" : "1.999.0"
5+
}
46
}
57
}

0 commit comments

Comments
 (0)