-
Notifications
You must be signed in to change notification settings - Fork 372
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
semver: add wrapper for SemVer functionality #273
Conversation
Tests expected to fail because kubernetes-sigs/krew-index#181 currently fails the |
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.
Nice work overall, just some small nits.
func (v Version) String() string { | ||
vv := k8sver.Version(v) | ||
s := (&vv).String() | ||
if !strings.HasPrefix(s, "v") { |
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 check is obsolete, as it will always evaluate to true, so that could be a one-liner.
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.
k8sver.Version#String() will return a string DEFINITELY starting without v
. This check helps us change the underlying semver utility without changing our code. (This pkg is meant to be a wrapper.)
Not all semver parsers are enforcing v*, but I want to.
// character. | ||
func Parse(s string) (Version, error) { | ||
var vv Version | ||
if !strings.HasPrefix(s, "v") { |
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.
We could be lenient here and just pass through the semver, as k8sver understands an optional v
prefix.
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 think we should be less lenient first, then maybe more lenient.
Right now all plugins have v* prefix, so let's keep 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.
IMHO the k8sver handles errors just fine, so why add additional checks around that call? I don't think we will switch to another SemVer implementation which would require the v prefix (that would justify the additional check).
But it's a minor thing, I'm fine either way. Your call.
{"negative value in minor", "v1.-2.3", "", true}, | ||
{"negative value in patch", "v1.2.-3", "", true}, | ||
{"empty pre-release identifier", "v1.0.1-", "", true}, | ||
{"empty meta identifier", "v1.0.1+", "", true}, |
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.
Maybe also worth testing if [:alpha:]
chars lead to errors.
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 you give a specific example?
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.
Something like
{"major with alpha chars", "va.0.1", "", true},
{"minor with alpha chars", "v1.a.1", "", true},
{"patch with alpha chars", "v1.0.a", "", true},
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.
that feels a bit too obvious but I'll add tests for v0a.0.0
, v0.0a.0
and v0.0.0a
5be39c5
to
c512307
Compare
Codecov Report
@@ Coverage Diff @@
## master #273 +/- ##
==========================================
+ Coverage 53.94% 54.98% +1.04%
==========================================
Files 18 19 +1
Lines 862 882 +20
==========================================
+ Hits 465 485 +20
Misses 341 341
Partials 56 56
Continue to review full report at Codecov.
|
This package introduces a wrapper for `k8s.io/apimachinery/pkg/util/version` package for its parts that we rely on for our handling of semver values. go.{mod,sum} will likely conflict soon as there are other in-flight PRs. Also refactored the validation code to verify 'version' value can be parsed. Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, corneliusweig The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This package introduces a wrapper for
k8s.io/apimachinery/pkg/util/version
package for its parts that we rely on for our handling of semver values.
go.{mod,sum} will likely conflict soon as there are other in-flight PRs.
Also refactored the validation code to verify 'version' value can be parsed.
/assign @corneliusweig