Skip to content

Commit

Permalink
Merge pull request #130 from wader/semver-dont-sort-template
Browse files Browse the repository at this point in the history
semver: Don't sort versions when using template
  • Loading branch information
wader authored Nov 24, 2023
2 parents 0fc0aaa + ea20a61 commit d3d4af0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/filter/semver/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ func (f semverFilter) Filter(versions filter.Versions, versionKey string) (filte
svs = append(svs, semverVersion{ver: ver, v: v})
}
}
sort.Slice(svs, func(i int, j int) bool {
return svs[i].ver.LessThan(svs[j].ver)
})

// if template assume input is already sorted etc
if f.template != "" {
var vs filter.Versions
for _, v := range svs {
Expand All @@ -143,6 +141,10 @@ func (f semverFilter) Filter(versions filter.Versions, versionKey string) (filte
return vs, versionKey, nil
}

sort.Slice(svs, func(i int, j int) bool {
return svs[i].ver.LessThan(svs[j].ver)
})

var latest *semverVersion
var latestIndex int
for i, v := range svs {
Expand Down
7 changes: 7 additions & 0 deletions internal/pipeline/testdata/semver
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ n. -> error:no filter matches

semver -> error:no filter matches
semver: -> error:needs a contraint or version pattern argument

n.n.n -> semver:n.n.n
4.5.6,1.2.3 -> 4.5.6,1.2.3 4.5.6
1.2.3,4.5.6 -> 1.2.3,4.5.6 1.2.3
semver:n -> semver:n
4.5.6,1.2.3 -> 4,1 4
1.2.3,4.5.6 -> 1,4 1

0 comments on commit d3d4af0

Please sign in to comment.