-
Notifications
You must be signed in to change notification settings - Fork 150
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
Version v1.0.2-alpha.0
should be greater than v1.0.1
but version.NewConstraint(...).Check
returns false
#130
Comments
v1.0.2-alpha.0
should be greater than v1.0.1
but constraint.Check
returns falsev1.0.2-alpha.0
should be greater than v1.0.1
but version.NewConstraint(...).Check
returns false
I don't know if it is mentioned in the docs, but the implementation and code comments are here: https://github.com/hashicorp/go-version/blob/main/constraint.go#L197-L215 case cPre && vPre:
// A constraint with a pre-release can only match a pre-release version
// with the same base segments.
return reflect.DeepEqual(c.Segments64(), v.Segments64())
case !cPre && vPre:
// A constraint without a pre-release can only match a version without a
// pre-release.
return false So, it's intentional. |
I've realized that my use case is not well aligned with the purpose of the package (or npm's purposes). This library uses constraints to solve a package dependency problem: Selecting a compatible version from a pool of available releases. I'm trying to use it in a client application, to make inferences about the server's capabilities: "If the server version is >=1.2, it can do feature X" I'd been using a constraint ">=1.2" for that purpose, and not getting the When the server version is, say "2.1-alpha", it does not satisfy the ">=1.2" constraint. The constraint behavior is reasonable when selecting from available packages. It's just less suited to my scenario. My original comment is below. @kke said:
I'm not sure that it is. While the cited comments correctly describe the behavior of the code, this snippet considers pre-release tags only in isolation. There's no mention or consideration of the major/minor/patch values, so it's not a good match for the situation raised by @sebastian-sommerfeld-io. The PR discussion for this code is here. That discussion gets closer to the mark, but doesn't quite address this case. That discussion does, however, make clear that the behavior was intended to match npm's pre-release label handling, and includes a (now-dead) link relevant documentation. The npm link now lives here. The npm document includes this nugget (emphasis mine):
Clearly the npm parser would not fail the constraint check based only on the presence of a pre-release label, but would use that presence as a tiebreaker when considering versions with the same major/minor/patch value. I think it's a bug. I'm hoping @jbardin will weigh in on the original intentions. |
Yes, this is intentional as pointed out earlier in the code. One of the goals of the comparisons made in this package is to ensure that the typical constraints used in a production environment can never automatically update to a prerelease version. One must always explicitly opt-in to try prerelease versions using this scheme, otherwise prereleases are not considered. @chrismarget-j, in a client-server situation, you can use the same constraints, but you must still take care have the client opt-in to test the alpha versions of a server. Depending on the use case, it could be critical that a client configured for I'll close this out since the code is working as designed. |
Thank you for your reply, @jbardin.
Would you mind elaborating on this? I've currently got something like this in the client code: featureXok = version.MustConstraints(version.NewConstraint(">= 1.2.0")) I use it to determine whether it's safe to use server "feature X": if featureXok.Check(client.serverVersion()) {
// do something which relies on feature X
} This check fails when the The failure (3.1.0-alpha is not greater or equal than 1.2.0) took me by surprise. What would it mean to "have the client opt-in to test alpha versions of a server" in this case? I'm thinking of adding |
By "opt-in", I mean that the client would specifically need to use a constraint which allows alpha releases, and Whether a server supports a feature or not is not directly related to whether a particular version is acceptable to use. Version |
Thank you @jbardin.
I'm not sure it's possible for me to write a constraint which broadly considers pre-releases. As it stands now, my client knows nothing about any I think we're zeroing in on the realization I had when I edited my first comment in this issue. This package exists mostly for the reason you just raised: To determine "whether a particular version is acceptable to use". It seems I'm a little off in the weeds trying to use it to create "feature available" milestones. |
Hey guys ... I stumbled upon this issue while implementing a tool to validate versions when I release one of my github projects. I want to make sure, that the version for my next release is greater than the latest version.
When checking for pre-release versions (alpha / beta) I stumbled upon a bug (from my point of view):
v1.0.1
which is a stable releasev1.0.2
is greater thanv1.0.1
then everything works finev1.0.2-alpha.0
is greater thanv1.0.1
then the result is false ... my expectation is that this check would pass, because I increased the minor version and marked it as unstable.v1.0.2-alpha.1
is greater thanv1.0.2-alpha.0
then everything works fine again.I wrote a short testcase in Go to validate
issue.go:
issue_test.go:
Could you take a look into this please? Feel free to reach out to me for information if you feel the need. Best regards.
The text was updated successfully, but these errors were encountered: