Skip to content

Commit dcd565b

Browse files
authored
adjust custom/nightly/adhoc build terminology (#3)
Previously, a version build was (incorrectly) termed "nightly" if it contained a commit count; these are not necessarily, or maybe never, true nightly builds. We now call them "custom" builds. Previously, a build with an arbitrary label was termed "custom"; these are now called "adhoc".
1 parent b28396e commit dcd565b

2 files changed

Lines changed: 112 additions & 60 deletions

File tree

version.go

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
rc = releasePhase(3)
3838
cloudonly = releasePhase(4)
3939
stable = releasePhase(5)
40-
custom = releasePhase(6)
40+
adhoc = releasePhase(6)
4141
)
4242

4343
// Version represents a CockroachDB (binary) version. Versions consist of three parts:
@@ -53,11 +53,11 @@ type Version struct {
5353
// the fields are compared in the order listed here, and the earliest field with
5454
// a difference determines the relative ordering of two unequal versions.
5555
//
56-
// The reference order: year, ordinal, patch, phase, phaseOrdinal, phaseSubOrdinal, nightlyOrdinal
57-
year, ordinal, patch int
58-
phase releasePhase
59-
phaseOrdinal, phaseSubOrdinal, nightlyOrdinal int
60-
customLabel string
56+
// The reference order: year, ordinal, patch, phase, phaseOrdinal, phaseSubOrdinal, customOrdinal
57+
year, ordinal, patch int
58+
phase releasePhase
59+
phaseOrdinal, phaseSubOrdinal, customOrdinal int
60+
adhocLabel string
6161
// raw is the original, unprocessed string this Version was created with
6262
raw string
6363
}
@@ -82,7 +82,7 @@ func (v Version) Patch() int {
8282
// - %p: phase sort order (see the top of version.go)
8383
// - %o: phase ordinal (eg, the 1 in "v24.1.0-rc.1")
8484
// - %s: phase sub-ordinal (eg the 2 in "v24.1.0-rc.1-cloudonly.2")
85-
// - %n: nightly ordinal (eg the 12 in "v24.1.0-12-gabcdef")
85+
// - %n: adhoc build ordinal (eg the 12 in "v24.1.0-12-gabcdef")
8686
// - %%: literal "%"
8787
func (v Version) Format(formatStr string) string {
8888
placeholderRe := regexp.MustCompile("%[^%XYZpPosn]")
@@ -96,7 +96,7 @@ func (v Version) Format(formatStr string) string {
9696
beta: "beta",
9797
rc: "rc",
9898
cloudonly: "cloudonly",
99-
custom: "",
99+
adhoc: "",
100100
stable: "",
101101
}
102102

@@ -107,7 +107,7 @@ func (v Version) Format(formatStr string) string {
107107
formatStr = strings.ReplaceAll(formatStr, "%P", phaseName[v.phase])
108108
formatStr = strings.ReplaceAll(formatStr, "%o", strconv.Itoa(v.phaseOrdinal))
109109
formatStr = strings.ReplaceAll(formatStr, "%s", strconv.Itoa(v.phaseSubOrdinal))
110-
formatStr = strings.ReplaceAll(formatStr, "%n", strconv.Itoa(v.nightlyOrdinal))
110+
formatStr = strings.ReplaceAll(formatStr, "%n", strconv.Itoa(v.customOrdinal))
111111
formatStr = strings.ReplaceAll(formatStr, "%%", "%")
112112
return formatStr
113113
}
@@ -171,9 +171,19 @@ func (v Version) IsPrerelease() bool {
171171
return v.phase < cloudonly && !v.Empty()
172172
}
173173

174-
// IsCustomOrNightlyBuild determines if the version is a custom build or nightly build.
175-
func (v Version) IsCustomOrNightlyBuild() bool {
176-
return v.nightlyOrdinal > 0
174+
// IsCustomOrAdhocBuild determines if the version is a adhoc build or adhoc build.
175+
func (v Version) IsCustomOrAdhocBuild() bool {
176+
return v.IsCustomBuild() || v.IsAdhocBuild()
177+
}
178+
179+
// IsCustomBuild determines if the version is a adhoc build.
180+
func (v Version) IsCustomBuild() bool {
181+
return v.customOrdinal > 0
182+
}
183+
184+
// IsAdhocBuild determines if the version is a adhoc build.
185+
func (v Version) IsAdhocBuild() bool {
186+
return v.adhocLabel != ""
177187
}
178188

179189
// IsCloudOnlyBuild determines if the version is a CockroachDB Cloud specific build.
@@ -197,17 +207,17 @@ func Parse(str string) (Version, error) {
197207
patterns := []*regexp.Regexp{
198208
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))(?:-fips)?$`),
199209
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>alpha|beta|rc|cloudonly)\.(?P<phaseOrdinal>[0-9]+)(?:-fips)?$`),
200-
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<nightlyOrdinal>(?:[1-9][0-9]*|0))-g[a-f0-9]+(?:-fips)?$`),
201-
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>alpha|beta|rc|cloudonly).(?P<phaseOrdinal>[0-9]+)-(?P<nightlyOrdinal>(?:[1-9][0-9]*|0))-g[a-f0-9]+(?:-fips)?$`),
210+
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<customOrdinal>(?:[1-9][0-9]*|0))-g[a-f0-9]+(?:-fips)?$`),
211+
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>alpha|beta|rc|cloudonly).(?P<phaseOrdinal>[0-9]+)-(?P<customOrdinal>(?:[1-9][0-9]*|0))-g[a-f0-9]+(?:-fips)?$`),
202212
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>alpha|beta|rc|cloudonly).(?P<phaseOrdinal>[0-9]+)-cloudonly(-rc|\.)(?P<phaseSubOrdinal>(?:[1-9][0-9]*|0))$`),
203213
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>cloudonly)-rc(?P<phaseOrdinal>[0-9]+)$`),
204214
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<phase>cloudonly)(?P<phaseOrdinal>[0-9]+)?$`),
205215

206216
// vX.Y.Z-<anything> will sort after the corresponding "plain" vX.Y.Z version
207-
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<customLabel>[-a-zA-Z0-9\.\+]+)$`),
217+
regexp.MustCompile(`^v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)\.(?P<patch>(?:[1-9][0-9]*|0))-(?P<adhocLabel>[-a-zA-Z0-9\.\+]+)$`),
208218

209219
// sha256:<hash>:latest-vX.Y-build will sort just after vX.Y.0, but before vX.Y.1
210-
regexp.MustCompile(`^sha256:(?P<customLabel>[^:]+):latest-v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)-build$`),
220+
regexp.MustCompile(`^sha256:(?P<adhocLabel>[^:]+):latest-v(?P<year>[1-9][0-9]*)\.(?P<ordinal>[1-9][0-9]*)-build$`),
211221
}
212222

213223
preReleasePhase := map[string]releasePhase{
@@ -257,15 +267,15 @@ func Parse(str string) (Version, error) {
257267
}
258268
}
259269

260-
// nightly/custom builds, eg -10-g7890abcd
261-
if ord := submatch(pat, matches, "nightlyOrdinal"); ord != "" {
262-
v.nightlyOrdinal, _ = strconv.Atoi(ord)
270+
// adhoc/adhoc builds, eg -10-g7890abcd
271+
if ord := submatch(pat, matches, "customOrdinal"); ord != "" {
272+
v.customOrdinal, _ = strconv.Atoi(ord)
263273
}
264274

265-
// arbitrary/custom build tags; we have these old versions and need to parse them
266-
if customLabel := submatch(pat, matches, "customLabel"); customLabel != "" {
267-
v.phase = custom
268-
v.customLabel = customLabel
275+
// arbitrary/adhoc build tags; we have these old versions and need to parse them
276+
if adhocLabel := submatch(pat, matches, "adhocLabel"); adhocLabel != "" {
277+
v.phase = adhoc
278+
v.adhocLabel = adhocLabel
269279
}
270280

271281
return v, nil
@@ -296,12 +306,12 @@ func MustParse(str string) Version {
296306
// rc, cloudonly. Pre-release versions will look like "v24.1.0-cloudonly.1"
297307
// or "v23.2.0-rc.1".
298308
//
299-
// Additionally, we have custom builds, which have suffixes like "-<n>-g<hex>",
309+
// Additionally, we have adhoc builds, which have suffixes like "-<n>-g<hex>",
300310
// where <n> is an integer commit count past the branch point, and <hex> is
301311
// the git SHA. These versions sort AFTER the corresponding "normal" version,
302312
// eg "v24.1.0-1-g9cbe7c5281" is AFTER "v24.1.0".
303313
//
304-
// A version can have both a pre-release and custom build suffix, like
314+
// A version can have both a pre-release and adhoc build suffix, like
305315
// "v24.1.0-rc.2-14-g<hex>". In these cases, the pre-release portion has precedence,
306316
// so this example would sort after v24.1.0-rc.2, but before v24.1.0-rc.3.
307317
func (v Version) Compare(w Version) int {
@@ -323,10 +333,10 @@ func (v Version) Compare(w Version) int {
323333
if rslt := cmp.Compare(v.phaseSubOrdinal, w.phaseSubOrdinal); rslt != 0 {
324334
return rslt
325335
}
326-
if rslt := cmp.Compare(v.nightlyOrdinal, w.nightlyOrdinal); rslt != 0 {
336+
if rslt := cmp.Compare(v.customOrdinal, w.customOrdinal); rslt != 0 {
327337
return rslt
328338
}
329-
if rslt := cmp.Compare(v.customLabel, w.customLabel); rslt != 0 {
339+
if rslt := cmp.Compare(v.adhocLabel, w.adhocLabel); rslt != 0 {
330340
return rslt
331341
}
332342
return 0

version_test.go

Lines changed: 75 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestVersion_Getters(t *testing.T) {
5050

5151
require.True(t, v.IsPrerelease())
5252
require.False(t, v.IsCloudOnlyBuild())
53-
require.False(t, v.IsCustomOrNightlyBuild())
53+
require.False(t, v.IsCustomOrAdhocBuild())
5454
}
5555

5656
func TestVersion_IsPrerelease(t *testing.T) {
@@ -79,31 +79,73 @@ func TestVersion_IsPrerelease(t *testing.T) {
7979
require.False(t, MustParse("v23.2.0-cloudonly2").IsPrerelease())
8080
}
8181

82-
func TestVersion_IsCustomOrNightlyBuild(t *testing.T) {
83-
// Valid pre-release versions
84-
require.False(t, MustParse("v20.2.0-beta.3").IsCustomOrNightlyBuild())
85-
require.False(t, MustParse("v19.1.0-rc.5").IsCustomOrNightlyBuild())
86-
require.False(t, MustParse("v20.2.0-alpha.1").IsCustomOrNightlyBuild())
87-
require.True(t, MustParse("v21.1.0-rc.2-163-g122c66f436").IsCustomOrNightlyBuild())
88-
require.True(t, MustParse("v21.1.0-beta.5-57-gf05a57face").IsCustomOrNightlyBuild())
89-
require.True(t, MustParse("v21.1.0-alpha.3-2846-g7ae3ac92f7").IsCustomOrNightlyBuild())
90-
91-
// Valid [cloudonly] pre-release versions
92-
require.False(t, MustParse("v23.2.0-rc.2-cloudonly-rc2").IsCustomOrNightlyBuild())
82+
func TestVersion_CustomAndAdhocBuilds(t *testing.T) {
83+
builds := []struct {
84+
version string
85+
adhoc bool
86+
custom bool
87+
}{
88+
// Valid pre-release versions
89+
{version: "v20.2.0-beta.3", adhoc: false, custom: false},
90+
{version: "v19.1.0-rc.5", adhoc: false, custom: false},
91+
{version: "v20.2.0-alpha.1", adhoc: false, custom: false},
92+
{version: "v21.1.0-rc.2-163-g122c66f436", adhoc: false, custom: true},
93+
{version: "v21.1.0-beta.5-57-gf05a57face", adhoc: false, custom: true},
94+
{version: "v21.1.0-alpha.3-2846-g7ae3ac92f7", adhoc: false, custom: true},
95+
96+
// Valid [cloudonly] pre-release versions
97+
{version: "v23.2.0-rc.2-cloudonly-rc2", adhoc: false, custom: false},
98+
99+
// Valid production versions
100+
{version: "v19.2.6", adhoc: false, custom: false},
101+
{version: "v21.1.0", adhoc: false, custom: false},
102+
{version: "v21.1.0-247-g5668206478", adhoc: false, custom: true},
103+
104+
// Valid [cloudonly] production versions
105+
{version: "v23.1.12-cloudonly-rc2", adhoc: false, custom: false},
106+
107+
// Valid [cloudonly] v23.2.0 (production) versions may or may not have "rc" after "-cloudonly" suffix.
108+
{version: "v23.2.0-cloudonly-rc2", adhoc: false, custom: false},
109+
{version: "v23.2.0-cloudonly", adhoc: false, custom: false},
110+
{version: "v23.2.0-cloudonly.1", adhoc: false, custom: false},
111+
{version: "v23.2.0-cloudonly2", adhoc: false, custom: false},
112+
113+
// All other adhoc labels
114+
{version: "v23.2.0-arbitrary-adhoc-label", adhoc: true, custom: false},
115+
}
93116

94-
// Valid production versions
95-
require.False(t, MustParse("v19.2.6").IsCustomOrNightlyBuild())
96-
require.False(t, MustParse("v21.1.0").IsCustomOrNightlyBuild())
97-
require.True(t, MustParse("v21.1.0-247-g5668206478").IsCustomOrNightlyBuild())
117+
t.Run("IsCustomOrAdhocBuild", func(t *testing.T) {
118+
for _, tc := range builds {
119+
v := MustParse(tc.version)
120+
if tc.adhoc || tc.custom {
121+
require.True(t, v.IsCustomOrAdhocBuild())
122+
} else {
123+
require.False(t, v.IsCustomOrAdhocBuild())
124+
}
125+
}
126+
})
98127

99-
// Valid [cloudonly] production versions
100-
require.False(t, MustParse("v23.1.12-cloudonly-rc2").IsCustomOrNightlyBuild())
128+
t.Run("IsAdhocBuild", func(t *testing.T) {
129+
for _, tc := range builds {
130+
v := MustParse(tc.version)
131+
if tc.adhoc {
132+
require.True(t, v.IsAdhocBuild())
133+
} else {
134+
require.False(t, v.IsAdhocBuild())
135+
}
136+
}
137+
})
101138

102-
// Valid [cloudonly] v23.2.0 (production) versions may or may not have "rc" after "-cloudonly" suffix.
103-
require.False(t, MustParse("v23.2.0-cloudonly-rc2").IsCustomOrNightlyBuild())
104-
require.False(t, MustParse("v23.2.0-cloudonly").IsCustomOrNightlyBuild())
105-
require.False(t, MustParse("v23.2.0-cloudonly.1").IsCustomOrNightlyBuild())
106-
require.False(t, MustParse("v23.2.0-cloudonly2").IsCustomOrNightlyBuild())
139+
t.Run("IsCustomBuild", func(t *testing.T) {
140+
for _, tc := range builds {
141+
v := MustParse(tc.version)
142+
if tc.custom {
143+
require.True(t, v.IsCustomBuild())
144+
} else {
145+
require.False(t, v.IsCustomBuild())
146+
}
147+
}
148+
})
107149
}
108150

109151
func TestVersion_IsCloudOnlyBuild(t *testing.T) {
@@ -305,15 +347,15 @@ func TestParse(t *testing.T) {
305347
phaseOrdinal: 2,
306348
},
307349
},
308-
// custom releases
350+
// adhoc releases
309351
{
310352
raw: "v24.2.3-12-gabcd1234",
311353
want: Version{
312-
year: 24,
313-
ordinal: 2,
314-
patch: 3,
315-
phase: stable,
316-
nightlyOrdinal: 12,
354+
year: 24,
355+
ordinal: 2,
356+
patch: 3,
357+
phase: stable,
358+
customOrdinal: 12,
317359
},
318360
},
319361
} {
@@ -400,7 +442,7 @@ func TestVersionCompare(t *testing.T) {
400442
want: aLessThanB,
401443
},
402444

403-
// even if there's a prerelease or nightly tag
445+
// even if there's a prerelease or custom tag
404446
{
405447
a: "v20.2.7",
406448
b: "v21.1.0-alpha.3",
@@ -454,7 +496,7 @@ func TestVersionCompare(t *testing.T) {
454496
want: aLessThanB,
455497
},
456498

457-
// nightly & custom builds are greater than "regular" builds, prereleases, and cloudonly
499+
// custom & adhoc builds are greater than "regular" builds, prereleases, and cloudonly
458500
{
459501
a: "v21.1.0-alpha.3",
460502
b: "v21.1.0-1-g9cbe7c5281",
@@ -533,12 +575,12 @@ func TestVersionOrdering(t *testing.T) {
533575
want: []string{"v20.2.10", "v21.1.0-alpha.1", "v21.1.0-beta.2", "v21.1.0-rc.1", "v21.1.0-cloudonly.1", "v21.1.0"},
534576
},
535577
{
536-
name: "sorts custom builds after corresponding normal version",
578+
name: "sorts adhoc builds after corresponding normal version",
537579
input: []string{"v21.1.0-1-g9cbe7c5281", "v21.1.0", "v21.1.0-rc.1"},
538580
want: []string{"v21.1.0-rc.1", "v21.1.0", "v21.1.0-1-g9cbe7c5281"},
539581
},
540582
{
541-
name: "sorts nonstandard custom builds after corresponding normal version",
583+
name: "sorts nonstandard adhoc builds after corresponding normal version",
542584
input: []string{"v21.1.0-customLabel", "v21.1.0", "v21.1.0-rc.1"},
543585
want: []string{"v21.1.0-rc.1", "v21.1.0", "v21.1.0-customLabel"},
544586
},

0 commit comments

Comments
 (0)