⚡ Optimize Pre-Push Hook for Speed
✅ Optimized Pre-Push Hook: - Quick checks only: ESLint, TypeScript, npm audit - Removed slow tests and build (run in GitHub Actions) - ~3x faster for small fixes ✅ Added Full Pre-Push Option: - npm run pre-push:full for complete checks - Use for important changes or releases - Includes tests and build locally 🎯 Best Practices: - Quick checks locally (30 seconds) - Full validation in GitHub Actions - Best of both worlds: speed + thoroughness 📝 Usage: - Normal pushes: npm run pre-push (fast) - Important changes: npm run pre-push:full (thorough)
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"lint:fix": "eslint . --fix",
|
"lint:fix": "eslint . --fix",
|
||||||
"pre-push": "./scripts/pre-push.sh",
|
"pre-push": "./scripts/pre-push.sh",
|
||||||
|
"pre-push:full": "./scripts/pre-push-full.sh",
|
||||||
"buildAnalyze": "cross-env ANALYZE=true next build",
|
"buildAnalyze": "cross-env ANALYZE=true next build",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
|
|||||||
111
scripts/pre-push-full.sh
Executable file
111
scripts/pre-push-full.sh
Executable file
@@ -0,0 +1,111 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Full Pre-Push Hook Script
|
||||||
|
# Runs ALL checks locally before allowing push to remote
|
||||||
|
# Use this for important changes or before releases
|
||||||
|
|
||||||
|
set -e # Exit on any error
|
||||||
|
|
||||||
|
echo "🚀 Running FULL Pre-Push Checks..."
|
||||||
|
echo "=================================="
|
||||||
|
|
||||||
|
# Colors for output
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
|
||||||
|
# Function to print colored output
|
||||||
|
print_status() {
|
||||||
|
echo -e "${BLUE}[INFO]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_success() {
|
||||||
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_warning() {
|
||||||
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
print_error() {
|
||||||
|
echo -e "${RED}[ERROR]${NC} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if we're in a git repository
|
||||||
|
if ! git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
|
print_error "Not in a git repository!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get current branch
|
||||||
|
CURRENT_BRANCH=$(git branch --show-current)
|
||||||
|
print_status "Current branch: $CURRENT_BRANCH"
|
||||||
|
|
||||||
|
# Check if there are uncommitted changes
|
||||||
|
if ! git diff-index --quiet HEAD --; then
|
||||||
|
print_error "You have uncommitted changes. Please commit or stash them first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 1. Install dependencies
|
||||||
|
print_status "Installing dependencies..."
|
||||||
|
if ! npm ci --silent; then
|
||||||
|
print_error "Failed to install dependencies"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "Dependencies installed"
|
||||||
|
|
||||||
|
# 2. Run ESLint
|
||||||
|
print_status "Running ESLint..."
|
||||||
|
if ! npm run lint; then
|
||||||
|
print_error "ESLint failed! Please fix the errors before pushing."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "ESLint passed"
|
||||||
|
|
||||||
|
# 3. Run Tests
|
||||||
|
print_status "Running tests..."
|
||||||
|
if ! npm run test; then
|
||||||
|
print_error "Tests failed! Please fix the failing tests before pushing."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "All tests passed"
|
||||||
|
|
||||||
|
# 4. Build Application
|
||||||
|
print_status "Building application..."
|
||||||
|
if ! npm run build; then
|
||||||
|
print_error "Build failed! Please fix the build errors before pushing."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "Build successful"
|
||||||
|
|
||||||
|
# 5. Security Audit
|
||||||
|
print_status "Running security audit..."
|
||||||
|
if ! npm audit --audit-level=moderate; then
|
||||||
|
print_warning "Security vulnerabilities found. Consider running 'npm audit fix'"
|
||||||
|
# Don't fail the push for security warnings, just warn
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 6. Type Check
|
||||||
|
print_status "Running TypeScript type check..."
|
||||||
|
if ! npx tsc --noEmit; then
|
||||||
|
print_error "TypeScript type check failed!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
print_success "TypeScript type check passed"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=================================="
|
||||||
|
print_success "All FULL pre-push checks passed! ✅"
|
||||||
|
print_status "Ready to push to $CURRENT_BRANCH"
|
||||||
|
echo "=================================="
|
||||||
|
|
||||||
|
# Optional: Show what will be pushed
|
||||||
|
echo ""
|
||||||
|
print_status "Files to be pushed:"
|
||||||
|
git diff --name-only origin/$CURRENT_BRANCH..HEAD 2>/dev/null || git diff --name-only HEAD~1..HEAD
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
print_status "Proceeding with push..."
|
||||||
@@ -64,30 +64,7 @@ if ! npm run lint; then
|
|||||||
fi
|
fi
|
||||||
print_success "ESLint passed"
|
print_success "ESLint passed"
|
||||||
|
|
||||||
# 3. Run Tests
|
# 3. Quick Type Check (faster than full build)
|
||||||
print_status "Running tests..."
|
|
||||||
if ! npm run test; then
|
|
||||||
print_error "Tests failed! Please fix the failing tests before pushing."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
print_success "All tests passed"
|
|
||||||
|
|
||||||
# 4. Build Application
|
|
||||||
print_status "Building application..."
|
|
||||||
if ! npm run build; then
|
|
||||||
print_error "Build failed! Please fix the build errors before pushing."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
print_success "Build successful"
|
|
||||||
|
|
||||||
# 5. Security Audit
|
|
||||||
print_status "Running security audit..."
|
|
||||||
if ! npm audit --audit-level=moderate; then
|
|
||||||
print_warning "Security vulnerabilities found. Consider running 'npm audit fix'"
|
|
||||||
# Don't fail the push for security warnings, just warn
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 6. Type Check
|
|
||||||
print_status "Running TypeScript type check..."
|
print_status "Running TypeScript type check..."
|
||||||
if ! npx tsc --noEmit; then
|
if ! npx tsc --noEmit; then
|
||||||
print_error "TypeScript type check failed!"
|
print_error "TypeScript type check failed!"
|
||||||
@@ -95,6 +72,16 @@ if ! npx tsc --noEmit; then
|
|||||||
fi
|
fi
|
||||||
print_success "TypeScript type check passed"
|
print_success "TypeScript type check passed"
|
||||||
|
|
||||||
|
# Note: Tests and Build will run in GitHub Actions
|
||||||
|
print_status "Skipping tests and build locally (will run in CI/CD)"
|
||||||
|
|
||||||
|
# 4. Security Audit (quick check)
|
||||||
|
print_status "Running security audit..."
|
||||||
|
if ! npm audit --audit-level=moderate; then
|
||||||
|
print_warning "Security vulnerabilities found. Consider running 'npm audit fix'"
|
||||||
|
# Don't fail the push for security warnings, just warn
|
||||||
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "================================"
|
echo "================================"
|
||||||
print_success "All pre-push checks passed! ✅"
|
print_success "All pre-push checks passed! ✅"
|
||||||
|
|||||||
Reference in New Issue
Block a user