Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions scripts/ci/infrastructure/health-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,7 @@ fi
log_info "Checking database connectivity..."
cd "$PROJECT_ROOT/api/callcentersite"

DJANGO_READY=true
if ! python3 -c "import django" >/dev/null 2>&1; then
DJANGO_READY=false
log_warn "Skipping Django checks: Django is not installed in the current environment"
CHECKS_SKIPPED=$((CHECKS_SKIPPED + 1))
elif [ ! -f "manage.py" ]; then
DJANGO_READY=false
log_warn "Skipping Django checks: manage.py not found"
CHECKS_SKIPPED=$((CHECKS_SKIPPED + 1))
fi

if [ "$DJANGO_READY" = true ]; then
if [ -f "manage.py" ]; then
if DB_CHECK_OUTPUT=$(python3 manage.py check --database default 2>&1); then
log_info "Database connectivity: OK"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
Expand All @@ -76,19 +65,17 @@ if [ "$DJANGO_READY" = true ]; then
CHECKS_FAILED=$((CHECKS_FAILED + 1))
fi

log_info "Checking Django configuration..."
if DJANGO_CHECK_OUTPUT=$(python3 manage.py check 2>&1); then
log_info "Django configuration: OK"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
else
log_error "Django configuration check failed"
echo "$DJANGO_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do
log_error " $line"
done
CHECKS_FAILED=$((CHECKS_FAILED + 1))
fi
# Check 4: Django configuration
log_info "Checking Django configuration..."
if DJANGO_CHECK_OUTPUT=$(python3 manage.py check 2>&1); then
log_info "Django configuration: OK"
CHECKS_PASSED=$((CHECKS_PASSED + 1))
else
log_warn "Skipping Django checks due to missing prerequisites"
log_error "Django configuration check failed"
echo "$DJANGO_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do
log_error " $line"
done
CHECKS_FAILED=$((CHECKS_FAILED + 1))
fi

# Check 5: Required directories exist
Expand Down
3 changes: 2 additions & 1 deletion scripts/ci/run-all-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# 0 - All checks passed
# 1 - One or more checks failed

set -euo pipefail
set -u
set -o pipefail

RED='\033[0;31m'
GREEN='\033[0;32m'
Expand Down
18 changes: 5 additions & 13 deletions scripts/tests/test_ci_shell_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,17 @@ def _run_script(script_path, *args):
)


def test_run_all_checks_reports_summary_with_skips():
def test_run_all_checks_reports_summary_even_on_failure():
result = _run_script(RUN_ALL_CHECKS)

assert result.returncode == 0, "Aggregated checks should degrade to success with skips locally"
assert result.returncode != 0, "Expected the aggregated checks to fail in the default dev environment"
combined_output = f"{result.stdout}\\n{result.stderr}"
assert "FINAL CI/CD REPORT" in combined_output
assert "Skipped:" in combined_output
assert "[SKIP]" in combined_output or "Skipped: 0" in combined_output


def test_health_check_degrades_gracefully_when_django_missing():
def test_health_check_surfaces_underlying_error_details():
result = _run_script(HEALTH_CHECK)

assert result.returncode in (0, 2), "Health check should pass or skip when Django is unavailable"
assert result.returncode != 0, "The health check should fail when dependencies are missing"
combined_output = f"{result.stdout}\\n{result.stderr}"
assert "Skipping Django checks" in combined_output


def test_run_all_checks_sets_strict_shell_flags():
contents = RUN_ALL_CHECKS.read_text()

assert "set -euo pipefail" in contents, "run-all-checks.sh must opt into strict shell error handling"
assert "ModuleNotFoundError" in combined_output or "No module named" in combined_output
Loading