Skip to content

feat: Add support for update checks and notifications #4810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Dec 1, 2022
Merged
Prev Previous commit
Next Next commit
Fix edge case where update check has never succeeded
  • Loading branch information
mafredri committed Nov 29, 2022
commit 64ad0f5b00371de6d87a3e892b38de13be4e0b85
21 changes: 16 additions & 5 deletions coderd/updatecheck.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package coderd

import (
"database/sql"
"net/http"

"golang.org/x/mod/semver"
"golang.org/x/xerrors"

"github.com/coder/coder/buildinfo"
"github.com/coder/coder/coderd/httpapi"
Expand All @@ -13,19 +15,28 @@ import (
func (api *API) updateCheck(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()

currentVersion := codersdk.UpdateCheckResponse{
Current: true,
Version: buildinfo.Version(),
URL: buildinfo.ExternalURL(),
}

if api.updateChecker == nil {
// If update checking is disabled, echo the current
// version.
httpapi.Write(ctx, rw, http.StatusOK, codersdk.UpdateCheckResponse{
Current: true,
Version: buildinfo.Version(),
URL: buildinfo.ExternalURL(),
})
httpapi.Write(ctx, rw, http.StatusOK, currentVersion)
return
}

uc, err := api.updateChecker.Latest(ctx)
if err != nil {
if xerrors.Is(err, sql.ErrNoRows) {
// Update checking is enabled, but has never
// succeeded, reproduce behavior as if disabled.
httpapi.Write(ctx, rw, http.StatusOK, currentVersion)
return
}

httpapi.InternalServerError(rw, err)
return
}
Expand Down