MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / checkForUpdate

Function checkForUpdate

cmd/update.go:76–112  ·  view source on GitHub ↗

checkForUpdate checks if a new version is available

()

Source from the content-addressed store, hash-verified

74
75// checkForUpdate checks if a new version is available
76func checkForUpdate() (*UpdateStatus, error) {
77 currentVersion := Version
78 status := &UpdateStatus{
79 CurrentVersion: currentVersion,
80 }
81
82 // Get latest release info
83 release, err := getLatestRelease()
84 if err != nil {
85 status.Error = err.Error()
86 return status, err
87 }
88
89 latestVersion := strings.TrimPrefix(release.TagName, "v")
90 status.LatestVersion = latestVersion
91 status.HasUpdate = isNewer(latestVersion, currentVersion)
92
93 if status.HasUpdate {
94 // Find the appropriate asset for current platform
95 expectedName := fmt.Sprintf("%s_%s", runtime.GOOS, runtime.GOARCH)
96 for _, asset := range release.Assets {
97 if strings.HasPrefix(asset.Name, expectedName) && !strings.HasSuffix(asset.Name, checksumExtension) {
98 status.DownloadURL = asset.BrowserDownloadURL
99 status.AssetName = asset.Name
100 break
101 }
102 }
103
104 if status.DownloadURL == "" {
105 err := fmt.Errorf("no release found for %s/%s", runtime.GOOS, runtime.GOARCH)
106 status.Error = err.Error()
107 return status, err
108 }
109 }
110
111 return status, nil
112}
113
114// performUpdate downloads and installs the update
115func performUpdate(status *UpdateStatus) error {

Callers 4

runUpdateFunction · 0.85
handleSettingsFunction · 0.85
handleUpdateCheckFunction · 0.85
handleUpdatePerformFunction · 0.85

Calls 3

getLatestReleaseFunction · 0.85
isNewerFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected