(ctx context.Context, us *updateState)
| 195 | } |
| 196 | |
| 197 | func (c *App) maybeCheckGithub(ctx context.Context, us *updateState) error { |
| 198 | if !clock.Now().After(us.NextCheckTime) { |
| 199 | return nil |
| 200 | } |
| 201 | |
| 202 | log(ctx).Debug("time for next update check has been reached") |
| 203 | |
| 204 | // before we check for update, write update state file again, so if this fails |
| 205 | // we won't bother GitHub for a while |
| 206 | us.NextCheckTime = clock.Now().Add(c.updateCheckInterval) |
| 207 | if err := c.writeUpdateState(us); err != nil { |
| 208 | return errors.Wrap(err, "unable to write update state") |
| 209 | } |
| 210 | |
| 211 | newAvailableVersion, err := getLatestReleaseNameFromGitHub(ctx) |
| 212 | if err != nil { |
| 213 | return errors.Wrap(err, "update to get the latest release from GitHub") |
| 214 | } |
| 215 | |
| 216 | log(ctx).Debugf("latest version on GitHub: %v previous %v", newAvailableVersion, us.AvailableVersion) |
| 217 | |
| 218 | // we got updated version from GitHub, write it in a state file again |
| 219 | if newAvailableVersion != us.AvailableVersion { |
| 220 | if err = verifyGitHubReleaseIsComplete(ctx, newAvailableVersion); err != nil { |
| 221 | return errors.Wrap(err, "unable to validate GitHub release") |
| 222 | } |
| 223 | |
| 224 | us.AvailableVersion = newAvailableVersion |
| 225 | |
| 226 | if err := c.writeUpdateState(us); err != nil { |
| 227 | return errors.Wrap(err, "unable to write update state") |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | return nil |
| 232 | } |
| 233 | |
| 234 | // maybePrintUpdateNotification prints notification about available version. |
| 235 | func (c *App) maybePrintUpdateNotification(ctx context.Context) { |
no test coverage detected