Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"fmt"
"strings"

"github.com/google/go-github/v57/github"
"github.com/savioxavier/termlink"
Expand Down Expand Up @@ -45,15 +46,16 @@ func GithubClient() *github.Client {
func CheckVersionUpdate() {
ghClient := GithubClient()
res, skip := VersionCheck(ghClient)
if skip {
if skip || res == nil || res.TagName == nil {
return
}

// Check if the version is different from the one in the binary
if res.TagName != nil && *res.TagName != fmt.Sprintf("v%s", VersionCli) {
if res.TagName != nil && *res.TagName != VersionCli {
fmt.Printf("A newer version (%s) is available, please upgrade with \"civo update\"\n", *res.TagName)
}
latest := *res.TagName
latestClean := strings.TrimPrefix(latest, "v")
currentClean := strings.TrimPrefix(VersionCli, "v")

if latestClean != currentClean {
fmt.Printf("A newer version (%s) is available, please upgrade with \"civo update\"\n", latest)
}
}

Expand Down
16 changes: 16 additions & 0 deletions common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ func TestVersionCheck(t *testing.T) {
}
})
}

func TestCheckVersionUpdate(t *testing.T) {
t.Run("nil release or tag safety", func(t *testing.T) {
oldCli := VersionCli
defer func() { VersionCli = oldCli }()

VersionCli = "1.0.0"

// Ensure calling with nil handling doesn't panic
res, skip := VersionCheck(github.NewClient(nil))
if skip && res == nil {
// Should return cleanly without panic
CheckVersionUpdate()
}
})
}