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

Skip to content

Commit 9a9bae1

Browse files
committed
use semver
1 parent 5435418 commit 9a9bae1

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

buildinfo/buildinfo.go

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

@@ -61,25 +60,11 @@ func Version() string {
6160
func VersionsMatch(v1, v2 string) bool {
6261
// Developer versions are disregarded...hopefully they know what they are
6362
// doing.
64-
if strings.HasPrefix(v1, develPrefix) || strings.HasPrefix(v2, develPrefix) {
63+
if semver.Prerelease(v1) != "" || semver.Prerelease(v2) != "" {
6564
return true
6665
}
6766

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
67+
return semver.Compare(semver.MajorMinor(v1), semver.MajorMinor(v2)) == 0
8368
}
8469

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

buildinfo/buildinfo_test.go

Lines changed: 0 additions & 7 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
{

0 commit comments

Comments
 (0)