-
Notifications
You must be signed in to change notification settings - Fork 53
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
Fix: Expand regular expression for version #68
Conversation
@SamiSousa Could you add a unit test that ensures success for the version suffix condition? |
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.
I miss unittest to prove your implementation is right
operatorcourier/validate.py
Outdated
pattern1 = re.compile(r'v(\d+\.)(\d+\.)(\d)') | ||
pattern2 = re.compile(r'(\d+\.)(\d+\.)(\d)') | ||
return pattern1.match(field) or pattern2.match(field) | ||
pattern = re.compile(r'(v)?(\d+\.)(\d+\.)(\d)(-[a-z0-9\.])*') |
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.
Do you need all ()
? You are not returning any substring from field
r'v?\d+[.]\d+[.]\d(-([a-z0-9][.]?)+)*'
I miss unittests.
Actually this is not working as you expect. (-[a-z0-9\.])*
matches -a-.-2
instead -a.2
. How about uppercase letters and underscores, are they allowed?
Also If I remember correctly quay doesn't allow leading zeroes
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.
For the AppRegistry, quay allows any valid semver. Things like 0.0.1
and 1.21.5-beta1
are valid.
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.
I agree that we can remove extraneous groups. I'd actually prefer using a proven semver library rather than reinventing the regex.
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.
Scratch what I said, this version in the CSV has no relation to quay's AppRegistry, my mistake.
In any case, there should be a doc that outlines what format this version field can take. From experience I have seen versions that use a semver followed by a tag. I agree that -a-.-2
doesn't look right, so I'll update it to avoid something like that
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.
It'd be better to use an external semver validator such as py package semver to avoid having to test the version regex we've implemented, especially as it becomes increasingly more complex.
041419b
to
cd77149
Compare
operatorcourier/validate.py
Outdated
pattern2 = re.compile(r'(\d+\.)(\d+\.)(\d)') | ||
return pattern1.match(field) or pattern2.match(field) | ||
version = re.compile(r'v?\d+\.\d+\.\d+' | ||
r'(-[A-Za-z0-9]+([-\.]?[A-Za-z0-9]+)*)?' |
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.
@alecmerdler Is there a standard for what a valid CSV version field is?
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.
Just standard SemVer (major.minor.patch
).
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.
I've seen versions such as 0.0.1
and 1.22.0-beta1
, so I've set this regex to match those as well.
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.
But major.minor.patch
isn't the full standard for Semantic Versioning:
https://semver.org/#spec-item-9
Is prerelease tagging supported? If so, we should check for 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.
@kevinrizza Based on what I've seen, prerelease tagging is supported, and should be checked fo. I suggest that we use an external semver validator such as py package semver
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.
+1
cd77149
to
ca5026e
Compare
@kevinrizza Added the |
tests/test_validate.py
Outdated
@@ -46,7 +46,7 @@ def test_ui_valid_bundle_io(bundle, expected_validation_results_dict): | |||
{'errors': [ | |||
"csv.spec.links must be a list of name & url pairs.", | |||
"spec.version invalid is not a valid version " | |||
"(example of a valid version is: v1.0.12)", | |||
"(example of a valid version is: 1.0.12)", |
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.
Can we make sure to have both a positive and a negative test?
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.
I'll use v<anything>
as the negative test for this field
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.
Actually, since this is already the negative, do you mean we need a positive test case?
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.
For the positive test case, isn't the valid.bundle.yaml
sufficient? Or should I test additional valid semvers? I don't think I need to test several semvers this since we're using an external package, so the valid bundle and the invalid bundle should be enough.
ca5026e
to
6806361
Compare
/cc @galletti94 |
6806361
to
7cd235c
Compare
- Use semver.parse on CSV version field This adds support for versions that use a string after the semver. Eg: '0.10.1', '5.4.3-alpha1' and '0.0.3-beta5+build.3' are valid
7cd235c
to
e793ea7
Compare
@MartinBasti @kevinrizza I've rebased my PR, please let me know if additional changes are needed |
/lgtm |
This adds support for versions that use a string after the semver.
Replaces #65