diff --git a/internal/helm/repository/oci_chart_repository.go b/internal/helm/repository/oci_chart_repository.go index af987c35..cfb47846 100644 --- a/internal/helm/repository/oci_chart_repository.go +++ b/internal/helm/repository/oci_chart_repository.go @@ -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 { v, err := version.ParseVersion(cv) if err != nil { @@ -239,14 +239,14 @@ func getLastMatchingVersionOrConstraint(cvs []string, ver string) (string, error continue } - matchingVersions = append(matchingVersions, cv) + matchingVersions = append(matchingVersions, v) } if len(matchingVersions) == 0 { return "", fmt.Errorf("could not locate a version matching provided version string %s", ver) } // 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 } diff --git a/internal/helm/repository/oci_chart_repository_test.go b/internal/helm/repository/oci_chart_repository_test.go index 14041653..cc84cd0f 100644 --- a/internal/helm/repository/oci_chart_repository_test.go +++ b/internal/helm/repository/oci_chart_repository_test.go @@ -101,6 +101,8 @@ func TestOCIChartRepoisitory_Get(t *testing.T) { "0.1.5+a.min.hour", "0.1.5+c.now", "0.2.0", + "0.9.0", + "0.10.0", "1.0.0", "1.1.0-rc.1", }, @@ -144,6 +146,11 @@ func TestOCIChartRepoisitory_Get(t *testing.T) { version: "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", version: ">2.0.0",