Skip to content

Commit

Permalink
Improve compare versions
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 23, 2024
1 parent 7abf99e commit c9c3343
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/cmds/scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func generateImageList(files []string) ([]string, error) {
if !ok {
images[entry] = ""
}
if existing, ok := images[img]; !ok || semver.MustParse(tag).GreaterThan(semver.MustParse(existing)) {
if existing, ok := images[img]; !ok || GreaterThan(tag, existing) {
images[img] = tag
}
}
Expand Down Expand Up @@ -322,3 +322,21 @@ CMD="./crane"

return nil
}

func parseVersion(v string) (*semver.Version, error) {
if strings.HasPrefix(v, "alma-") {
v = strings.TrimPrefix(v, "alma-")
} else if pre, _, ok := strings.Cut(v, "_"); ok {
v = pre
}
return semver.NewVersion(v)
}

func GreaterThan(x, y string) bool {
xv, xe := parseVersion(x)
yv, ye := parseVersion(y)
if xe == nil && ye == nil {
return xv.GreaterThan(yv)
}
return strings.Compare(x, y) > 0
}

0 comments on commit c9c3343

Please sign in to comment.