aboutsummaryrefslogtreecommitdiff
path: root/internal/stdlib/stdlib.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2023-07-12 14:25:19 -0400
committerRobert Findley <rfindley@google.com>2023-07-12 19:51:17 +0000
commit8cc68fd9b58be65b191809d99fd444c44233fffa (patch)
tree57a039f0bc1e99fffd754f56077c9f724307b937 /internal/stdlib/stdlib.go
parentf36927e488132f6f557327e5dd83ea462dfed99d (diff)
downloadgo-x-pkgsite-8cc68fd9b58be65b191809d99fd444c44233fffa.tar.xz
internal/stdlib: update to account for .0 major version suffixes
Starting with go1.21.0, the first version of new major Go versions will include the .0 suffix (compare go1.20). Update pkgsite logic to account for this switch, and add unit+integration test support. Fixes golang/go#60373 Change-Id: Ibdac8a3413a48f925427a5aae366bed2f691cfa6 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/508937 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org> TryBot-Result: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'internal/stdlib/stdlib.go')
-rw-r--r--internal/stdlib/stdlib.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/stdlib/stdlib.go b/internal/stdlib/stdlib.go
index b7fa93bc..b11a0a89 100644
--- a/internal/stdlib/stdlib.go
+++ b/internal/stdlib/stdlib.go
@@ -101,6 +101,9 @@ func VersionForTag(tag string) string {
// TagForVersion returns the Go standard library repository tag corresponding
// to semver. The Go tags differ from standard semantic versions in a few ways,
// such as beginning with "go" instead of "v".
+//
+// Starting with go1.21.0, the first patch release of major go versions include
+// the .0 suffix. Previously, the .0 suffix was elided (golang/go#57631).
func TagForVersion(v string) (_ string, err error) {
defer derrors.Wrap(&err, "TagForVersion(%q)", v)
@@ -122,7 +125,9 @@ func TagForVersion(v string) (_ string, err error) {
prerelease := semver.Prerelease(goVersion)
versionWithoutPrerelease := strings.TrimSuffix(goVersion, prerelease)
patch := strings.TrimPrefix(versionWithoutPrerelease, semver.MajorMinor(goVersion)+".")
- if patch == "0" {
+ if patch == "0" && (semver.Compare(v, "v1.21.0") < 0 || prerelease != "") {
+ // Starting with go1.21.0, the first patch version includes .0.
+ // Prereleases do not include .0 (we don't do prereleases for other patch releases).
versionWithoutPrerelease = strings.TrimSuffix(versionWithoutPrerelease, ".0")
}
goVersion = fmt.Sprintf("go%s", strings.TrimPrefix(versionWithoutPrerelease, "v"))
@@ -251,10 +256,11 @@ func refNameForVersion(v string) (plumbing.ReferenceName, error) {
return plumbing.NewTagReferenceName(tag), nil
}
-// Versions returns all the versions of Go that are relevant to the discovery
-// site. These are all release versions (tags of the forms "goN.N" and
-// "goN.N.N", where N is a number) and beta or rc versions (tags of the forms
-// "goN.NbetaN" and "goN.N.NbetaN", and similarly for "rc" replacing "beta").
+// Versions returns all the semantic versions of Go that are relevant to the
+// discovery site. These are all release versions (derived from tags of the
+// forms "goN.N" and "goN.N.N", where N is a number) and beta or rc versions
+// (derived from tags of the forms "goN.NbetaN" and "goN.N.NbetaN", and
+// similarly for "rc" replacing "beta").
func Versions() (_ []string, err error) {
defer derrors.Wrap(&err, "stdlib.Versions()")