diff --git a/cmd/skillshare/upgrade.go b/cmd/skillshare/upgrade.go index b29cc48b4..4142b08c6 100644 --- a/cmd/skillshare/upgrade.go +++ b/cmd/skillshare/upgrade.go @@ -104,12 +104,23 @@ func upgradeCLIBinary(dryRun, force bool) error { // Get latest version from GitHub treeSpinner := ui.StartTreeSpinner("Checking latest version...", false) release, err := versionpkg.FetchLatestRelease() + + var latestVersion string if err != nil { - treeSpinner.Fail("Failed to check") - return fmt.Errorf("failed to check latest version: %w", err) + // API failed - try to use cached version + cachedVersion := versionpkg.GetCachedVersion() + if cachedVersion != "" && cachedVersion != version { + latestVersion = cachedVersion + treeSpinner.Success(fmt.Sprintf("Latest: v%s (cached)", latestVersion)) + } else { + // No useful cache - skip silently + treeSpinner.Success("Skipped (rate limited)") + return nil + } + } else { + latestVersion = release.Version + treeSpinner.Success(fmt.Sprintf("Latest: v%s", latestVersion)) } - latestVersion := release.Version - treeSpinner.Success(fmt.Sprintf("Latest: v%s", latestVersion)) if version == latestVersion && !force { ui.StepEnd("Status", "Already up to date ✓") @@ -135,7 +146,7 @@ func upgradeCLIBinary(dryRun, force bool) error { } // Get download URL for current platform - downloadURL, err := release.GetDownloadURL() + downloadURL, err := versionpkg.BuildDownloadURL(latestVersion) if err != nil { return fmt.Errorf("failed to get download URL: %w", err) } diff --git a/internal/version/check.go b/internal/version/check.go index ca05bf367..1e73a3179 100644 --- a/internal/version/check.go +++ b/internal/version/check.go @@ -13,9 +13,9 @@ import ( var Version = "dev" const ( - githubRepo = "runkids/skillshare" - checkInterval = 24 * time.Hour - cacheFileName = "version-check.json" + githubRepo = "runkids/skillshare" + checkInterval = 24 * time.Hour + cacheFileName = "version-check.json" ) // Cache holds version check cache data @@ -26,8 +26,8 @@ type Cache struct { // CheckResult holds the result of a version check type CheckResult struct { - CurrentVersion string - LatestVersion string + CurrentVersion string + LatestVersion string UpdateAvailable bool } @@ -80,6 +80,15 @@ func ClearCache() { os.Remove(cachePath) } +// GetCachedVersion returns the cached latest version if available +func GetCachedVersion() string { + cache, err := loadCache() + if err != nil || cache == nil { + return "" + } + return cache.LatestVersion +} + // loadCache loads the version check cache from disk func loadCache() (*Cache, error) { cachePath, err := getCachePath() diff --git a/internal/version/github.go b/internal/version/github.go index 7dfb196e3..8c50cb6fe 100644 --- a/internal/version/github.go +++ b/internal/version/github.go @@ -44,6 +44,11 @@ type Asset struct { // GetDownloadURL returns the download URL for the current platform func (r *Release) GetDownloadURL() (string, error) { + return BuildDownloadURL(r.Version) +} + +// BuildDownloadURL constructs download URL from version string +func BuildDownloadURL(version string) (string, error) { osName := runtime.GOOS archName := runtime.GOARCH @@ -52,15 +57,11 @@ func (r *Release) GetDownloadURL() (string, error) { if osName == "windows" { ext = "zip" } - expectedName := fmt.Sprintf("skillshare_%s_%s_%s.%s", r.Version, osName, archName, ext) - for _, asset := range r.Assets { - if asset.Name == expectedName { - return asset.BrowserDownloadURL, nil - } - } - - return "", fmt.Errorf("no release found for %s/%s", osName, archName) + // Construct URL directly (avoids needing asset list from API) + filename := fmt.Sprintf("skillshare_%s_%s_%s.%s", version, osName, archName, ext) + url := fmt.Sprintf("https://github.com/%s/releases/download/v%s/%s", githubRepo, version, filename) + return url, nil } // newGitHubClient creates an HTTP client with optional auth