Files
nixos-core/.githooks/pre-commit
kiskaadee 8cc06e2470
Core Architecture & Invariant CI / validate (pull_request) Failing after 1m16s
chore(core): scrub personal domain/username literals and enforce pyright in flake checks
2026-10-19 13:59:18 -05:00

47 lines
1.5 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 Pyright Type Checker
echo " ↳ Checking static types with Pyright..."
if command -v pyright >/dev/null 2>&1; then
pyright
elif command -v nix >/dev/null 2>&1 && [ -f flake.nix ]; then
nix develop --command pyright
else
echo "⚠️ [pre-commit] Neither pyright nor nix found; skipping pyright"
fi
# 3. 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!"