Skip to content

Commit 767b761

Browse files
authored
batches: match on abbreviated commit hash in version (#678)
1 parent cfcc3fb commit 767b761

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

internal/api/version_check.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ func CheckSourcegraphVersion(version, constraint, minDate string) (bool, error)
2222
return true, nil
2323
}
2424

25-
buildDate := regexp.MustCompile(`^\d+_(\d{4}-\d{2}-\d{2})_[a-z0-9]{7}$`)
25+
// Since we don't actually care about the abbreviated commit hash at the end of the
26+
// version string, we match on 7 or more characters. Currently, the Sourcegraph version
27+
// is expected to return 12:
28+
// https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/enterprise/dev/ci/internal/ci/config.go?L96.
29+
buildDate := regexp.MustCompile(`^\d+_(\d{4}-\d{2}-\d{2})_[a-z0-9]{7,}$`)
2630
matches := buildDate.FindStringSubmatch(version)
2731
if len(matches) > 1 {
2832
return matches[1] >= minDate, nil

internal/api/version_check_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ func TestCheckSourcegraphVersion(t *testing.T) {
1919
minDate: "2020-01-19",
2020
expected: true,
2121
},
22+
{
23+
currentVersion: "3.12.6-rc.3",
24+
constraint: ">= 3.10.6-0",
25+
minDate: "2020-01-19",
26+
expected: true,
27+
},
2228
{
2329
currentVersion: "3.12.6",
2430
constraint: ">= 3.13",
@@ -43,6 +49,7 @@ func TestCheckSourcegraphVersion(t *testing.T) {
4349
minDate: "2020-01-19",
4450
expected: true,
4551
},
52+
// 7-character abbreviated hash
4653
{
4754
currentVersion: "54959_2020-01-29_9258595",
4855
minDate: "2020-01-19",
@@ -61,6 +68,32 @@ func TestCheckSourcegraphVersion(t *testing.T) {
6168
constraint: ">= 0.0",
6269
expected: true,
6370
},
71+
// 12-character abbreviated hash
72+
{
73+
currentVersion: "54959_2020-01-29_925859585436",
74+
minDate: "2020-01-19",
75+
constraint: ">= 999.13",
76+
expected: true,
77+
},
78+
{
79+
currentVersion: "54959_2020-01-29_925859585436",
80+
minDate: "2020-01-30",
81+
constraint: ">= 999.13",
82+
expected: false,
83+
},
84+
{
85+
currentVersion: "54959_2020-01-29_925859585436",
86+
minDate: "2020-01-29",
87+
constraint: ">= 0.0",
88+
expected: true,
89+
},
90+
// Full 40-character hash, just for fun
91+
{
92+
currentVersion: "54959_2020-01-29_7db7d396346284fd0f8f79f130f38b16fb1d3d70",
93+
minDate: "2020-01-29",
94+
constraint: ">= 0.0",
95+
expected: true,
96+
},
6497
} {
6598
actual, err := CheckSourcegraphVersion(tc.currentVersion, tc.constraint, tc.minDate)
6699
if err != nil {

0 commit comments

Comments
 (0)