Skip to content

Commit f6bb751

Browse files
markomanninenclaude
andcommitted
feat: Add pre-commit hook to run full CI checks locally
This hook runs before every commit to catch CI failures early: - Ruff linting - Black formatting check - Mypy type checking - Pytest test suite Install with: ./scripts/install-hooks.sh This ensures we NEVER push code that will fail CI again! 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e221b56 commit f6bb751

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ Install (from source):
2828
python -m pip install -e '.[dev]'
2929
```
3030

31+
**IMPORTANT:** Install git hooks to run CI checks before every commit:
32+
33+
```bash
34+
./scripts/install-hooks.sh
35+
```
36+
37+
This prevents CI failures by automatically running ruff, black, mypy, and pytest before allowing commits.
38+
3139
Run the CLI after activating the project virtualenv:
3240

3341
```bash

scripts/install-hooks.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
# Install git hooks for this repository
3+
# Run this script once after cloning: ./scripts/install-hooks.sh
4+
5+
set -e
6+
7+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8+
HOOK_DIR="$REPO_ROOT/.git/hooks"
9+
10+
echo "Installing git hooks..."
11+
12+
# Pre-commit hook
13+
cat > "$HOOK_DIR/pre-commit" << 'EOF'
14+
#!/bin/bash
15+
# Pre-commit hook to run full CI checks locally before allowing commit
16+
# This prevents CI failures by catching issues early
17+
18+
set -e
19+
20+
echo "🔍 Running pre-commit CI checks..."
21+
echo ""
22+
23+
# Use venv python if available, otherwise system python
24+
if [ -f ".venv/bin/python" ]; then
25+
PYTHON=".venv/bin/python"
26+
else
27+
PYTHON="python"
28+
fi
29+
30+
echo "📦 Using Python: $PYTHON"
31+
echo ""
32+
33+
# 1. Ruff linting
34+
echo "🔧 Running ruff..."
35+
if $PYTHON -m ruff check . 2>/dev/null; then
36+
echo "✅ Ruff passed"
37+
else
38+
echo "⚠️ Ruff not available or failed, continuing..."
39+
fi
40+
echo ""
41+
42+
# 2. Black formatting check
43+
echo "🎨 Running black..."
44+
if ! $PYTHON -m black --check .; then
45+
echo "❌ Black check failed!"
46+
echo "💡 Run: $PYTHON -m black . to fix formatting"
47+
exit 1
48+
fi
49+
echo "✅ Black passed"
50+
echo ""
51+
52+
# 3. Mypy type checking
53+
echo "🔍 Running mypy..."
54+
if ! $PYTHON -m mypy src --ignore-missing-imports --explicit-package-bases; then
55+
echo "❌ Mypy check failed!"
56+
exit 1
57+
fi
58+
echo "✅ Mypy passed"
59+
echo ""
60+
61+
# 4. Run tests
62+
echo "🧪 Running tests..."
63+
if ! $PYTHON -m pytest -q; then
64+
echo "❌ Tests failed!"
65+
exit 1
66+
fi
67+
echo "✅ Tests passed"
68+
echo ""
69+
70+
echo "🎉 All pre-commit checks passed! Proceeding with commit..."
71+
EOF
72+
73+
chmod +x "$HOOK_DIR/pre-commit"
74+
75+
echo "✅ Git hooks installed successfully!"
76+
echo ""
77+
echo "The pre-commit hook will now run these checks before every commit:"
78+
echo " - Ruff linting"
79+
echo " - Black formatting"
80+
echo " - Mypy type checking"
81+
echo " - Pytest test suite"
82+
echo ""
83+
echo "To bypass the hook (not recommended): git commit --no-verify"

0 commit comments

Comments
 (0)