Skip to content

Commit f917421

Browse files
authored
Revert "chore(version)!: remove 'hotpatch' versioning (#14510)" (#14586)
This reverts commit 2f3ef74.
1 parent d3788f6 commit f917421

File tree

4 files changed

+79
-18
lines changed

4 files changed

+79
-18
lines changed

pkg/version/channels_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestGetLatestVersions(t *testing.T) {
14+
four := int64(4)
1415
testCases := []struct {
1516
name string
1617
resp interface{}
@@ -20,16 +21,18 @@ func TestGetLatestVersions(t *testing.T) {
2021
{
2122
"valid response",
2223
map[string]string{
23-
"foo": "foo-1.2.3",
24-
"stable": "stable-2.1.0",
25-
"edge": "edge-2.1.0",
24+
"foo": "foo-1.2.3",
25+
"fooHotpatch": "foo-1.2.3-4",
26+
"stable": "stable-2.1.0",
27+
"edge": "edge-2.1.0",
2628
},
2729
nil,
2830
Channels{
2931
[]channelVersion{
30-
{"foo", "1.2.3", "foo-1.2.3"},
31-
{"stable", "2.1.0", "stable-2.1.0"},
32-
{"edge", "2.1.0", "edge-2.1.0"},
32+
{"foo", "1.2.3", nil, "foo-1.2.3"},
33+
{"foo", "1.2.3", &four, "foo-1.2.3-4"},
34+
{"stable", "2.1.0", nil, "stable-2.1.0"},
35+
{"edge", "2.1.0", nil, "edge-2.1.0"},
3336
},
3437
},
3538
},
@@ -99,7 +102,7 @@ func channelsEqual(c1, c2 Channels) bool {
99102
for _, cv1 := range c1.array {
100103
found := false
101104
for _, cv2 := range c2.array {
102-
if cv1.channel == cv2.channel && cv1.version == cv2.version {
105+
if cv1.channel == cv2.channel && cv1.version == cv2.version && cv1.hotpatchEqual(cv2) {
103106
found = true
104107
break
105108
}
@@ -113,12 +116,13 @@ func channelsEqual(c1, c2 Channels) bool {
113116
}
114117

115118
func TestChannelsMatch(t *testing.T) {
119+
four := int64(4)
116120
channels := Channels{
117121
[]channelVersion{
118-
{"stable", "2.1.0", "stable-2.1.0"},
119-
{"foo", "1.2.3", "foo-1.2.3"},
120-
{"foo", "1.2.3", "foo-1.2.3-4"},
121-
{"version", "3.2.1", "version-3.2.1"},
122+
{"stable", "2.1.0", nil, "stable-2.1.0"},
123+
{"foo", "1.2.3", nil, "foo-1.2.3"},
124+
{"foo", "1.2.3", &four, "foo-1.2.3-4"},
125+
{"version", "3.2.1", nil, "version-3.2.1"},
122126
},
123127
}
124128

@@ -137,7 +141,8 @@ func TestChannelsMatch(t *testing.T) {
137141
fmt.Errorf("is running version 1.2.2 but the latest foo version is 1.2.3"),
138142
},
139143
{
140-
"foo-1.2.3-3", nil,
144+
"foo-1.2.3-3",
145+
fmt.Errorf("is running version 1.2.3-3 but the latest foo version is 1.2.3-4"),
141146
},
142147
{
143148
"unsupportedChannel-1.2.3",

pkg/version/channelversion.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package version
22

33
import (
44
"fmt"
5+
"strconv"
56
"strings"
67
)
78

@@ -10,22 +11,53 @@ import (
1011
type channelVersion struct {
1112
channel string
1213
version string
14+
hotpatch *int64
1315
original string
1416
}
1517

18+
// hotpatchSuffix is the suffix applied to channel names to indicate that the
19+
// version string includes a hotpatch number (e.g. dev-0.1.2-3)
20+
const hotpatchSuffix = "Hotpatch"
21+
1622
func (cv channelVersion) String() string {
1723
return cv.original
1824
}
1925

20-
// updateChannel returns the channel name to check for updates, returning the
21-
// channel name.
26+
// updateChannel returns the channel name to check for updates. if there's no
27+
// hotpatch number set, then it returns the channel name itself. otherwise it
28+
// returns the channel name suffixed with "Hotpatch" to indicate that a separate
29+
// update channel should be used.
2230
func (cv channelVersion) updateChannel() string {
31+
if cv.hotpatch != nil {
32+
return cv.channel + hotpatchSuffix
33+
}
2334
return cv.channel
2435
}
2536

37+
// versionWithHotpatch returns the version string, suffixed with the hotpatch
38+
// number if it exists.
39+
func (cv channelVersion) versionWithHotpatch() string {
40+
if cv.hotpatch == nil {
41+
return cv.version
42+
}
43+
return fmt.Sprintf("%s-%d", cv.version, *cv.hotpatch)
44+
}
45+
46+
func (cv channelVersion) hotpatchEqual(other channelVersion) bool {
47+
if cv.hotpatch == nil && other.hotpatch == nil {
48+
return true
49+
}
50+
if cv.hotpatch == nil || other.hotpatch == nil {
51+
return false
52+
}
53+
return *cv.hotpatch == *other.hotpatch
54+
}
55+
2656
// parseChannelVersion parses a build string into a channelVersion struct. it
2757
// expects the channel and version to be separated by a hyphen (e.g. dev-0.1.2).
28-
// if the version is suffixed with any other non-numeric build info strings (e.g. dev-0.1.2-foo),
58+
// the version may additionally include a hotpatch number, which is separated
59+
// from the base version by another hyphen (e.g. dev-0.1.2-3). if the version is
60+
// suffixed with any other non-numeric build info strings (e.g. dev-0.1.2-foo),
2961
// those strings are ignored.
3062
func parseChannelVersion(cv string) (channelVersion, error) {
3163
parts := strings.Split(cv, "-")
@@ -35,8 +67,16 @@ func parseChannelVersion(cv string) (channelVersion, error) {
3567

3668
channel := parts[0]
3769
version := parts[1]
70+
var hotpatch *int64
71+
72+
for _, part := range parts[2:] {
73+
if i, err := strconv.ParseInt(part, 10, 64); err == nil {
74+
hotpatch = &i
75+
break
76+
}
77+
}
3878

39-
return channelVersion{channel, version, cv}, nil
79+
return channelVersion{channel, version, hotpatch, cv}, nil
4080
}
4181

4282
// IsReleaseChannel returns true if the channel of the version is "edge" or

pkg/version/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func match(expectedVersion, actualVersion string) error {
6161
actual, expected)
6262
}
6363

64-
if actual.version != expected.version {
64+
if actual.version != expected.version || !actual.hotpatchEqual(expected) {
6565
return fmt.Errorf("is running version %s but the latest %s version is %s",
66-
actual.version, actual.channel, expected.version)
66+
actual.versionWithHotpatch(), actual.channel, expected.versionWithHotpatch())
6767
}
6868

6969
return nil

pkg/version/version_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ func TestMatch(t *testing.T) {
2727
expected: "dev-0.1.2-bar",
2828
actual: "dev-0.1.2-baz",
2929
},
30+
{
31+
name: "up-to-date with hotpatch",
32+
expected: "dev-0.1.2-3",
33+
actual: "dev-0.1.2-3",
34+
},
35+
{
36+
name: "up-to-date with hotpatch and different build info",
37+
expected: "dev-0.1.2-3-bar",
38+
actual: "dev-0.1.2-3-baz",
39+
},
3040
{
3141
name: "not up-to-date",
3242
expected: "dev-0.1.2",
@@ -39,6 +49,12 @@ func TestMatch(t *testing.T) {
3949
actual: "dev-0.1.1-bar",
4050
err: errors.New("is running version 0.1.1 but the latest dev version is 0.1.2"),
4151
},
52+
{
53+
name: "not up-to-date with hotpatch",
54+
expected: "dev-0.1.2-3",
55+
actual: "dev-0.1.2-2",
56+
err: errors.New("is running version 0.1.2-2 but the latest dev version is 0.1.2-3"),
57+
},
4258
{
4359
name: "mismatched channels",
4460
expected: "dev-0.1.2",

0 commit comments

Comments
 (0)