checkForUpdates checks if a newer version of gh-aw is available This function is non-blocking and ignores all errors (connectivity, API, etc.)
(noCheckUpdate bool, verbose bool)
| 100 | // checkForUpdates checks if a newer version of gh-aw is available |
| 101 | // This function is non-blocking and ignores all errors (connectivity, API, etc.) |
| 102 | func checkForUpdates(noCheckUpdate bool, verbose bool) { |
| 103 | // Quick check if we should even attempt the update check |
| 104 | if !shouldCheckForUpdate(noCheckUpdate) { |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | updateCheckLog.Print("Checking for gh-aw updates...") |
| 109 | |
| 110 | // Update the last check time immediately to prevent concurrent checks |
| 111 | updateLastCheckTime() |
| 112 | |
| 113 | // Get current version |
| 114 | currentVersion := GetVersion() |
| 115 | if !workflow.IsReleasedVersion(currentVersion) { |
| 116 | updateCheckLog.Print("Not a released version, skipping update check") |
| 117 | return |
| 118 | } |
| 119 | |
| 120 | // Query GitHub API for latest release |
| 121 | latestVersion, err := getLatestRelease(false) |
| 122 | if err != nil { |
| 123 | // Silently ignore errors - update check should never fail the command |
| 124 | updateCheckLog.Printf("Error checking for updates (ignoring): %v", err) |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | if latestVersion == "" { |
| 129 | updateCheckLog.Print("Could not determine latest version") |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | if latestVersion == currentVersion { |
| 134 | if verbose { |
| 135 | updateCheckLog.Print("gh-aw is up to date") |
| 136 | } |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | currentVersionNormalized := strings.TrimPrefix(currentVersion, "v") |
| 141 | latestVersionNormalized := strings.TrimPrefix(latestVersion, "v") |
| 142 | if currentVersionNormalized == latestVersionNormalized { |
| 143 | if verbose { |
| 144 | updateCheckLog.Print("gh-aw is up to date (version format differs)") |
| 145 | } |
| 146 | return |
| 147 | } |
| 148 | |
| 149 | if isCurrentVersionAtLeastLatest(currentVersion, latestVersion) { |
| 150 | updateCheckLog.Printf("Current version (%s) appears newer than latest release (%s), skipping notification", currentVersion, latestVersion) |
| 151 | return |
| 152 | } |
| 153 | |
| 154 | // A newer version is available - display update message |
| 155 | updateCheckLog.Printf("Newer version available: %s (current: %s)", latestVersion, currentVersion) |
| 156 | fmt.Fprintln(os.Stderr, "") |
| 157 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("A new version of gh-aw is available: %s (current: %s)", renderReleaseVersion(latestVersion), renderReleaseVersion(currentVersion)))) |
| 158 | fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Update with: gh extension upgrade github/gh-aw")) |
| 159 | fmt.Fprintln(os.Stderr, "") |