Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c92f17

Browse files
authored
Revert "feat: add version checking to CLI (#2643)"
This reverts commit 7ee7be3.
1 parent 7ee7be3 commit 6c92f17

File tree

6 files changed

+5
-174
lines changed

6 files changed

+5
-174
lines changed

buildinfo/buildinfo.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package buildinfo
33
import (
44
"fmt"
55
"runtime/debug"
6-
"strings"
76
"sync"
87
"time"
98

@@ -25,11 +24,6 @@ var (
2524
tag string
2625
)
2726

28-
const (
29-
// develPrefix is prefixed to developer versions of the application.
30-
develPrefix = "v0.0.0-devel"
31-
)
32-
3327
// Version returns the semantic version of the build.
3428
// Use golang.org/x/mod/semver to compare versions.
3529
func Version() string {
@@ -41,7 +35,7 @@ func Version() string {
4135
if tag == "" {
4236
// This occurs when the tag hasn't been injected,
4337
// like when using "go run".
44-
version = develPrefix + revision
38+
version = "v0.0.0-devel" + revision
4539
return
4640
}
4741
version = "v" + tag
@@ -54,20 +48,6 @@ func Version() string {
5448
return version
5549
}
5650

57-
// VersionsMatch compares the two versions. It assumes the versions match if
58-
// the major and the minor versions are equivalent. Patch versions are
59-
// disregarded. If it detects that either version is a developer build it
60-
// returns true.
61-
func VersionsMatch(v1, v2 string) bool {
62-
// Developer versions are disregarded...hopefully they know what they are
63-
// doing.
64-
if strings.HasPrefix(v1, develPrefix) || strings.HasPrefix(v2, develPrefix) {
65-
return true
66-
}
67-
68-
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
69-
}
70-
7151
// ExternalURL returns a URL referencing the current Coder version.
7252
// For production builds, this will link directly to a release.
7353
// For development builds, this will link to a commit.

buildinfo/buildinfo_test.go

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package buildinfo_test
22

33
import (
4-
"fmt"
54
"testing"
65

76
"github.com/stretchr/testify/require"
@@ -30,70 +29,4 @@ func TestBuildInfo(t *testing.T) {
3029
_, valid := buildinfo.Time()
3130
require.False(t, valid)
3231
})
33-
34-
t.Run("VersionsMatch", func(t *testing.T) {
35-
t.Parallel()
36-
37-
type testcase struct {
38-
name string
39-
v1 string
40-
v2 string
41-
expectMatch bool
42-
}
43-
44-
cases := []testcase{
45-
{
46-
name: "OK",
47-
v1: "v1.2.3",
48-
v2: "v1.2.3",
49-
expectMatch: true,
50-
},
51-
// Test that we return true if a developer version is detected.
52-
// Developers do not need to be warned of mismatched versions.
53-
{
54-
name: "DevelIgnored",
55-
v1: "v0.0.0-devel+123abac",
56-
v2: "v1.2.3",
57-
expectMatch: true,
58-
},
59-
// Our CI instance uses a "-devel" prerelease
60-
// flag. This is not the same as a developer WIP build.
61-
{
62-
name: "DevelPreleaseNotIgnored",
63-
v1: "v1.1.1-devel+123abac",
64-
v2: "v1.2.3",
65-
expectMatch: false,
66-
},
67-
{
68-
name: "MajorMismatch",
69-
v1: "v1.2.3",
70-
v2: "v0.1.2",
71-
expectMatch: false,
72-
},
73-
{
74-
name: "MinorMismatch",
75-
v1: "v1.2.3",
76-
v2: "v1.3.2",
77-
expectMatch: false,
78-
},
79-
// Different patches are ok, breaking changes are not allowed
80-
// in patches.
81-
{
82-
name: "PatchMismatch",
83-
v1: "v1.2.3+hash.whocares",
84-
v2: "v1.2.4+somestuff.hm.ok",
85-
expectMatch: true,
86-
},
87-
}
88-
89-
for _, c := range cases {
90-
c := c
91-
t.Run(c.name, func(t *testing.T) {
92-
t.Parallel()
93-
require.Equal(t, c.expectMatch, buildinfo.VersionsMatch(c.v1, c.v2),
94-
fmt.Sprintf("expected match=%v for version %s and %s", c.expectMatch, c.v1, c.v2),
95-
)
96-
})
97-
}
98-
})
9932
}

cli/login.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ func login() *cobra.Command {
6767
}
6868

6969
client := codersdk.New(serverURL)
70-
71-
// Try to check the version of the server prior to logging in.
72-
// It may be useful to warn the user if they are trying to login
73-
// on a very old client.
74-
err = checkVersions(cmd, client)
75-
if err != nil {
76-
return xerrors.Errorf("check versions: %w", err)
77-
}
78-
7970
hasInitialUser, err := client.HasFirstUser(cmd.Context())
8071
if err != nil {
8172
return xerrors.Errorf("has initial user: %w", err)

cli/root.go

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"fmt"
55
"net/url"
66
"os"
7-
"strconv"
87
"strings"
98
"time"
109

1110
"golang.org/x/xerrors"
1211

13-
"github.com/charmbracelet/lipgloss"
1412
"github.com/kirsle/configdir"
1513
"github.com/mattn/go-isatty"
1614
"github.com/spf13/cobra"
@@ -42,13 +40,7 @@ const (
4240
varForceTty = "force-tty"
4341
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
4442

45-
noVersionCheckFlag = "no-version-warning"
46-
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
47-
)
48-
49-
var (
50-
errUnauthenticated = xerrors.New(notLoggedInMessage)
51-
envSessionToken = "CODER_SESSION_TOKEN"
43+
envSessionToken = "CODER_SESSION_TOKEN"
5244
)
5345

5446
func init() {
@@ -61,37 +53,12 @@ func init() {
6153
}
6254

6355
func Root() *cobra.Command {
64-
var varSuppressVersion bool
65-
6656
cmd := &cobra.Command{
6757
Use: "coder",
6858
SilenceErrors: true,
6959
SilenceUsage: true,
7060
Long: `Coder — A tool for provisioning self-hosted development environments.
7161
`,
72-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
73-
if varSuppressVersion {
74-
return nil
75-
}
76-
77-
// Login handles checking the versions itself since it
78-
// has a handle to an unauthenticated client.
79-
if cmd.Name() == "login" {
80-
return nil
81-
}
82-
83-
client, err := createClient(cmd)
84-
// If the client is unauthenticated we can ignore the check.
85-
// The child commands should handle an unauthenticated client.
86-
if xerrors.Is(err, errUnauthenticated) {
87-
return nil
88-
}
89-
if err != nil {
90-
return xerrors.Errorf("create client: %w", err)
91-
}
92-
return checkVersions(cmd, client)
93-
},
94-
9562
Example: ` Start a Coder server.
9663
` + cliui.Styles.Code.Render("$ coder server") + `
9764
@@ -130,7 +97,6 @@ func Root() *cobra.Command {
13097
cmd.SetUsageTemplate(usageTemplate())
13198

13299
cmd.PersistentFlags().String(varURL, "", "Specify the URL to your deployment.")
133-
cliflag.BoolVarP(cmd.PersistentFlags(), &varSuppressVersion, noVersionCheckFlag, "", envNoVersionCheck, false, "Suppress warning when client and server versions do not match.")
134100
cliflag.String(cmd.PersistentFlags(), varToken, "", envSessionToken, "", fmt.Sprintf("Specify an authentication token. For security reasons setting %s is preferred.", envSessionToken))
135101
cliflag.String(cmd.PersistentFlags(), varAgentToken, "", "CODER_AGENT_TOKEN", "", "Specify an agent authentication token.")
136102
_ = cmd.PersistentFlags().MarkHidden(varAgentToken)
@@ -176,7 +142,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
176142
if err != nil {
177143
// If the configuration files are absent, the user is logged out
178144
if os.IsNotExist(err) {
179-
return nil, errUnauthenticated
145+
return nil, xerrors.New(notLoggedInMessage)
180146
}
181147
return nil, err
182148
}
@@ -191,7 +157,7 @@ func createClient(cmd *cobra.Command) (*codersdk.Client, error) {
191157
if err != nil {
192158
// If the configuration files are absent, the user is logged out
193159
if os.IsNotExist(err) {
194-
return nil, errUnauthenticated
160+
return nil, xerrors.New(notLoggedInMessage)
195161
}
196162
return nil, err
197163
}
@@ -365,30 +331,3 @@ func FormatCobraError(err error, cmd *cobra.Command) string {
365331
helpErrMsg := fmt.Sprintf("Run '%s --help' for usage.", cmd.CommandPath())
366332
return cliui.Styles.Error.Render(err.Error() + "\n" + helpErrMsg)
367333
}
368-
369-
func checkVersions(cmd *cobra.Command, client *codersdk.Client) error {
370-
flag := cmd.Flag("no-version-warning")
371-
if suppress, _ := strconv.ParseBool(flag.Value.String()); suppress {
372-
return nil
373-
}
374-
375-
clientVersion := buildinfo.Version()
376-
377-
info, err := client.BuildInfo(cmd.Context())
378-
if err != nil {
379-
return xerrors.Errorf("build info: %w", err)
380-
}
381-
382-
fmtWarningText := `version mismatch: client %s, server %s
383-
download the server version with: 'curl -L https://coder.com/install.sh | sh -s -- --version %s'
384-
`
385-
386-
if !buildinfo.VersionsMatch(clientVersion, info.Version) {
387-
warn := cliui.Styles.Warn.Copy().Align(lipgloss.Left)
388-
// Trim the leading 'v', our install.sh script does not handle this case well.
389-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), warn.Render(fmtWarningText), clientVersion, info.Version, strings.TrimPrefix(info.CanonicalVersion(), "v"))
390-
_, _ = fmt.Fprintln(cmd.OutOrStdout())
391-
}
392-
393-
return nil
394-
}

codersdk/buildinfo.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"net/http"
7-
"strings"
8-
9-
"golang.org/x/mod/semver"
107
)
118

129
// BuildInfoResponse contains build information for this instance of Coder.
@@ -19,15 +16,6 @@ type BuildInfoResponse struct {
1916
Version string `json:"version"`
2017
}
2118

22-
// CanonicalVersion trims build information from the version.
23-
// E.g. 'v0.7.4-devel+11573034' -> 'v0.7.4'.
24-
func (b BuildInfoResponse) CanonicalVersion() string {
25-
// We do a little hack here to massage the string into a form
26-
// that works well with semver.
27-
trimmed := strings.ReplaceAll(b.Version, "-devel+", "+devel-")
28-
return semver.Canonical(trimmed)
29-
}
30-
3119
// BuildInfo returns build information for this instance of Coder.
3220
func (c *Client) BuildInfo(ctx context.Context) (BuildInfoResponse, error) {
3321
res, err := c.Request(ctx, http.MethodGet, "/api/v2/buildinfo", nil)

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface AzureInstanceIdentityToken {
3636
readonly encoding: string
3737
}
3838

39-
// From codersdk/buildinfo.go:13:6
39+
// From codersdk/buildinfo.go:10:6
4040
export interface BuildInfoResponse {
4141
readonly external_url: string
4242
readonly version: string

0 commit comments

Comments
 (0)