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

ensure deterministic results for SortBySemVer() #559

Merged
merged 1 commit into from
Jun 8, 2023
Merged

ensure deterministic results for SortBySemVer() #559

merged 1 commit into from
Jun 8, 2023

Conversation

krancour
Copy link
Contributor

Fixes #375

The heart of the issue is that https://github.com/masterminds/semver does not yield deterministic results when sorting versions. That package (rightfully) considers 1.24 and 1.24.0, for example, to be equal. This is fine in nearly all circumstances, but when sorting a list of versions containing both of these, these two can appear in either order, making the results of the sort non-deterministic. If one's goal were to select the latest 1.24.x, you'd sometimes end up with list[len(list) - 1] being 1.24 and other times being 1.24.0.

This PR furnishes a drop-in replacement for the semver.Collection type that breaks comparison ties with a lexical comparison of the origin strings from which both Version objects were created.

fwiw, I do plan to offer this improvement upstream to https://github.com/masterminds/semver, but am also offering it here because the semver package has moved on to a v3 which is API-compatible, but has breaking changes in its functionality. I am reluctant to suggest that the solution is the get this merged upstream and then upgrade to v3, as that upgrade would surely affect things in other, unanticipated ways.

Signed-off-by: Kent <kent.rancourt@gmail.com>
@krancour
Copy link
Contributor Author

CI failure does not appear to be related to the change.

Copy link

@rbreeze rbreeze left a comment

Choose a reason for hiding this comment

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

LGTM

@krancour
Copy link
Contributor Author

krancour commented Jun 1, 2023

Gentle bump

@jannfis
Copy link
Contributor

jannfis commented Jun 8, 2023

Thank you for the PR and your patience @krancour, much appreciated.

Apologies for the delay in review. I think this is a very useful contribution.

Copy link
Contributor

@jannfis jannfis left a comment

Choose a reason for hiding this comment

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

LGTM

@jannfis jannfis merged commit d1b92e9 into argoproj-labs:master Jun 8, 2023
dlactin pushed a commit to dlactin/argocd-image-updater that referenced this pull request May 9, 2024
sribiere-jellysmack pushed a commit to sribiere-jellysmack/argocd-image-updater that referenced this pull request Aug 13, 2024
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.

Same image is updated multiple times, 1.20 --> 1.20.0 --> 1.20 --> 1.20.0
3 participants