Add Python tooling validation foundation
This commit is contained in:
@@ -28,6 +28,9 @@ jobs:
|
|||||||
-P infra-run/scripts/bash/gpfs \
|
-P infra-run/scripts/bash/gpfs \
|
||||||
-P infra-run/scripts/bash/veritas
|
-P infra-run/scripts/bash/veritas
|
||||||
|
|
||||||
|
- name: Python syntax checks
|
||||||
|
run: bash scripts/check-python.sh
|
||||||
|
|
||||||
- name: yamllint
|
- name: yamllint
|
||||||
run: yamllint .
|
run: yamllint .
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ Focused checks:
|
|||||||
```bash
|
```bash
|
||||||
./scripts/check-bash.sh
|
./scripts/check-bash.sh
|
||||||
./scripts/check-ansible.sh
|
./scripts/check-ansible.sh
|
||||||
|
./scripts/check-python.sh
|
||||||
./scripts/check-docs.sh
|
./scripts/check-docs.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -64,6 +65,15 @@ Also run targeted checks for changed files, such as `bash -n`, `ansible-playbook
|
|||||||
- Exit codes: `0` OK, `1` operational issue, `2` invalid input or missing dependency.
|
- Exit codes: `0` OK, `1` operational issue, `2` invalid input or missing dependency.
|
||||||
- Keep scripts readable; separate discovery, pre-check, change, post-check, and reporting when it helps.
|
- Keep scripts readable; separate discovery, pre-check, change, post-check, and reporting when it helps.
|
||||||
|
|
||||||
|
## Python Standards
|
||||||
|
|
||||||
|
- Use Python for parsing, reporting, and structured operational tooling where it adds value over Bash.
|
||||||
|
- Keep Python tools read-only by default.
|
||||||
|
- Prefer the Python standard library.
|
||||||
|
- Avoid frameworks and unnecessary abstractions.
|
||||||
|
- Use clear operational output and meaningful exit codes.
|
||||||
|
- Keep tools small, focused, and easy to validate.
|
||||||
|
|
||||||
## Ansible Standards
|
## Ansible Standards
|
||||||
|
|
||||||
- Keep playbooks short and roles simple.
|
- Keep playbooks short and roles simple.
|
||||||
|
|||||||
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
|
||||||
@@ -12,6 +12,11 @@ run_check() {
|
|||||||
shift
|
shift
|
||||||
|
|
||||||
printf '\n== %s ==\n' "$name"
|
printf '\n== %s ==\n' "$name"
|
||||||
|
if [[ ! -x "$1" ]]; then
|
||||||
|
printf 'WARNING: %s check is missing or not executable: %s\n' "$name" "$1"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
if "$@"; then
|
if "$@"; then
|
||||||
printf 'OK: %s completed\n' "$name"
|
printf 'OK: %s completed\n' "$name"
|
||||||
else
|
else
|
||||||
@@ -22,6 +27,7 @@ run_check() {
|
|||||||
|
|
||||||
run_check "Bash" "$ROOT_DIR/scripts/check-bash.sh"
|
run_check "Bash" "$ROOT_DIR/scripts/check-bash.sh"
|
||||||
run_check "Ansible" "$ROOT_DIR/scripts/check-ansible.sh"
|
run_check "Ansible" "$ROOT_DIR/scripts/check-ansible.sh"
|
||||||
|
run_check "Python" "$ROOT_DIR/scripts/check-python.sh"
|
||||||
run_check "Docs" "$ROOT_DIR/scripts/check-docs.sh"
|
run_check "Docs" "$ROOT_DIR/scripts/check-docs.sh"
|
||||||
|
|
||||||
printf '\n== Repository summary ==\n'
|
printf '\n== Repository summary ==\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user