Skip to content

Commit

Permalink
feat: sort the versions property
Browse files Browse the repository at this point in the history
  • Loading branch information
szkiba committed Oct 1, 2024
1 parent 23d19c9 commit fe1b715
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func load(ctx context.Context, in io.Reader, loose bool, lint bool, origin strin

ext.Versions = filterVersions(ext.Versions, constraints)
}

if err := sortVersions(ext.Versions); err != nil {
return nil, err
}
}

if lint {
Expand Down
32 changes: 31 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmd

import "github.com/Masterminds/semver/v3"
import (
"sort"

"github.com/Masterminds/semver/v3"
)

func tagsToVersions(tags []string) []string {
versions := make([]string, 0, len(tags))
Expand Down Expand Up @@ -33,3 +37,29 @@ func filterVersions(tags []string, constraints *semver.Constraints) []string {

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
}
9 changes: 9 additions & 0 deletions releases/v0.1.31.md
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.

0 comments on commit fe1b715

Please sign in to comment.