Files
webref/scripts/install-hooks.sh
Danilo Reyes 37b25689ff chore: disable coverage requirement and update pre-push hook template
- Commented out the coverage failure threshold in `pyproject.toml` until tests are written.
- Updated `install-hooks.sh` to create a pre-push hook template that is disabled by default, with instructions for enabling it when tests are ready.
2025-11-02 00:12:27 -06:00

108 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Install git hooks for the project
set -e
HOOKS_DIR=".git/hooks"
SCRIPTS_DIR="scripts"
echo "Installing git hooks..."
echo ""
# Create hooks directory if it doesn't exist
mkdir -p "$HOOKS_DIR"
# Pre-commit hook
cat > "$HOOKS_DIR/pre-commit" << 'EOF'
#!/usr/bin/env bash
# Git pre-commit hook - runs linting before commit
echo "🔍 Running pre-commit linting..."
echo ""
# Try to use nix run if available, otherwise use script directly
if command -v nix &> /dev/null && [ -f "flake.nix" ]; then
# Use nix run for consistent environment
if ! nix run .#lint; then
echo ""
echo "❌ Linting failed. Fix errors or use --no-verify to skip."
echo " Auto-fix: nix run .#lint-fix"
exit 1
fi
else
# Fallback to script
if ! ./scripts/lint.sh; then
echo ""
echo "❌ Linting failed. Fix errors or use --no-verify to skip."
echo " Auto-fix: ./scripts/lint.sh --fix"
exit 1
fi
fi
echo ""
echo "✅ Pre-commit checks passed!"
EOF
chmod +x "$HOOKS_DIR/pre-commit"
echo "✓ Installed pre-commit hook"
# Pre-push hook (DISABLED by default - enable when tests are ready)
cat > "$HOOKS_DIR/pre-push.disabled" << 'EOF'
#!/usr/bin/env bash
# Git pre-push hook - runs tests before push
#
# TO ENABLE: Rename this file to 'pre-push' (remove .disabled)
# TO DISABLE: Rename back to 'pre-push.disabled'
# OR use: git push --no-verify
echo "🧪 Running tests before push..."
echo ""
# Backend tests (if pytest is available)
if [ -d "backend" ] && command -v pytest &> /dev/null; then
cd backend
# Run tests without coverage requirement for pre-push
if ! pytest -xvs --tb=short --no-cov; then
echo ""
echo "❌ Backend tests failed. Fix tests or use --no-verify to skip."
exit 1
fi
cd ..
fi
# Frontend tests (if npm test is available)
if [ -d "frontend/node_modules" ]; then
cd frontend
if ! npm test -- --run; then
echo ""
echo "❌ Frontend tests failed. Fix tests or use --no-verify to skip."
exit 1
fi
cd ..
fi
echo ""
echo "✅ All tests passed!"
EOF
chmod +x "$HOOKS_DIR/pre-push.disabled"
echo "✓ Created pre-push hook template (disabled by default)"
echo " To enable: mv .git/hooks/pre-push.disabled .git/hooks/pre-push"
echo ""
echo "========================================="
echo "✅ Git hooks installed successfully!"
echo "========================================="
echo ""
echo "Hooks installed:"
echo " • pre-commit - Runs linting before commit"
echo " • pre-push - Runs tests before push (optional)"
echo ""
echo "To skip hooks when committing:"
echo " git commit --no-verify"
echo ""
echo "To uninstall:"
echo " rm .git/hooks/pre-commit .git/hooks/pre-push"
echo ""