From 121d2d8d8efc536085fef1f1792c068af5fa815d Mon Sep 17 00:00:00 2001 From: Denise Li Date: Wed, 10 Apr 2024 16:16:18 -0400 Subject: [PATCH] Switch version comparator logic to use semver --- version.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/version.go b/version.go index 646c3f883..0c24edba5 100644 --- a/version.go +++ b/version.go @@ -2,7 +2,8 @@ package ftl import ( "regexp" - "strconv" + + "golang.org/x/mod/semver" ) const VersionNumberParts int = 3 @@ -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"