@@ -96,7 +96,15 @@ func getEnvGoSemVer() string {
96
96
if ! strings .HasPrefix (goVersion , "go" ) {
97
97
log .Fatalf ("Expected 'go version' output of the form 'go1.2.3'; got '%s'" , goVersion )
98
98
}
99
- return "v" + goVersion [2 :]
99
+ // Go versions don't follow the SemVer format, but the only exception we normally care about
100
+ // is release candidates; so this is a horrible hack to convert e.g. `go1.22rc1` into `go1.22-rc1`
101
+ // which is compatible with the SemVer specification
102
+ rcIndex := strings .Index (goVersion , "rc" )
103
+ if rcIndex != - 1 {
104
+ return semver .Canonical ("v" + goVersion [2 :rcIndex ]) + "-" + goVersion [rcIndex :]
105
+ } else {
106
+ return "v" + goVersion [2 :]
107
+ }
100
108
}
101
109
102
110
// Returns the import path of the package being built, or "" if it cannot be determined.
@@ -787,10 +795,11 @@ func installDependenciesAndBuild() {
787
795
}
788
796
789
797
goVersionInfo := tryReadGoDirective (buildInfo )
798
+ canonEnvSemVer := semver .Canonical (getEnvGoSemVer ())
790
799
791
800
// This diagnostic is not required if the system Go version is 1.21 or greater, since the
792
801
// Go tooling should install required Go versions as needed.
793
- if semver .Compare (getEnvGoSemVer () , "v1.21.0" ) < 0 && goVersionInfo .Found && semver .Compare ("v" + goVersionInfo .Version , getEnvGoSemVer () ) > 0 {
802
+ if semver .Compare (canonEnvSemVer , "v1.21.0" ) < 0 && goVersionInfo .Found && semver .Compare ("v" + goVersionInfo .Version , canonEnvSemVer ) > 0 {
794
803
diagnostics .EmitNewerGoVersionNeeded ()
795
804
}
796
805
0 commit comments