feat: add version checking to CLI (#2725)

This commit is contained in:
Jon Ayers
2022-06-29 17:49:40 -05:00
committed by GitHub
parent 45328ec0f1
commit 7df5827767
6 changed files with 184 additions and 5 deletions

View File

@ -4,6 +4,9 @@ import (
"context"
"encoding/json"
"net/http"
"strings"
"golang.org/x/mod/semver"
)
// BuildInfoResponse contains build information for this instance of Coder.
@ -16,6 +19,15 @@ type BuildInfoResponse struct {
Version string `json:"version"`
}
// CanonicalVersion trims build information from the version.
// E.g. 'v0.7.4-devel+11573034' -> 'v0.7.4'.
func (b BuildInfoResponse) CanonicalVersion() string {
// We do a little hack here to massage the string into a form
// that works well with semver.
trimmed := strings.ReplaceAll(b.Version, "-devel+", "+devel-")
return semver.Canonical(trimmed)
}
// BuildInfo returns build information for this instance of Coder.
func (c *Client) BuildInfo(ctx context.Context) (BuildInfoResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/buildinfo", nil)