#!/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!"