-
Notifications
You must be signed in to change notification settings - Fork 47
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
Introduce Masterminds/semver #374
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #374 +/- ##
==========================================
- Coverage 81.68% 81.64% -0.04%
==========================================
Files 21 21
Lines 928 937 +9
==========================================
+ Hits 758 765 +7
- Misses 118 119 +1
- Partials 52 53 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
I think it needs more testing, but this is a start. |
@tmshort we don't have Prow on this repo; if you'd like to "hold" the PR, I'd recommend converting it to draft. |
@@ -87,7 +87,7 @@ func (b *BundlesAndDepsVariableSource) getEntityDependencies(ctx context.Context | |||
// todo(perdasilva): disambiguate between not found and actual errors | |||
requiredPackages, _ := bundleEntity.RequiredPackages() | |||
for _, requiredPackage := range requiredPackages { | |||
semverRange, err := bsemver.ParseRange(requiredPackage.VersionRange) | |||
semverRange, err := mmsemver.NewConstraint(requiredPackage.VersionRange) |
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.
Technically, this should remain blang
if we don't want to change the meaning of (and possibly break) the olm.package.required
constraints.
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 can look at it; changes were only made if they propagated from validation.go
s changes. This likely means that it would require intermixing Masterminds and blang code here.
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, looks like you'll need to convert a blang version to a masterminds verison somewhere along the line.
It looks like bundles_and_dependencies.go and required_package.go both call predicates.InVersionRange
, so it seems like we'll have to break that in two. Perhaps:
predicates.InMastermindsVersionRange
predicates.InBlangVersionRange
And then predicates.InMasterMindsVersionRange
converts the bundle entity blang version to a masterminds version to check against the mastermind constraint?
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.
blang.Range
is a function and cannot be converted into a MasterMind.Constraints
(which is a struct). I'm working out a couple different methods; none of which are pretty...
8ca0525
to
f63044a
Compare
@joelanford ready for review |
"1.Y", | ||
">1.2.3 && <2.3.4", | ||
">1.2.3;<2.3.4", | ||
"1.2.3 - 2.3.4", |
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.
worth including the blang '!=' equivalent here? (e.g. "!1.2.3")
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.
Probably.
/unhold |
Fixes operator-framework#345 Add positive and negative test cases. Signed-off-by: Todd Short <tshort@redhat.com>
Fixes operator-framework#346 Add support for Masterminds/semver for .spec.Version This is a bit more entangled into the code than I expected, most instances of bsemver were replaced. Signed-off-by: Todd Short <tshort@redhat.com>
ping @grokspawn @joelanford this should be ready now |
if err := b.loadPackage(); err != nil { | ||
return nil, err | ||
} | ||
return mmsemver.NewVersion(b.bundlePackage.Version) |
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.
Nit: the asymmetry of VersionBlang()
stuff being parsed during b.loadPackage()
and the masterminds version being parsed here every time is maybe a bit unexpected and feels a bit off?
Other potential options:
- add a new sibling field to
b.semVersion
, parse both duringloadPackage()
- parse into a blang version and then just build a masterminds.Version struct (either here or in
loadPackage
) using the blang version fields (this might be nice because its one fewer error to handle) - have this
Version()
method just return a string and expect that caller to do the parsing.
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.
Another option: do the (option 2) conversion from blang version to masterminds version in the InMastermindsVersionRange()
function.
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.
TL;DR: this is what happens when you try to optimize code coverage!
- I had created a new field, but all errors occurred during blang code processing (since it's just a simple version), and subsequently the masterminds error handling code was never executed, lowering code coverage. I could get rid of the error handling code, but that's bad form.
- The
Masterminds.Version
struct has no user-accessible fields, so you can't create the structure that way. It actually makes more sense to do ablang.Version.String()
and feed that intoMasterminds.NewVersion()
, but it's the same error handling problem as option 1. - This causes the version string to be parsed all the time, also non-optimal, and worse performance than option 1.
EDIT: Using just one semver library would make this moot.
EDIT 2: Option 3 is probably the cleanest in terms of API cleanliness, but not efficiency.
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.
Another option: do the (option 2) conversion from blang version to masterminds version in the InMastermindsVersionRange() function.
AFAICT, this means passing an blang structure into a mastermind-named function, which seems bad form.
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.
this means passing an blang structure into a mastermind-named function, which seems bad form.
I don't think so.
func InMastermindsSemverRange(semverRange *mmsemver.Constraints) input.Predicate {
return func(entity *input.Entity) bool {
bundleEntity := olmentity.NewBundleEntity(entity)
bundleVersion, err := bundleEntity.Version() // this is a blang version
if err != nil {
return false
}
return semverRange.Check(blangToMasterminds(bundleVersion))
}
}
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.
Sorry, I was thinking of this function: https://github.com/Masterminds/semver/blob/2f39fdc11c33c38e8b8b15b1f04334ba84e751f2/version.go#L214
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.
Although option 3 might be the cleanest, it is changing the behavior of sortVersion()
.
Anything I do to try to fix the nit will negatively impact code coverage.
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.
IMO, trying to cover every error path just leads to brittle tests that make refactoring hard. I think as long as we're covering the happy paths, and the coverage "regression" is only happening because of some refactoring of when/how errors are handled, we shouldn't spend time dealing in the 1s or .1s of coverage percentages.
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.
Is there a way to specify a (minimum, err maximum? negative) threshold for CodeCov?
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.
Sorry, I was thinking of this function: https://github.com/Masterminds/semver/blob/2f39fdc11c33c38e8b8b15b1f04334ba84e751f2/version.go#L214
Because of the pre and metadata fields, etc. it's just easier to do all conversions via .String()
.
Signed-off-by: Todd Short <tshort@redhat.com>
628ae95
Description
Add support for Masterminds/semver for .spec.Version
This is a bit more entangled into the code than I expected,
most instances of bsemver were replaced.
Fixes #345 and #346.
Includes the regex commit.
Reviewer Checklist