You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
Given my latest version is v1.0.1 which is a stable release
When I check if v1.0.2 is greater than v1.0.1 then everything works fine
When I check if v1.0.2-alpha.0 is greater than v1.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.
When I check if v1.0.2-alpha.1 is greater than v1.0.2-alpha.0 then everything works fine again.
I wrote a short testcase in Go to validate
issue.go:
package services
import (
"fmt""github.com/hashicorp/go-version"
)
// The next version should be greater that the current versionfuncIsGreater(currentstring, nextstring) bool {
parsedCurrent, err:=version.NewVersion(current)
iferr!=nil {
fmt.Print(err)
returnfalse
}
parsedNext, err:=version.NewVersion(next)
iferr!=nil {
fmt.Print(err)
returnfalse
}
// should be greater that current versionconstraint, err:=version.NewConstraint("> "+parsedCurrent.Original())
iferr!=nil {
fmt.Print(err)
returnfalse
}
if!constraint.Check(parsedNext) {
fmt.Print("next version "+parsedNext.Original() +" is not greater that current version "+parsedCurrent.Original())
}
returnconstraint.Check(parsedNext)
}
issue_test.go:
package services
import (
"testing""github.com/stretchr/testify/assert"
)
funcTest_ShouldBeGreater(t*testing.T) {
testCases:= []struct {
currentVersionstringnextVersionstringshouldBeValidbool
}{
{"v1.0.1", "v1.0.2", true},
{"v1.0.1", "v1.1.0", true},
{"v1.0.1", "v2.0.0", true},
{"v1.0.1", "v1.0.2-alpha.0", true}, // fails but should be true
{"v1.0.1", "v1.0.2-beta.0", true}, // fails but should be true
{"v1.0.2-alpha.0", "v1.0.2-alpha.1", true},
{"v1.0.2-alpha.0", "v1.0.2-beta.0", true},
{"v1.0.2-beta.1", "v1.0.2-beta.2", true},
{"v1.0.2-alpha.0", "v1.0.2", true},
{"v1.0.2-beta.0", "v1.0.2", true},
{"v1.0.2", "v1.0.2", false},
{"v1.0.2", "v1.0.1", false},
{"v1.0.2-beta.0", "v1.0.2-alpha.0", false},
{"v1.0.2-beta.2", "v1.0.2-beta.1", false},
{"v2.0.0", "v2.0.0", false},
}
for_, tc:=rangetestCases {
assert:=assert.New(t)
got:=IsGreater(tc.currentVersion, tc.nextVersion)
assert.NotNil(got)
assert.Equal(tc.shouldBeValid, got, "Result did not meet expectation - next version = "+tc.nextVersion+", current version = "+tc.currentVersion)
}
}
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:
sebastian-sommerfeld-io
changed the title
Version v1.0.2-alpha.0 should be greater than v1.0.1 but constraint.Check returns false
Version v1.0.2-alpha.0 should be greater than v1.0.1 but version.NewConstraint(...).Check returns false
Aug 3, 2023
casecPre&&vPre:
// A constraint with a pre-release can only match a pre-release version// with the same base segments.returnreflect.DeepEqual(c.Segments64(), v.Segments64())
case!cPre&&vPre:
// A constraint without a pre-release can only match a version without a// pre-release.returnfalse
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: