Skip to content
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

Merged
merged 3 commits into from
Jan 15, 2024
Merged

Conversation

mbg
Copy link
Member

@mbg mbg commented Jan 15, 2024

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 as go1.22rc1. Our existing handling of such versions meant that they were treated as invalid by semver.Compare and were therefore considered lower than all other versions. This PR implements a workaround for version identifiers that contain rc in them so that they are converted into a valid semantic version and therefore compared correctly.

@mbg mbg self-assigned this Jan 15, 2024
@mbg mbg requested a review from a team as a code owner January 15, 2024 14:04
@github-actions github-actions bot added the Go label Jan 15, 2024
// which is compatible with the SemVer specification
rcIndex := strings.Index(goVersion, "rc")
if rcIndex != -1 {
return semver.Canonical("v"+goVersion[2:rcIndex]) + "-" + goVersion[rcIndex:]
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@mbg mbg requested a review from owen-mc January 15, 2024 15:08
Copy link
Contributor

@owen-mc owen-mc left a 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.

@mbg mbg merged commit 6c9f79c into main Jan 15, 2024
12 checks passed
@mbg mbg deleted the mbg/go/handle-pre-release-versions branch January 15, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants