Skip to content

Commit d94c949

Browse files
committed
fix(ci): improve run-all-check resilience
1 parent e2ca895 commit d94c949

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

scripts/ci/infrastructure/health-check.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ log_info "Checking database connectivity..."
5353
cd "$PROJECT_ROOT/api/callcentersite"
5454

5555
if [ -f "manage.py" ]; then
56-
if python3 manage.py check --database default &> /dev/null; then
56+
if DB_CHECK_OUTPUT=$(python3 manage.py check --database default 2>&1); then
5757
log_info "Database connectivity: OK"
5858
CHECKS_PASSED=$((CHECKS_PASSED + 1))
5959
else
6060
log_error "Database connectivity failed"
61+
echo "$DB_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do
62+
log_error " $line"
63+
done
6164
CHECKS_FAILED=$((CHECKS_FAILED + 1))
6265
fi
6366
else
@@ -67,11 +70,14 @@ fi
6770

6871
# Check 4: Django configuration
6972
log_info "Checking Django configuration..."
70-
if python3 manage.py check &> /dev/null; then
73+
if DJANGO_CHECK_OUTPUT=$(python3 manage.py check 2>&1); then
7174
log_info "Django configuration: OK"
7275
CHECKS_PASSED=$((CHECKS_PASSED + 1))
7376
else
7477
log_error "Django configuration check failed"
78+
echo "$DJANGO_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do
79+
log_error " $line"
80+
done
7581
CHECKS_FAILED=$((CHECKS_FAILED + 1))
7682
fi
7783

scripts/ci/run-all-checks.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# 0 - All checks passed
1212
# 1 - One or more checks failed
1313

14-
set -e
14+
set -u
15+
set -o pipefail
1516

1617
RED='\033[0;31m'
1718
GREEN='\033[0;32m'
@@ -77,13 +78,30 @@ run_check() {
7778

7879
chmod +x "$check_script"
7980

81+
local exit_code
82+
local output=""
83+
local previous_errexit=0
84+
85+
if [[ $- == *e* ]]; then
86+
previous_errexit=1
87+
set +e
88+
fi
89+
8090
if [ "$VERBOSE" = true ]; then
8191
"$check_script"
92+
exit_code=$?
8293
else
83-
"$check_script" > /dev/null 2>&1
94+
output=$("$check_script" 2>&1)
95+
exit_code=$?
8496
fi
8597

86-
local exit_code=$?
98+
if [ $previous_errexit -eq 1 ]; then
99+
set -e
100+
fi
101+
102+
if [ "$VERBOSE" != true ] && [ $exit_code -ne 0 ] && [ -n "$output" ]; then
103+
echo "$output"
104+
fi
87105

88106
if [ $exit_code -eq 0 ]; then
89107
log_info "$check_name: PASS"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
from pathlib import Path
3+
4+
REPO_ROOT = Path(__file__).resolve().parents[2]
5+
RUN_ALL_CHECKS = REPO_ROOT / "scripts" / "ci" / "run-all-checks.sh"
6+
HEALTH_CHECK = REPO_ROOT / "scripts" / "ci" / "infrastructure" / "health-check.sh"
7+
8+
9+
def _run_script(script_path, *args):
10+
return subprocess.run(
11+
["bash", str(script_path), *args],
12+
cwd=REPO_ROOT,
13+
stdout=subprocess.PIPE,
14+
stderr=subprocess.PIPE,
15+
text=True,
16+
)
17+
18+
19+
def test_run_all_checks_reports_summary_even_on_failure():
20+
result = _run_script(RUN_ALL_CHECKS)
21+
22+
assert result.returncode != 0, "Expected the aggregated checks to fail in the default dev environment"
23+
combined_output = f"{result.stdout}\\n{result.stderr}"
24+
assert "FINAL CI/CD REPORT" in combined_output
25+
26+
27+
def test_health_check_surfaces_underlying_error_details():
28+
result = _run_script(HEALTH_CHECK)
29+
30+
assert result.returncode != 0, "The health check should fail when dependencies are missing"
31+
combined_output = f"{result.stdout}\\n{result.stderr}"
32+
assert "ModuleNotFoundError" in combined_output or "No module named" in combined_output

0 commit comments

Comments
 (0)