Files
wordpress/tests/test_compose_config.sh
stevensting 5d891c88c7
continuous-integration/drone/push Build is failing
Revert "Fix lint issues and improve test suite resilience"
This reverts commit 90d44bd3bc.
2026-07-21 16:09:11 +02:00

51 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
ROOT="$(dirname "$(realpath "$0")")/.."
pass=0
fail=0
# Detect available Docker Compose command
compose_cmd=""
if command -v docker &>/dev/null && docker compose version &>/dev/null 2>&1; then
compose_cmd="docker compose"
elif command -v docker-compose &>/dev/null; then
compose_cmd="docker-compose"
fi
# Validate a compose file against the Docker Compose specification
test_compose_config() {
local file=$1
# Skip if Docker Compose is not available on this system
if [ -z "$compose_cmd" ]; then
echo " SKIP $file (no docker compose available)"
return
fi
# config -q exits with non-zero if the compose file is invalid
if $compose_cmd -f "$file" config -q 2>/dev/null; then
echo " PASS $file"
pass=$((pass + 1))
else
echo " FAIL $file"
fail=$((fail + 1))
fi
}
echo "=== Docker Compose Config Validation ==="
# Validate main compose file first, then all override files
test_compose_config "$ROOT/compose.yml"
while IFS= read -r f; do
# Skip the main compose file (already tested above)
[ "$f" = "$ROOT/compose.yml" ] && continue
[ -f "$f" ] && test_compose_config "$f"
done < <(find "$ROOT" -maxdepth 1 -name 'compose*.yml' | sort)
echo "---"
echo "Passed: $pass Failed: $fail"
# Exit with failure if any compose file failed validation
[ "$fail" -eq 0 ]