Skip to content

Commit

Permalink
Use semver comparison for new version check (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Sep 17, 2024
1 parent bc2ccd1 commit 15cb2ba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ toolchain go1.22.3
require (
github.com/charmbracelet/bubbles v0.19.0
github.com/charmbracelet/bubbletea v0.27.1
github.com/coreos/go-semver v0.3.0
github.com/dukex/mixpanel v1.0.1
github.com/getsentry/sentry-go v0.29.0
github.com/go-git/go-git/v5 v5.11.0
Expand Down Expand Up @@ -81,7 +82,6 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmS
github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU=
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4=
github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down
14 changes: 13 additions & 1 deletion internal/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"github.com/onflow/flow-cli/internal/prompt"

"github.com/coreos/go-semver/semver"
"github.com/dukex/mixpanel"
"github.com/getsentry/sentry-go"
"github.com/spf13/afero"
Expand Down Expand Up @@ -302,7 +303,18 @@ func checkVersion(logger output.Logger) {

latestVersion := fmt.Sprintf("v%s", strings.TrimPrefix(latestVersionRaw, "v"))

if currentVersion != latestVersion {
// compare semver versions
currentSemver, err := semver.NewVersion(strings.TrimPrefix(currentVersion, "v"))
if err != nil {
return
}

latestSemver, err := semver.NewVersion(strings.TrimPrefix(latestVersion, "v"))
if err != nil {
return
}

if currentSemver.LessThan(*latestSemver) {
logger.Info(fmt.Sprintf(
"\n%s Version warning: a new version of Flow CLI is available (%s).\n"+
" Read the installation guide for upgrade instructions: https://docs.onflow.org/flow-cli/install\n",
Expand Down

0 comments on commit 15cb2ba

Please sign in to comment.