Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions go/extractor/autobuilder/build-environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import (
)

var minGoVersion = util.NewSemVer("1.11")

// This can be increased before a new minor version has been released, based on testing with the release candidates.
var maxGoVersion = util.NewSemVer("1.26")

// This should be the maximum supported version which has been released.
var goVersionToInstall = util.NewSemVer("1.26")

type versionInfo struct {
goModVersion util.SemVer // The version of Go found in the go directive in the `go.mod` file.
goEnvVersion util.SemVer // The version of Go found in the environment.
Expand Down Expand Up @@ -52,18 +57,18 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg string, version util
// was intended to be used to build this project. Go versions are generally backwards
// compatible, so we install the maximum supported version.
msg = "No version of Go installed and no `go.mod` file found. Requesting the maximum " +
"supported version of Go (" + maxGoVersion.String() + ")."
version = maxGoVersion
"supported version of Go that has been released (" + goVersionToInstall.String() + ")."
version = goVersionToInstall
diagnostics.EmitNoGoModAndNoGoEnv(msg)
} else if outsideSupportedRange(v.goEnvVersion) {
// The Go version installed in the environment is not supported. We have no indication
// which version was intended to be used to build this project. Go versions are generally
// backwards compatible, so we install the maximum supported version.
msg = "No `go.mod` file found. The version of Go installed in the environment (" +
v.goEnvVersion.String() + ") is outside of the supported range (" + minGoVersion.String() + "-" +
maxGoVersion.String() + "). Requesting the maximum supported version of Go (" + maxGoVersion.String() +
")."
version = maxGoVersion
maxGoVersion.String() + "). Requesting the maximum supported version of Go that has " +
"been released (" + goVersionToInstall.String() + ")."
version = goVersionToInstall
diagnostics.EmitNoGoModAndGoEnvUnsupported(msg)
} else {
// The version of Go that is installed is supported. We have no indication which version
Expand All @@ -86,9 +91,9 @@ func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg string, version util.
// installed. We install the maximum supported version as a best effort.
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). No version of Go installed. Requesting the maximum supported version of Go (" +
maxGoVersion.String() + ")."
version = maxGoVersion
"). No version of Go installed. Requesting the maximum supported version of Go that has " +
"been released (" + goVersionToInstall.String() + ")."
version = goVersionToInstall
diagnostics.EmitGoModVersionTooHighAndNoGoEnv(msg)
} else if aboveSupportedRange(v.goEnvVersion) {
// The version in the `go.mod` file is above the supported range. The version of Go that
Expand All @@ -108,8 +113,8 @@ func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg string, version util.
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
") is below the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
version = maxGoVersion
"). Requesting the maximum supported version of Go that has been released (" + goVersionToInstall.String() + ")."
version = goVersionToInstall
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooLow(msg)
} else if maxGoVersion.IsNewerThan(v.goEnvVersion) {
// The version in the `go.mod` file is above the supported range. The version of Go that
Expand All @@ -119,8 +124,8 @@ func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg string, version util.
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
") is below the maximum supported version (" + maxGoVersion.String() +
"). Requesting the maximum supported version of Go (" + maxGoVersion.String() + ")."
version = maxGoVersion
"). Requesting the maximum supported version of Go that has been released (" + goVersionToInstall.String() + ")."
version = goVersionToInstall
diagnostics.EmitGoModVersionTooHighAndEnvVersionBelowMax(msg)
} else {
// The version in the `go.mod` file is above the supported range. The version of Go that
Expand Down
22 changes: 14 additions & 8 deletions go/extractor/autobuilder/build-environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ func TestGetVersionToInstall(t *testing.T) {
}
tests := map[inputVersions]string{
// getVersionWhenGoModVersionNotFound()
{"", ""}: maxGoVersion.String(),
{"", "1.2.2"}: maxGoVersion.String(),
{"", "9999.0.1"}: maxGoVersion.String(),
{"", ""}: goVersionToInstall.String(),
{"", "1.2.2"}: goVersionToInstall.String(),
{"", "9999.0.1"}: goVersionToInstall.String(),
{"", "1.11.13"}: "",
{"", "1.20.3"}: "",

// getVersionWhenGoModVersionTooHigh()
{"9999.0", ""}: maxGoVersion.String(),
{"9999.0", "9999.0.1"}: "",
{"9999.0", "1.1"}: maxGoVersion.String(),
{"9999.0", minGoVersion.String()}: maxGoVersion.String(),
{"9999.0", maxGoVersion.String()}: "",
{"9999.0", ""}: goVersionToInstall.String(),
{"9999.0", "9999.0.1"}: "",
{"9999.0", "1.1"}: goVersionToInstall.String(),
{"9999.0", minGoVersion.String()}: goVersionToInstall.String(),
{"9999.0", goVersionToInstall.String()}: "",

// getVersionWhenGoModVersionTooLow()
{"0.0", ""}: minGoVersion.String(),
Expand Down Expand Up @@ -54,3 +54,9 @@ func TestGetVersionToInstall(t *testing.T) {
}
}
}

func TestMaxGoVersions(t *testing.T) {
if goVersionToInstall.IsNewerThan(maxGoVersion) {
t.Errorf("goVersionToInstall (%s) should not be newer than maxGoVersion (%s).", goVersionToInstall, maxGoVersion)
}
}
Loading