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

Validate versions in metadata.json files are sorted #1431

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

meteorcloudy
Copy link
Member

Addressing #1425 (comment)

"0.12.0",
"0.12.2",
"0.12.3",
"1.0.1",
"1.0.0rc1",
Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, our current version format will actually put 1.0.0rc1 after 1.0.1, 1.0.0-rc1 would have worked correctly though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it was that way, which is why I had to release 1.0.1.

"6.4.0.2",
"6.4.0"
"6.4.0",
"6.4.0.2"
Copy link
Contributor

Choose a reason for hiding this comment

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

@kormide This module version was published using the Publish to BCR app (https://github.com/bazelbuild/bazel-central-registry/pull/1393/files#diff-c23aea529689affd6d10f59c5441c91cc81a61d289144862e237d9d591e6c9d7). Is it possible that the app doesn't sort versions with more than 3 semver segments correctly?

Copy link
Contributor

Choose a reason for hiding this comment

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

The algorithm is that it sorts non-semvers lexicographically and puts them at the top of the list, then it sorts semvers by version and puts them at the bottom. I don't think 6.4.0.2 is a valid semver, is it?

Copy link
Contributor

Choose a reason for hiding this comment

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

In any case, it should match the algorithm that's in the BCR..

Copy link
Member

Choose a reason for hiding this comment

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

see

# Translated from:
# https://github.com/bazelbuild/bazel/blob/79a53def2ebbd9358450f739ea37bf70662e8614/src/main/java/com/google/devtools/build/lib/bazel/bzlmod/Version.java#L58
@functools.total_ordering
class Version:
@functools.total_ordering
class Identifier:
def __init__(self, s):
if not s:
raise RegistryException("identifier is empty")
self.val = int(s) if s.isnumeric() else s
def __eq__(self, other):
if type(self.val) != type(other.val):
return False
return self.val == other.val
def __lt__(self, other):
if type(self.val) != type(other.val):
return type(self.val) == int
return self.val < other.val
@staticmethod
def convert_to_identifiers(s):
if s == None:
return None
return [Version.Identifier(i) for i in s.split(".")]
def __init__(self, version_str):
PATTERN = re.compile(r"^([a-zA-Z0-9.]+)(?:-([a-zA-Z0-9.-]+))?(?:\+[a-zA-Z0-9.-]+)?$")
m = PATTERN.match(version_str)
if not m:
raise RegistryException(f"`{version_str}` is not a valid version")
self.release = Version.convert_to_identifiers(m.groups()[0])
self.prerelease = Version.convert_to_identifiers(m.groups()[1])
def __eq__(self, other):
return (self.release, self.prerelease) == (other.release, other.prerelease)
def __lt__(self, other):
if self.release != other.release:
return self.release < other.release
if self.prerelease == None:
return False
if other.prerelease == None:
return True
return self.prerelease < other.prerelease
for the sorting algorithm for bzlmod versions

Copy link
Member

Choose a reason for hiding this comment

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

and https://bazel.build/external/module#version_format for an overview of the format

Copy link
Contributor

Choose a reason for hiding this comment

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

"0.12.0",
"0.12.2",
"0.12.3",
"1.0.1",
"1.0.0rc1",
Copy link
Contributor

Choose a reason for hiding this comment

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

@meteorcloudy meteorcloudy disabled auto-merge February 5, 2024 10:28
@meteorcloudy meteorcloudy merged commit 87c1e07 into bazelbuild:main Feb 5, 2024
6 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.

5 participants