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
70 changes: 36 additions & 34 deletions go/extractor/autobuilder/build-environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,55 +83,58 @@ func getVersionWhenGoModVersionNotFound(v versionInfo) (msg string, version util
func getVersionWhenGoModVersionTooHigh(v versionInfo) (msg string, version util.SemVer) {
if v.goEnvVersion == nil {
// The version in the `go.mod` file is above the supported range. There is no Go version
// installed. We install the maximum supported version as a best effort.
// installed. We install the version from the `go.mod` file 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 version of Go from the `go.mod` file (" +
v.goModVersion.String() + ")."
version = v.goModVersion
diagnostics.EmitGoModVersionTooHighAndNoGoEnv(msg)
} else if aboveSupportedRange(v.goEnvVersion) {
} else if !outsideSupportedRange(v.goEnvVersion) {
// The version in the `go.mod` file is above the supported range. The version of Go that
// is installed is above the supported range. We do not install a version of Go.
// is installed is in the supported range. We install the version from the `go.mod`
// file 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() +
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). Not requesting any version of Go."
version = nil
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHigh(msg)
") is inside the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). Requesting the version of Go from the `go.mod` file (" + v.goModVersion.String() + ")."
version = v.goModVersion
diagnostics.EmitGoModVersionTooHighAndEnvVersionSupported(msg)
} else if belowSupportedRange(v.goEnvVersion) {
// The version in the `go.mod` file is above the supported range. The version of Go that
// is installed is below the supported range. We install the maximum supported version as
// a best effort.
// is installed is below the supported range. We install the version from the `go.mod`
// file 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() +
"). 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 version of Go from the `go.mod` file (" + v.goModVersion.String() + ")."
version = v.goModVersion
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooLow(msg)
} else if maxGoVersion.IsNewerThan(v.goEnvVersion) {
} else if v.goModVersion.IsNewerThan(v.goEnvVersion) {
// The version in the `go.mod` file is above the supported range. The version of Go that
// is installed is supported and below the maximum supported version. We install the
// maximum supported version as a best effort.
// is installed is also above the supported range, but older. We install the version
// from the `go.mod` file 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() +
"). 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
diagnostics.EmitGoModVersionTooHighAndEnvVersionBelowMax(msg)
") is also above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
") but older. Requesting the version of Go from the `go.mod` file (" + v.goModVersion.String() +
")."
version = v.goModVersion
diagnostics.EmitGoModVersionTooHighAndEnvVersionTooHighButOlder(msg)
} else {
// The version in the `go.mod` file is above the supported range. The version of Go that
// is installed is the maximum supported version. We do not install a version of Go.
// is installed is also above the supported range, but newer or equal. We do not install
// a version of Go.
msg = "The version of Go found in the `go.mod` file (" + v.goModVersion.String() +
") is above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). The version of Go installed in the environment (" + v.goEnvVersion.String() +
") is the maximum supported version (" + maxGoVersion.String() +
") is also above the supported range (" + minGoVersion.String() + "-" + maxGoVersion.String() +
"). Not requesting any version of Go."
version = nil
diagnostics.EmitGoModVersionTooHighAndEnvVersionMax(msg)
diagnostics.EmitGoModVersionTooHighAndEnvTooHigh(msg)
}

return msg, version
Expand Down Expand Up @@ -218,17 +221,16 @@ func getVersionWhenGoModVersionSupported(v versionInfo) (msg string, version uti

// Check the versions of Go found in the environment and in the `go.mod` file, and return a
// version to install. If the version is the empty string then no installation is required.
// We never return a version of Go that is outside of the supported range.
//
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
// | Found in go.mod > | *None* | *Below min supported* | *In supported range* | *Above max supported |
// | Installed \/ | | | | |
// |-----------------------|-----------------------|-----------------------|-----------------------------------------------------|------------------------------------------------|
// | *None* | Install max supported | Install min supported | Install version from go.mod | Install max supported |
// | *Below min supported* | Install max supported | Install min supported | Install version from go.mod | Install max supported |
// | *In supported range* | No action | No action | Install version from go.mod if newer than installed | Install max supported if newer than installed |
// | *Above max supported* | Install max supported | Install min supported | Install version from go.mod | No action |
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+------------------------------------------------+
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+-----------------------------------------------------+
// | Found in go.mod > | *None* | *Below min supported* | *In supported range* | *Above max supported |
// | Installed \/ | | | | |
// |-----------------------|-----------------------|-----------------------|-----------------------------------------------------|-----------------------------------------------------|
// | *None* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
// | *Below min supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod |
// | *In supported range* | No action | No action | Install version from go.mod if newer than installed | Install version from go.mod |
// | *Above max supported* | Install max supported | Install min supported | Install version from go.mod | Install version from go.mod if newer than installed |
// +-----------------------+-----------------------+-----------------------+-----------------------------------------------------+-----------------------------------------------------+
func getVersionToInstall(v versionInfo) (msg string, version util.SemVer) {
if v.goModVersion == nil {
return getVersionWhenGoModVersionNotFound(v)
Expand Down
12 changes: 8 additions & 4 deletions go/extractor/autobuilder/build-environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ func TestGetVersionToInstall(t *testing.T) {
{"", "1.20.3"}: "",

// getVersionWhenGoModVersionTooHigh()
{"9999.0", ""}: maxGoVersion.String(),
{"9999.0", ""}: "9999.0",
{"9999.0", "9999.0.1"}: "",
{"9999.0", "1.1"}: maxGoVersion.String(),
{"9999.0", minGoVersion.String()}: maxGoVersion.String(),
{"9999.0", maxGoVersion.String()}: "",
{"9999.0", "1.1"}: "9999.0",
{"9999.0", minGoVersion.String()}: "9999.0",
{"9999.0", maxGoVersion.String()}: "9999.0",
{"9999.1", "9999.0"}: "9999.1",
{"9999.0", "9999.1"}: "",
{"9999.0", "9999.0"}: "",
{"9999.0rc2", ""}: "v9999.0.0-rc2",

// getVersionWhenGoModVersionTooLow()
{"0.0", ""}: minGoVersion.String(),
Expand Down
18 changes: 9 additions & 9 deletions go/extractor/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ func EmitGoModVersionTooHighAndNoGoEnv(msg string) {
)
}

func EmitGoModVersionTooHighAndEnvVersionTooHigh(msg string) {
func EmitGoModVersionTooHighAndEnvVersionSupported(msg string) {
emitDiagnostic(
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high",
"Go version in `go.mod` file above supported range and Go version in environment above supported range",
"go/autobuilder/env-go-mod-version-too-high-go-env-supported",
"Go version in `go.mod` file above supported range and Go version in environment is supported",
msg,
severityNote,
telemetryOnly,
Expand All @@ -444,21 +444,21 @@ func EmitGoModVersionTooHighAndEnvVersionTooLow(msg string) {
)
}

func EmitGoModVersionTooHighAndEnvVersionBelowMax(msg string) {
func EmitGoModVersionTooHighAndEnvVersionTooHighButOlder(msg string) {
emitDiagnostic(
"go/autobuilder/env-go-mod-version-too-high-go-env-below-max",
"Go version in `go.mod` file above supported range and Go version in environment is supported and below the maximum supported version",
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high-but-older",
"Go version in `go.mod` file above supported range and Go version in environment is above supported range but older",
msg,
severityNote,
telemetryOnly,
noLocation,
)
}

func EmitGoModVersionTooHighAndEnvVersionMax(msg string) {
func EmitGoModVersionTooHighAndEnvTooHigh(msg string) {
emitDiagnostic(
"go/autobuilder/env-go-mod-version-too-high-go-env-max",
"Go version in `go.mod` file above supported range and Go version in environment is the maximum supported version",
"go/autobuilder/env-go-mod-version-too-high-go-env-too-high",
"Go version in `go.mod` file above supported range and Go version in environment is above supported range",
msg,
severityNote,
telemetryOnly,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"configuration" : {
"go" : { }
"go" : {
"version" : "1.999.0"
}
}
}
Loading