Skip to content

Commit 225f2bf

Browse files
authored
Merge pull request #7895 from Extra-Chill/fix/7880-release-blocking-command-normalization
Fix release blocking command normalization
2 parents 284c73b + 4a3d65c commit 225f2bf

3 files changed

Lines changed: 84 additions & 33 deletions

File tree

.github/release-quality-policy.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
is_blocking_command() {
6+
local command="$1"
7+
local configured
8+
local canonical
9+
10+
IFS=',' read -r -a configured_commands <<< "${BLOCKING_COMMANDS}"
11+
for configured in "${configured_commands[@]}"; do
12+
canonical="$(printf '%s' "${configured}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')"
13+
canonical="${canonical#review}"
14+
if [ "${canonical}" = "${command}" ]; then
15+
return 0
16+
fi
17+
done
18+
19+
return 1
20+
}
21+
22+
failed=0
23+
24+
check_command() {
25+
local command="$1"
26+
local result="$2"
27+
28+
if is_blocking_command "${command}"; then
29+
if [ "${result}" = "success" ]; then
30+
echo "::notice::Release-blocking command ${command} passed"
31+
else
32+
echo "::error::Release-blocking command ${command} finished with result: ${result}"
33+
failed=1
34+
fi
35+
else
36+
echo "::notice::Command ${command} is tracked but not release-blocking (result: ${result})"
37+
fi
38+
}
39+
40+
check_command audit "${AUDIT_RESULT}"
41+
check_command lint "${LINT_RESULT}"
42+
check_command test "${TEST_RESULT}"
43+
44+
exit "${failed}"

.github/workflows/release.yml

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -421,35 +421,7 @@ jobs:
421421
LINT_RESULT: ${{ needs.gate-lint.result }}
422422
TEST_RESULT: ${{ needs.gate-test.result }}
423423
run: |
424-
set -euo pipefail
425-
426-
normalized="$(printf '%s' "${BLOCKING_COMMANDS}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')"
427-
blocking=",${normalized},"
428-
failed=0
429-
430-
check_command() {
431-
local command="$1"
432-
local result="$2"
433-
434-
if [[ "${blocking}" == *",${command},"* ]]; then
435-
if [ "${result}" = "success" ]; then
436-
echo "::notice::Release-blocking command ${command} passed"
437-
else
438-
echo "::error::Release-blocking command ${command} finished with result: ${result}"
439-
failed=1
440-
fi
441-
else
442-
echo "::notice::Command ${command} is tracked but not release-blocking (result: ${result})"
443-
fi
444-
}
445-
446-
check_command audit "${AUDIT_RESULT}"
447-
check_command lint "${LINT_RESULT}"
448-
check_command test "${TEST_RESULT}"
449-
450-
if [ "${failed}" -ne 0 ]; then
451-
exit 1
452-
fi
424+
bash .github/release-quality-policy.sh
453425
454426
# ── Step 4: Version bump + changelog + tag ──
455427
prepare:

tests/release_workflow_test.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@ fn release_workflow() -> &'static str {
22
include_str!("../.github/workflows/release.yml")
33
}
44

5+
fn release_quality_policy_script() -> &'static str {
6+
include_str!("../.github/release-quality-policy.sh")
7+
}
8+
9+
fn release_quality_policy(
10+
blocking_commands: &str,
11+
audit_result: &str,
12+
lint_result: &str,
13+
test_result: &str,
14+
) -> std::process::Output {
15+
std::process::Command::new("bash")
16+
.arg(".github/release-quality-policy.sh")
17+
.env("BLOCKING_COMMANDS", blocking_commands)
18+
.env("AUDIT_RESULT", audit_result)
19+
.env("LINT_RESULT", lint_result)
20+
.env("TEST_RESULT", test_result)
21+
.output()
22+
.expect("release quality policy should run")
23+
}
24+
525
fn job_section<'a>(workflow: &'a str, job: &str) -> &'a str {
626
let marker = format!(" {job}:\n");
727
let start = workflow
@@ -51,13 +71,28 @@ fn release_quality_policy_defaults_to_lint_and_test_blocking() {
5171
let policy = job_section(release_workflow(), "release-quality-policy");
5272

5373
assert!(policy.contains("BLOCKING_COMMANDS: ${{ env.RELEASE_BLOCKING_COMMANDS }}"));
74+
assert!(policy.contains("bash .github/release-quality-policy.sh"));
5475
assert!(policy.contains(
5576
"AUDIT_RESULT: ${{ needs.gate-audit.outputs.audit-result || needs.gate-audit.result }}"
5677
));
57-
assert!(policy.contains("check_command audit"));
58-
assert!(policy.contains("check_command lint"));
59-
assert!(policy.contains("check_command test"));
60-
assert!(policy.contains("Command ${command} is tracked but not release-blocking"));
78+
assert!(release_quality_policy_script().contains("check_command audit"));
79+
assert!(release_quality_policy_script().contains("check_command lint"));
80+
assert!(release_quality_policy_script().contains("check_command test"));
81+
assert!(release_quality_policy_script()
82+
.contains("Command ${command} is tracked but not release-blocking"));
83+
}
84+
85+
#[test]
86+
fn release_quality_policy_blocks_review_test_failures_and_allows_passing_gates() {
87+
let failed = release_quality_policy("review lint,review test", "failure", "success", "failure");
88+
89+
assert!(!failed.status.success());
90+
assert!(String::from_utf8_lossy(&failed.stdout)
91+
.contains("Release-blocking command test finished with result: failure"));
92+
93+
let passed = release_quality_policy("review lint,review test", "failure", "success", "success");
94+
95+
assert!(passed.status.success());
6196
}
6297

6398
#[test]

0 commit comments

Comments
 (0)