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

Fix: Expand regular expression for version #68

Merged
merged 1 commit into from
Mar 29, 2019

Conversation

SamiSousa
Copy link
Contributor

  • Combined regex patterns
  • Added optional version suffix

This adds support for versions that use a string after the semver.
Replaces #65

@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 13, 2019
@kevinrizza
Copy link
Member

@SamiSousa Could you add a unit test that ensures success for the version suffix condition?

Copy link
Contributor

@MartinBasti MartinBasti left a 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

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\.])*')
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

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]+)*)?'
Copy link
Contributor Author

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?

Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

+1

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 20, 2019
@SamiSousa
Copy link
Contributor Author

@kevinrizza Added the semver package for semver parsing, updated the Pipfile appropriately. Updated the example version to match a valid version value

operatorcourier/validate.py Outdated Show resolved Hide resolved
@@ -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)",
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Contributor Author

@SamiSousa SamiSousa Mar 27, 2019

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.

@MartinBasti MartinBasti mentioned this pull request Mar 26, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 27, 2019
@SamiSousa
Copy link
Contributor Author

/cc @galletti94

@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 27, 2019
- 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
@SamiSousa
Copy link
Contributor Author

@MartinBasti @kevinrizza I've rebased my PR, please let me know if additional changes are needed

@kevinrizza
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 29, 2019
@kevinrizza kevinrizza merged commit 830872b into operator-framework:master Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants