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

publish-announcement: sort versions to be decreasing order #135

Merged
merged 10 commits into from
Jul 19, 2024

Conversation

gdams
Copy link
Member

@gdams gdams commented Jul 3, 2024

No description provided.

@gdams gdams requested a review from a team as a code owner July 3, 2024 17:07
@gdams gdams requested a review from dagood July 3, 2024 20:14

// IsNewerThan compares two versions and returns true if the receiver is newer than the argument
// version. The comparison is done by comparing the major, minor, patch, revision, prerelease and note parts in that
// order. If all parts are equal, false is returned. It may return an error if a part is not an integer.
Copy link
Member

Choose a reason for hiding this comment

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

I tried rewriting this to explain the intent behind "may return an error if a part is not an integer", but I'm ending up not really happy about exposing this method with it implemented this way. I see a few ways forward:

  • Preprocessing the versions to actually make sure they're all integers. I think this makes more sense to the user, is more usable, and ends up with a cleaner implementation: https://gist.github.com/dagood/9d36726d640d3138165916636d564ecf
  • We could move this back to publish-announcement and unexport it to remove the burden of making it a public API.
  • This method could be improved to handle strings as well as numbers to remove error and simplify usage and the explanation. Basically: a more generic natural sort, rather than a natural sort if the data happens to meet some constraints.

Copy link
Contributor

Choose a reason for hiding this comment

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

looks good!

Copy link
Member

@dagood dagood Jul 16, 2024

Choose a reason for hiding this comment

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

@mertakman and I chatted about this and I liked the suggestion to use https://pkg.go.dev/sort#Interface and to simply put non-int-parseable elements at the end of the slice. This is easier to document as part of our exported API and is analogous to how Go sorts (or rather, doesn't sort?) various NaNs.

This is similar to the third alternative above, but we don't really need to make an effort to support "bad" versions in much detail. Also, using sort.Interface to make it more intuitive to use rather than the current func and sort.Slice. Perf isn't a significant factor here given our use cases (not that it's necessarily a problem here).

(In the future we might want to consider restricting what goversion allows, to catch "bad" versions early and eliminate this edge case. From the dev/user's point of view, this would mean catching it in the microsoft-go-infra-release-start pipeline before the version number is used to do anything.)

@dagood
Copy link
Member

dagood commented Jul 17, 2024

@mertakman I see a force push, but no changes to the sorting code in this PR--just a rebase or something so far?

@gdams gdams requested a review from dagood July 18, 2024 16:06
goversion/goversion.go Outdated Show resolved Hide resolved
goversion/goversion.go Outdated Show resolved Hide resolved
goversion/goversion_test.go Outdated Show resolved Hide resolved
@mertakman mertakman requested a review from dagood July 18, 2024 18:22
Copy link
Member

@dagood dagood left a comment

Choose a reason for hiding this comment

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

I pushed a few changes, now it LGTM. @mertakman or @gdams, take a look and make sure you agree and feel free to merge. 🙂

@mertakman mertakman merged commit aa0eca2 into microsoft:main Jul 19, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants