Skip to content

Commit

Permalink
Update version check to use semantic versioning. (#125)
Browse files Browse the repository at this point in the history
* Update version check to use semantic versioning.

This change adds a new dependency to

    github.com/Masterminds/semver

It now parses the published version from GitHub and the installed
version, then does a comparison of the two versions using the
semantic versioning algorithm.

* Make version error messages mutually exclusive.

---------

Co-authored-by: Curtis Schlak <[email protected]>
  • Loading branch information
realistschuckle and Curtis Schlak authored Mar 6, 2024
1 parent bb77eca commit d21f10e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/user"
"time"

"github.com/Masterminds/semver"
"github.com/gSchool/glearn-cli/api/github"
"github.com/gSchool/glearn-cli/api/learn"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -153,7 +154,15 @@ func setupLearnAPI(getPresignedPostUrl bool) {
if err != nil {
fmt.Printf("Something went wrong when fetching latest CLI version: %s\n", err)
} else if version != currentReleaseVersion {
fmt.Printf("\nWARNING: There is newer version of the learn tool available.\nLatest: %s\nCurrent: %s\nTo avoid issues, upgrade by following the instructions at this link:\nhttps://github.com/gSchool/glearn-cli/blob/master/upgrade_instructions.md\n\n", version, currentReleaseVersion)
versionRemote, versionRemoteErr := semver.NewVersion(version)
versionInstalled, versionInstalledErr := semver.NewVersion(currentReleaseVersion)
if versionRemoteErr != nil {
fmt.Printf("Failed to parse the CLI's current version. Err: %v", err)
} else if versionInstalledErr != nil {
fmt.Printf("Failed to parse the latest CLI release version. Err: %v", err)
} else if versionInstalled.LessThan(versionRemote) {
fmt.Printf("\nWARNING: There is newer version of the learn tool available.\nLatest: %s\nCurrent: %s\nTo avoid issues, upgrade by following the instructions at this link:\nhttps://github.com/gSchool/glearn-cli/blob/master/upgrade_instructions.md\n\n", version, currentReleaseVersion)
}
}

learn.API = api
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
)

require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/fatih/color v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
Expand Down

0 comments on commit d21f10e

Please sign in to comment.