mirror of
https://github.com/coder/coder.git
synced 2025-07-23 21:32:07 +00:00
feat: add version checking to CLI (#2725)
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user