Skip to content

Commit f18220a

Browse files
committed
ci: validate release channel version sequences
1 parent fd73380 commit f18220a

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
release_type="${RELEASE_TYPE:-standard}"
6+
current_version="${CURRENT_VERSION:-}"
7+
version_prefix="${VERSION_PREFIX:-}"
8+
release_channel_name="${RELEASE_CHANNEL_NAME:-Selected}"
9+
10+
write_output() {
11+
local key="$1"
12+
local value="$2"
13+
14+
echo "${key}=${value}"
15+
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
16+
echo "${key}=${value}" >> "${GITHUB_OUTPUT}"
17+
fi
18+
}
19+
20+
case "${release_type}" in
21+
standard)
22+
if [[ ! "${current_version}" =~ ^[0-9]+([.][0-9]+)*$ ]]; then
23+
echo "${release_channel_name} channel returned an invalid currentVersion: ${current_version:-<empty>}" >&2
24+
exit 1
25+
fi
26+
new_version="$(awk -F. '{$NF = $NF + 1} 1' OFS=. <<<"${current_version}")"
27+
;;
28+
glean)
29+
if [[ -z "${version_prefix}" ]]; then
30+
echo "VERSION_PREFIX is required." >&2
31+
exit 1
32+
fi
33+
34+
if [[ -z "${current_version}" ]]; then
35+
new_version="${version_prefix}.1"
36+
else
37+
version_prefix_pattern="${version_prefix//./\\.}"
38+
if [[ ! "${current_version}" =~ ^${version_prefix_pattern}\.([0-9]+)$ ]]; then
39+
echo "${release_channel_name} currentVersion must match ${version_prefix}.x: ${current_version}" >&2
40+
exit 1
41+
fi
42+
new_version="${version_prefix}.$((10#${BASH_REMATCH[1]} + 1))"
43+
fi
44+
;;
45+
*)
46+
echo "Unsupported release type: ${release_type}" >&2
47+
exit 1
48+
;;
49+
esac
50+
51+
write_output current "${current_version}"
52+
write_output new "${new_version}"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
6+
SCRIPT="${SCRIPT_DIR}/calculate-release-version.sh"
7+
8+
fail() {
9+
echo "FAIL: $*" >&2
10+
exit 1
11+
}
12+
13+
assert_output() {
14+
local file="$1"
15+
local key="$2"
16+
local expected="$3"
17+
local actual
18+
19+
actual="$(awk -F= -v key="${key}" '$1 == key { print substr($0, index($0, "=") + 1) }' "${file}" | tail -n1)"
20+
[[ "${actual}" == "${expected}" ]] \
21+
|| fail "${key}: expected ${expected:-<empty>}, got ${actual:-<empty>}"
22+
}
23+
24+
assert_version() {
25+
local name="$1"
26+
local release_type="$2"
27+
local current_version="$3"
28+
local version_prefix="$4"
29+
local expected_current="$5"
30+
local expected_new="$6"
31+
local tmp_dir output_file channel_name
32+
33+
tmp_dir="$(mktemp -d)"
34+
output_file="${tmp_dir}/github-output"
35+
channel_name="Nightly"
36+
if [[ "${release_type}" == "glean" ]]; then
37+
channel_name="Glean-Stable"
38+
fi
39+
40+
RELEASE_TYPE="${release_type}" \
41+
RELEASE_CHANNEL_NAME="${channel_name}" \
42+
CURRENT_VERSION="${current_version}" \
43+
VERSION_PREFIX="${version_prefix}" \
44+
GITHUB_OUTPUT="${output_file}" \
45+
bash "${SCRIPT}" >"${tmp_dir}/stdout" 2>"${tmp_dir}/stderr" \
46+
|| fail "${name}: script exited non-zero"
47+
48+
assert_output "${output_file}" current "${expected_current}"
49+
assert_output "${output_file}" new "${expected_new}"
50+
rm -rf "${tmp_dir}"
51+
}
52+
53+
assert_version_fails() {
54+
local name="$1"
55+
local release_type="$2"
56+
local current_version="$3"
57+
local version_prefix="$4"
58+
local expected_error="$5"
59+
local tmp_dir channel_name
60+
61+
tmp_dir="$(mktemp -d)"
62+
channel_name="Nightly"
63+
if [[ "${release_type}" == "glean" ]]; then
64+
channel_name="Glean-Stable"
65+
fi
66+
67+
if RELEASE_TYPE="${release_type}" \
68+
RELEASE_CHANNEL_NAME="${channel_name}" \
69+
CURRENT_VERSION="${current_version}" \
70+
VERSION_PREFIX="${version_prefix}" \
71+
bash "${SCRIPT}" >"${tmp_dir}/stdout" 2>"${tmp_dir}/stderr"; then
72+
fail "${name}: script unexpectedly succeeded"
73+
fi
74+
75+
grep -Fq "${expected_error}" "${tmp_dir}/stderr" \
76+
|| fail "${name}: expected error was not emitted"
77+
rm -rf "${tmp_dir}"
78+
}
79+
80+
assert_version "increments standard version" \
81+
standard "0.2.140" "" "0.2.140" "0.2.141"
82+
assert_version "bootstraps empty Glean version" \
83+
glean "" "0.2.87" "" "0.2.87.1"
84+
assert_version "increments existing Glean version" \
85+
glean "0.2.87.1" "0.2.87" "0.2.87.1" "0.2.87.2"
86+
assert_version "increments a multi-digit Glean sequence" \
87+
glean "0.2.87.19" "0.2.87" "0.2.87.19" "0.2.87.20"
88+
89+
assert_version_fails "rejects empty standard version" \
90+
standard "" "" "Nightly channel returned an invalid currentVersion: <empty>"
91+
assert_version_fails "rejects a different Glean family" \
92+
glean "0.2.88.1" "0.2.87" "Glean-Stable currentVersion must match 0.2.87.x: 0.2.88.1"
93+
assert_version_fails "requires the Glean version prefix" \
94+
glean "" "" "VERSION_PREFIX is required."
95+
96+
echo "calculate-release-version tests passed"

0 commit comments

Comments
 (0)