-
Notifications
You must be signed in to change notification settings - Fork 366
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
Conversation
"0.12.0", | ||
"0.12.2", | ||
"0.12.3", | ||
"1.0.1", | ||
"1.0.0rc1", |
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.
Unfortunately, our current version format will actually put 1.0.0rc1
after 1.0.1
, 1.0.0-rc1
would have worked correctly though.
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.
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.
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" |
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.
@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?
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.
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?
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.
In any case, it should match the algorithm that's in the BCR..
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.
see
bazel-central-registry/tools/registry.py
Lines 82 to 128 in 127d917
# 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 |
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.
and https://bazel.build/external/module#version_format for an overview of the format
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.
"0.12.0", | ||
"0.12.2", | ||
"0.12.3", | ||
"1.0.1", | ||
"1.0.0rc1", |
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.
Addressing #1425 (comment)