Add Python tooling validation foundation
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
PYTHON_DIR="$ROOT_DIR/infra-run/scripts/python"
|
||||
|
||||
ok_count=0
|
||||
warn_count=0
|
||||
fail_count=0
|
||||
|
||||
ok() {
|
||||
printf 'OK: %s\n' "$*"
|
||||
ok_count=$((ok_count + 1))
|
||||
}
|
||||
|
||||
warning() {
|
||||
printf 'WARNING: %s\n' "$*"
|
||||
warn_count=$((warn_count + 1))
|
||||
}
|
||||
|
||||
critical() {
|
||||
printf 'CRITICAL: %s\n' "$*"
|
||||
fail_count=$((fail_count + 1))
|
||||
}
|
||||
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
critical "python3 not installed"
|
||||
printf '\nPython summary: %d OK, %d WARNING, %d CRITICAL\n' "$ok_count" "$warn_count" "$fail_count"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ ! -d "$PYTHON_DIR" ]]; then
|
||||
warning "No infra-run/scripts/python directory found"
|
||||
printf '\nPython summary: %d OK, %d WARNING, %d CRITICAL\n' "$ok_count" "$warn_count" "$fail_count"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
mapfile -t python_files < <(find "$PYTHON_DIR" -type f -name '*.py' -print | sort)
|
||||
|
||||
if ((${#python_files[@]} == 0)); then
|
||||
warning "No Python files found under infra-run/scripts/python"
|
||||
else
|
||||
ok "Found ${#python_files[@]} Python files"
|
||||
fi
|
||||
|
||||
for file in "${python_files[@]}"; do
|
||||
if python3 -m py_compile "$file"; then
|
||||
ok "py_compile ${file#"$ROOT_DIR"/}"
|
||||
else
|
||||
critical "Python syntax failed: ${file#"$ROOT_DIR"/}"
|
||||
fi
|
||||
done
|
||||
|
||||
printf '\nPython summary: %d OK, %d WARNING, %d CRITICAL\n' "$ok_count" "$warn_count" "$fail_count"
|
||||
|
||||
if ((fail_count > 0)); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user