Fix sorting semver from OCI repository tags
If implemented this fix the issue where we previously did a string ordering of matching semver versions when retrieving a list of tags from an OCI registry. Signed-off-by: Soule BA <soule@weave.works>
This commit is contained in:
parent
e55c0ceb5d
commit
a163ea1dff
|
@ -228,7 +228,7 @@ func getLastMatchingVersionOrConstraint(cvs []string, ver string) (string, error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
matchingVersions := make([]string, 0, len(cvs))
|
matchingVersions := make([]*semver.Version, 0, len(cvs))
|
||||||
for _, cv := range cvs {
|
for _, cv := range cvs {
|
||||||
v, err := version.ParseVersion(cv)
|
v, err := version.ParseVersion(cv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -239,14 +239,14 @@ func getLastMatchingVersionOrConstraint(cvs []string, ver string) (string, error
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
matchingVersions = append(matchingVersions, cv)
|
matchingVersions = append(matchingVersions, v)
|
||||||
}
|
}
|
||||||
if len(matchingVersions) == 0 {
|
if len(matchingVersions) == 0 {
|
||||||
return "", fmt.Errorf("could not locate a version matching provided version string %s", ver)
|
return "", fmt.Errorf("could not locate a version matching provided version string %s", ver)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort versions
|
// Sort versions
|
||||||
sort.Sort(sort.Reverse(sort.StringSlice(matchingVersions)))
|
sort.Sort(sort.Reverse(semver.Collection(matchingVersions)))
|
||||||
|
|
||||||
return matchingVersions[0], nil
|
return matchingVersions[0].Original(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,8 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
|
||||||
"0.1.5+a.min.hour",
|
"0.1.5+a.min.hour",
|
||||||
"0.1.5+c.now",
|
"0.1.5+c.now",
|
||||||
"0.2.0",
|
"0.2.0",
|
||||||
|
"0.9.0",
|
||||||
|
"0.10.0",
|
||||||
"1.0.0",
|
"1.0.0",
|
||||||
"1.1.0-rc.1",
|
"1.1.0-rc.1",
|
||||||
},
|
},
|
||||||
|
@ -144,6 +146,11 @@ func TestOCIChartRepoisitory_Get(t *testing.T) {
|
||||||
version: "0.1.0",
|
version: "0.1.0",
|
||||||
expected: "0.1.0",
|
expected: "0.1.0",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "should return 0.10.0",
|
||||||
|
version: "0.*",
|
||||||
|
expected: "0.10.0",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "should an error for unfunfilled range",
|
name: "should an error for unfunfilled range",
|
||||||
version: ">2.0.0",
|
version: ">2.0.0",
|
||||||
|
|
Loading…
Reference in New Issue