diff options
| author | Rob Findley <rfindley@google.com> | 2023-07-12 14:25:19 -0400 |
|---|---|---|
| committer | Robert Findley <rfindley@google.com> | 2023-07-12 19:51:17 +0000 |
| commit | 8cc68fd9b58be65b191809d99fd444c44233fffa (patch) | |
| tree | 57a039f0bc1e99fffd754f56077c9f724307b937 /internal/stdlib | |
| parent | f36927e488132f6f557327e5dd83ea462dfed99d (diff) | |
| download | go-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')
| -rw-r--r-- | internal/stdlib/gorepo.go | 1 | ||||
| -rw-r--r-- | internal/stdlib/stdlib.go | 16 | ||||
| -rw-r--r-- | internal/stdlib/stdlib_test.go | 29 |
3 files changed, 38 insertions, 8 deletions
diff --git a/internal/stdlib/gorepo.go b/internal/stdlib/gorepo.go index 6bb2077f..09ee8ca3 100644 --- a/internal/stdlib/gorepo.go +++ b/internal/stdlib/gorepo.go @@ -161,6 +161,7 @@ var testRefs = []plumbing.ReferenceName{ "refs/tags/go1.13", "refs/tags/go1.13beta1", "refs/tags/go1.14.6", + "refs/tags/go1.21.0", "refs/heads/dev.fuzz", "refs/heads/master", // other tags 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()") diff --git a/internal/stdlib/stdlib_test.go b/internal/stdlib/stdlib_test.go index 8841b0a8..7425150e 100644 --- a/internal/stdlib/stdlib_test.go +++ b/internal/stdlib/stdlib_test.go @@ -64,6 +64,26 @@ func TestTagForVersion(t *testing.T) { want: "go1.13", }, { + name: "version v1.20.0-rc.2", + version: "v1.20.0-rc.2", + want: "go1.20rc2", + }, + { + name: "version v1.20.0", + version: "v1.20.0", + want: "go1.20", + }, + { + name: "version v1.21.0-rc.2", + version: "v1.21.0-rc.2", + want: "go1.21rc2", + }, + { + name: "version v1.21.0", + version: "v1.21.0", + want: "go1.21.0", + }, + { name: "master branch", version: "master", want: "master", @@ -96,7 +116,7 @@ func TestTagForVersion(t *testing.T) { return } if got != test.want { - t.Errorf("TagForVersion(%q) = %q, %v, wanted %q, %v", test.version, got, err, test.want, nil) + t.Fatalf("TagForVersion(%q) = %q, %v, wanted %q, %v", test.version, got, err, test.want, nil) } }) } @@ -236,7 +256,7 @@ func TestZipInfo(t *testing.T) { }{ { requestedVersion: "latest", - want: "v1.14.6", + want: "v1.21.0", }, { requestedVersion: "master", @@ -279,7 +299,8 @@ func TestVersions(t *testing.T) { otherWants := append([]string{"v1.17.6"}, commonWants...) t.Run("test", func(t *testing.T) { defer WithTestData()() - testVersions(commonWants) + testWants := append([]string{"v1.21.0"}, commonWants...) + testVersions(testWants) }) t.Run("local", func(t *testing.T) { if *repoPath == "" { @@ -316,6 +337,8 @@ func TestVersionForTag(t *testing.T) { {"go1.0", ""}, {"weekly.2012-02-14", ""}, {"latest", "latest"}, + {"go1.21.0", "v1.21.0"}, + {"go1.21", "v1.21.0"}, } { got := VersionForTag(test.in) if got != test.want { |
