-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from grafana/85-sort-the-versions-property
sort the versions property
- Loading branch information
Showing
3 changed files
with
78 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
) | ||
|
||
func tagsToVersions(tags []string) []string { | ||
versions := make([]string, 0, len(tags)) | ||
|
||
for _, tag := range tags { | ||
_, err := semver.NewVersion(tag) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
versions = append(versions, tag) | ||
} | ||
|
||
return versions | ||
} | ||
|
||
func filterVersions(tags []string, constraints *semver.Constraints) []string { | ||
versions := make([]string, 0, len(tags)) | ||
|
||
for _, tag := range tags { | ||
version, err := semver.NewVersion(tag) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
if constraints.Check(version) { | ||
versions = append(versions, tag) | ||
} | ||
} | ||
|
||
return versions | ||
} | ||
|
||
func sortVersions(versions []string) error { | ||
type version struct { | ||
source string | ||
parsed *semver.Version | ||
} | ||
|
||
all := make([]*version, 0, len(versions)) | ||
|
||
for _, source := range versions { | ||
parsed, err := semver.NewVersion(source) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
all = append(all, &version{source: source, parsed: parsed}) | ||
} | ||
|
||
sort.Slice(all, func(i, j int) bool { return all[i].parsed.Compare(all[j].parsed) > 0 }) | ||
|
||
for idx := range all { | ||
versions[idx] = all[idx].source | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
k6registry `v0.1.31` is here 🎉! | ||
|
||
This is an internal maintenance release. | ||
|
||
**Sort the versions property** | ||
|
||
The tags queried via the repository manager API happen to be in good order, the most recently created tag is at the beginning of the list. However, this does not guarantee that the list is always ordered according to semantic versioning. | ||
|
||
After loading and detecting the versions of the extension during registry generation, the versions property now sorted according to semantic versioning. |