Skip to content

Commit

Permalink
Switch version comparator logic to use semver
Browse files Browse the repository at this point in the history
  • Loading branch information
deniseli committed Apr 10, 2024
1 parent 14262d3 commit 121d2d8
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package ftl

import (
"regexp"
"strconv"

"golang.org/x/mod/semver"
)

const VersionNumberParts int = 3
Expand All @@ -23,27 +24,12 @@ func IsVersionAtLeastMin(v string, minVersion string) (bool, error) {
if !IsRelease(v) || !IsRelease(minVersion) {
return true, nil
}
vParsed := regexp.MustCompile(`\d+`).FindAllString(v, VersionNumberParts)
minVParsed := regexp.MustCompile(`\d+`).FindAllString(minVersion, VersionNumberParts)
for i := range VersionNumberParts {
vInt, err := strconv.Atoi(vParsed[i])
if err != nil {
return false, err
}
minVInt, err := strconv.Atoi(minVParsed[i])
if err != nil {
return false, err
}
if vInt > minVInt {
return true, nil
}
if vInt < minVInt {
return false, nil
}
}
return true, nil
return semver.Compare("v"+v, "v"+minVersion) >= 0, nil
}

// VersionIsMock is set by tests and used to block evaluation of versions that look like release versions but are not real.
var VersionIsMock = false

// Version of FTL binary (set by linker).
var Version = "dev"

Expand Down

0 comments on commit 121d2d8

Please sign in to comment.