Skip to content

Commit

Permalink
fix(cli): do not upgrade if latest stable is older(eg: beta)
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan CJ <rohantmp@gmail.com>
  • Loading branch information
rohantmp committed Sep 12, 2024
1 parent b3eb551 commit 6e00f0c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ func CheckForNewerVersion() (string, error) {
errLatestVersion = err
return
}

v := semver.MustParse(version)
// if latest not found or latest version found is less than or equal to the current version, do not upgrade
if !found || latest.Version.Compare(v) != 1 {
if !found {
return
}

Expand Down Expand Up @@ -147,13 +145,27 @@ func Upgrade(flagVersion string, log log.Logger) error {
return nil
}

newerVersion, err := CheckForNewerVersion()
latestStable, err := CheckForNewerVersion()
if err != nil {
return err
}
if newerVersion == "" {
if latestStable == "" {
log.Infof("Current binary is the latest version: %s", version)
return nil
}

version = GetVersion()
semverCurrentVersion := semver.MustParse(version)
semverLatestStableVersion := semver.MustParse(latestStable)
cmp := semverLatestStableVersion.Compare(semverCurrentVersion)
if cmp == 0 {
log.Infof("Current binary is the latest version: %s", version)
return nil
} else if cmp == -1 {
command := fmt.Sprintf("%s upgrade --version %s", os.Args[0], latestStable)
log.Infof("Current binary version is newer than the latest stable version: %q", version)
log.Infof("To upgrade to latest stable use %q.", command)
return nil
}

v := semver.MustParse(version)
Expand Down

0 comments on commit 6e00f0c

Please sign in to comment.