Skip to content

Commit

Permalink
fix sort's
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Jan 6, 2023
1 parent c293ed5 commit 58bb15f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func main() {
re, _ := regexp.Compile(`\d+\.((\d+|x)(\.(\d+|x))?)`)
ver = string(re.Find([]byte(_path)))
if *major {
ver = string(ver[0]) + ".x"
ver = strings.Split(ver, ".")[0] + ".x"
}
} else {
re := regexp.MustCompile(`junit-(.+).xml`)
Expand Down Expand Up @@ -190,14 +190,13 @@ func main() {
}

sort.Slice(versions, func(i, j int) bool {
v1, err := version.NewVersion(versions[i])
if err != nil {
return false
}
vi := strings.ReplaceAll(versions[i], "x", "0")
vj := strings.ReplaceAll(versions[j], "x", "0")

v2, err := version.NewVersion(versions[j])
if err != nil {
return false
v1, err1 := version.NewVersion(vi)
v2, err2 := version.NewVersion(vj)
if err1 != nil || err2 != nil {
return vi < vj
}

return v1.LessThan(v2)
Expand Down

0 comments on commit 58bb15f

Please sign in to comment.