New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/website/internal/dl: version sorting doesn't sort pre-release versions #47367
Comments
Thanks for the report. The |
Hm, are you sure? In func parseVersion(v string) (maj, min int, tail string) {
if i := strings.Index(v, "beta"); i > 0 {
tail = v[i:]
v = v[:i]
}
if i := strings.Index(v, "rc"); i > 0 {
tail = v[i:]
v = v[:i]
}
p := strings.Split(strings.TrimPrefix(v, "go1."), ".")
maj, _ = strconv.Atoi(p[0])
if len(p) < 2 {
return
}
min, _ = strconv.Atoi(p[1])
return
} Then in func versionLess(a, b string) bool {
// Put stable releases first.
if isStable(a) != isStable(b) {
return isStable(a)
}
maja, mina, ta := parseVersion(a)
majb, minb, tb := parseVersion(b)
if maja == majb {
if mina == minb {
return ta >= tb
}
return mina >= minb
}
return maja >= majb
} This is then tested to be the case in |
Ahh, actually what's happening is this, from if len(unstable) != 0 {
// Only show one (latest) unstable version,
// consider the older ones to be archived.
archive = append(archive, *r)
return
} Basically, since archives are currently first, and since there's only one unstable release, it's placed in the wrong spot for In other words, the problem of this issue is fixed by #50201 and https://golang.org/cl/371934. |
I'll add a test case to that CL and make sure it works for the case here. |
Change https://golang.org/cl/371934 mentions this issue: |
When include=all is used, archived versions (old) and unstable versions (new) are appended to the list of returned versions. This makes the order of the list rather awkward: current, old, new. This commit makes the ordering a bit more natural: new, current, old. However, even like that, releases will be out of order, because, for example, 1.18rc1 is new, while 1.17.6 is current, but 1.18beta1 is old. So, this commit takes care to sort the entire list properly to avoid that. This way, the entire list is sorted by version. Nothing changes semantically, as users of the API can still filter out unstable releases using the "stable: true" field. This commit also adds a test case, to make sure this behavior doesn't regress. Fixes golang/go#50201. Fixes golang/go#47367. Change-Id: Ic136197dcdd47aa149601b75ba5152a2006c790a Reviewed-on: https://go-review.googlesource.com/c/website/+/371934 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Jason Donenfeld <Jason@zx2c4.com> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Jamal Carvalho <jamalcarvalho@google.com>
What did you do?
Ran
curl "https://golang.org/dl/?mode=json&include=all"
in consoleWhat did you expect to see?
go1.17rc1 before go1.17beta1
What did you see instead?
go1.17rc1 after go1.17beta1
The text was updated successfully, but these errors were encountered: