Skip to content

Commit

Permalink
Merge pull request #30 from hathora/fix-version-check
Browse files Browse the repository at this point in the history
Fix version check to show if there's a newer release than the installed binary
  • Loading branch information
drewfead authored Jun 14, 2024
2 parents 9a38eb5 + b546d33 commit 4825759
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
15 changes: 8 additions & 7 deletions internal/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ func App() *cli.Command {
Version: BuildVersion,
CustomRootCommandHelpTemplate: cli.SubcommandHelpTemplate,
Before: func(ctx context.Context, cmd *cli.Command) error {
cfg, err := VerbosityConfigFrom(cmd)
if err != nil {
return err
}
_, cleanupLogger := setup.Logger(cfg.Verbosity)
cleanup = append(cleanup, cleanupLogger)
handleNewVersionAvailable(BuildVersion)

if isCallForHelp(cmd) {
return nil
}
err := altsrc.InitializeValueSourcesFromFlags(ctx, cmd, os.Args[1:])
if err != nil {
return err
}
cfg, err := VerbosityConfigFrom(cmd)

err = altsrc.InitializeValueSourcesFromFlags(ctx, cmd, os.Args[1:])
if err != nil {
return err
}
_, cleanupLogger := setup.Logger(cfg.Verbosity)
cleanup = append(cleanup, cleanupLogger)
return nil
},
Commands: []*cli.Command{
Expand Down
14 changes: 11 additions & 3 deletions internal/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,17 @@ func handleNewVersionAvailable(currentVersion string) {
zap.L().Warn("unable to decode the latest version number")
}

versionDiff := version.Compare(release.TagName, currentVersion)
prefixedVersion := "go" + currentVersion
showLatest := false
if !version.IsValid(prefixedVersion) {
zap.L().Warn("You are using a development version of the hathora cli.")
showLatest = true
} else if version.Compare("go"+release.TagName, prefixedVersion) > 0 {
zap.L().Warn("You are using an outdated version of the hathora cli.")
showLatest = true
}

if versionDiff > 0 {
zap.L().Warn("A new version of hathora-ci is available for download.")
if showLatest {
zap.L().Warn("Version " + release.TagName + " is available for download.")
}
}

0 comments on commit 4825759

Please sign in to comment.