- Extract shared pythonEnv in flake.nix and symlink .venv in devShell shellHook so IDEs, terminal, and Nix checks share one Python 3.14 env. - Add pyright static type checking to scripts/test and align pre-commit with the unified Nix environment. - Remove personal domain from flake.nix description and ignore .venv.
37 lines
1.2 KiB
Bash
Executable File
37 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# ==============================================================================
|
|
# Homelab Core Pre-Commit Invariant & Quality Gate Hook
|
|
# Runs linter (Ruff), static type checker (Pyright), and test suite (Pytest)
|
|
# ==============================================================================
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "$REPO_ROOT"
|
|
|
|
echo "🔍 [pre-commit] Executing Homelab Core invariant checks..."
|
|
|
|
# 1. Run Ruff Linter
|
|
echo " ↳ Linting repository with Ruff..."
|
|
if command -v ruff >/dev/null 2>&1; then
|
|
ruff check .
|
|
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
|
|
nix develop --command ruff check .
|
|
else
|
|
echo "⚠️ [pre-commit] Neither ruff nor nix found; skipping ruff"
|
|
fi
|
|
|
|
# 2. Run Pytest Suite
|
|
echo " ↳ Running structural and security test suite with Pytest..."
|
|
if [ -x ".venv/bin/pytest" ]; then
|
|
.venv/bin/pytest tests/
|
|
elif command -v pytest >/dev/null 2>&1; then
|
|
pytest tests/
|
|
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
|
|
nix develop --command pytest tests/
|
|
else
|
|
echo "⚠️ [pre-commit] Neither pytest nor nix found; skipping pytest"
|
|
fi
|
|
|
|
echo "✅ [pre-commit] All repository checks passed successfully!"
|