-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Go: Better handle pre-release versions #15327
Conversation
// which is compatible with the SemVer specification | ||
rcIndex := strings.Index(goVersion, "rc") | ||
if rcIndex != -1 { | ||
return semver.Canonical("v"+goVersion[2:rcIndex]) + "-" + goVersion[rcIndex:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it confusing that we call semver.Canonical
here and also on line 798 (but not at other call-sites). Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think L798 is leftover from the first attempt at getting this to work and is no longer necessary, so can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Would there be any benefit in also using semver.Canonical
on the other branch, so that we know we're always returning a canonical version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done for spotting this and fixing it so quickly.
The
go version
command returns a version identifier which is not a valid semantic version. This is noticeable for pre-release builds of Go, such asgo1.22rc1
. Our existing handling of such versions meant that they were treated as invalid bysemver.Compare
and were therefore considered lower than all other versions. This PR implements a workaround for version identifiers that containrc
in them so that they are converted into a valid semantic version and therefore compared correctly.