Skip to content

Commit 6c9f79c

Browse files
authored
Merge pull request github#15327 from github/mbg/go/handle-pre-release-versions
Go: Better handle pre-release versions
2 parents 63a914a + 8c13429 commit 6c9f79c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

go/extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ func getEnvGoSemVer() string {
9696
if !strings.HasPrefix(goVersion, "go") {
9797
log.Fatalf("Expected 'go version' output of the form 'go1.2.3'; got '%s'", goVersion)
9898
}
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 semver.Canonical("v" + goVersion[2:])
107+
}
100108
}
101109

102110
// Returns the import path of the package being built, or "" if it cannot be determined.

0 commit comments

Comments
 (0)