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

Skip to content

Commit 54cb664

Browse files
committed
more stuff
1 parent d855172 commit 54cb664

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

buildinfo/buildinfo.go

Lines changed: 2 additions & 19 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

@@ -59,27 +58,11 @@ func Version() string {
5958
// disregarded. If it detects that either version is a developer build it
6059
// returns true.
6160
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) {
61+
if semver.Prerelease(v1) == "-devel" || semver.Prerelease(v2) == "-devel" {
6562
return true
6663
}
6764

68-
v1Toks := strings.Split(v1, ".")
69-
v2Toks := strings.Split(v2, ".")
70-
71-
// Versions should be formatted as "<major>.<minor>.<patch>".
72-
// We assume malformed versions are evidence of a bug and return false.
73-
if len(v1Toks) < 3 || len(v2Toks) < 3 {
74-
return false
75-
}
76-
77-
// Slice off the patch suffix. Patch versions should be non-breaking
78-
// changes.
79-
v1MajorMinor := strings.Join(v1Toks[:2], ".")
80-
v2MajorMinor := strings.Join(v2Toks[:2], ".")
81-
82-
return v1MajorMinor == v2MajorMinor
65+
return semver.MajorMinor(v1) == semver.MajorMinor(v2)
8366
}
8467

8568
// ExternalURL returns a URL referencing the current Coder version.

buildinfo/buildinfo_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,6 @@ func TestBuildInfo(t *testing.T) {
4848
v2: "v1.2.3",
4949
expectMatch: true,
5050
},
51-
// Test that we return false if a version is malformed.
52-
{
53-
name: "MalformedIgnored",
54-
v1: "v1.2.3",
55-
v2: "v1.2",
56-
expectMatch: false,
57-
},
5851
// Test that we return true if a developer version is detected.
5952
// Developers do not need to be warned of mismatched versions.
6053
{
@@ -86,10 +79,6 @@ func TestBuildInfo(t *testing.T) {
8679
}
8780

8881
for _, c := range cases {
89-
// It's very important to do this since we're running the tests
90-
// in parallel. Otherwise you will likely get the last element
91-
// in the list since the goroutines will likely start executing
92-
// after the for loop has completed.
9382
c := c
9483
t.Run(c.name, func(t *testing.T) {
9584
t.Parallel()

cli/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func Root() *cobra.Command {
127127
cmd.SetUsageTemplate(usageTemplate())
128128

129129
cmd.PersistentFlags().String(varURL, "", "Specify the URL to your deployment.")
130-
cliflag.BoolVarP(cmd.PersistentFlags(), &varSuppressVersion, "no-version-warning", "", envNoVersionCheck, false, "Suppress warning when client and server versions do not match.")
130+
cliflag.BoolVarP(cmd.Flags(), &varSuppressVersion, "no-version-warning", "", envNoVersionCheck, false, "Suppress warning when client and server versions do not match.")
131131
cliflag.String(cmd.PersistentFlags(), varToken, "", envSessionToken, "", fmt.Sprintf("Specify an authentication token. For security reasons setting %s is preferred.", envSessionToken))
132132
cliflag.String(cmd.PersistentFlags(), varAgentToken, "", "CODER_AGENT_TOKEN", "", "Specify an agent authentication token.")
133133
_ = cmd.PersistentFlags().MarkHidden(varAgentToken)

codersdk/buildinfo.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package codersdk
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/json"
76
"net/http"
7+
"strings"
8+
9+
"golang.org/x/mod/semver"
810
)
911

1012
// BuildInfoResponse contains build information for this instance of Coder.
@@ -20,13 +22,8 @@ type BuildInfoResponse struct {
2022
// TrimmedVersion trims build information from the version.
2123
// E.g. 'v0.7.4-devel+11573034' -> 'v0.7.4'.
2224
func (b BuildInfoResponse) TrimmedVersion() string {
23-
// Linter doesn't like strings.Index...
24-
idx := bytes.Index([]byte(b.Version), []byte("-devel"))
25-
if idx < 0 {
26-
return b.Version
27-
}
28-
29-
return b.Version[:idx]
25+
trimmed := strings.ReplaceAll(b.Version, "-devel", "+devel")
26+
return semver.Canonical(trimmed)
3027
}
3128

3229
// BuildInfo returns build information for this instance of Coder.

0 commit comments

Comments
 (0)