Files
prowler/scripts/setup-git-hooks.sh
alejandrobailo d46f649ff1 feat: migrate from pre-commit to prek
Replace pre-commit with prek, a faster Rust-based alternative that is
7x faster for installation and 6x faster for execution while being
fully compatible with .pre-commit-config.yaml.

Changes:
- Remove pre-commit from pyproject.toml dev dependencies
- Update scripts/setup-git-hooks.sh to use prek
- Update developer documentation (introduction.mdx)
- Update security documentation (software-security.mdx)
- Update AGENTS.md files with new commands
- Regenerate poetry.lock

prek is installed as a standalone tool via:
- pipx install prek (recommended)
- brew install prek
- uv tool install prek

Benchmarks on Prowler codebase:
- Cold install: 25.18s → 3.42s (7.37x faster)
- Warm execution: 87.53s → 14.80s (5.92x faster)
- Cache size: 170MB → 154MB (9.4% smaller)
2026-01-26 18:41:05 +01:00

79 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Setup Git Hooks for Prowler
# This script installs git hooks using prek (fast pre-commit alternative)
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🔧 Setting up Prowler Git Hooks"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Check if we're in a git repository
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo -e "${RED}❌ Not in a git repository${NC}"
exit 1
fi
# Check if pyproject.toml exists
if [ ! -f "pyproject.toml" ]; then
echo -e "${RED}❌ pyproject.toml not found${NC}"
echo -e "${YELLOW} Please run this script from the repository root${NC}"
exit 1
fi
# Check if prek is installed, if not try to install it
if ! command -v prek &>/dev/null; then
echo -e "${YELLOW}📦 prek not found, attempting to install...${NC}"
if command -v pipx &>/dev/null; then
pipx install prek
elif command -v uv &>/dev/null; then
uv tool install prek
elif command -v brew &>/dev/null; then
brew install prek
else
echo -e "${RED}❌ Could not install prek automatically${NC}"
echo -e "${YELLOW} Install prek manually: https://github.com/j178/prek${NC}"
echo -e "${YELLOW} Options: pipx install prek | brew install prek | uv tool install prek${NC}"
exit 1
fi
fi
echo -e "${GREEN}${NC} prek is installed: $(prek --version)"
echo ""
# Clear any existing core.hooksPath to avoid conflicts
if git config --get core.hooksPath >/dev/null 2>&1; then
echo -e "${YELLOW}🧹 Clearing existing core.hooksPath configuration...${NC}"
git config --unset-all core.hooksPath
fi
# Uninstall old pre-commit hooks if they exist
if [ -f ".git/hooks/pre-commit" ] && grep -q "pre-commit" ".git/hooks/pre-commit" 2>/dev/null; then
echo -e "${YELLOW}🧹 Removing old pre-commit hooks...${NC}"
pre-commit uninstall 2>/dev/null || true
fi
echo -e "${YELLOW}🔗 Installing prek hooks...${NC}"
prek install
echo ""
echo -e "${GREEN}✅ Git hooks successfully configured!${NC}"
echo ""
echo -e "${YELLOW}📋 prek system (fast pre-commit alternative):${NC}"
echo -e " • prek manages all git hooks (~7x faster than pre-commit)"
echo -e " • API files: Python checks (black, flake8, bandit, etc.)"
echo -e " • UI files: UI checks (TypeScript, ESLint, Claude Code validation)"
echo -e " • Run manually: prek run --all-files"
echo ""
echo -e "${GREEN}🎉 Setup complete!${NC}"
echo ""