From 62ef4deb4fd4432b8f032a3ec0a417f0b55c6c02 Mon Sep 17 00:00:00 2001 From: Dennis Konkol Date: Fri, 5 Sep 2025 23:09:04 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20Add=20Pre-Push=20Hook=20&=20Fix?= =?UTF-8?q?=20GitHub=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Pre-Push Hook System: - Created scripts/pre-push.sh with comprehensive checks - Added Git pre-push hook (.git/hooks/pre-push) - Added npm run pre-push script - Added npm run lint:fix script 🔧 Pre-Push Checks: - Dependencies installation (npm ci) - ESLint validation (npm run lint) - Test execution (npm run test) - Build verification (npm run build) - Security audit (npm audit) - TypeScript type check (tsc --noEmit) ✅ GitHub Actions Fix: - Removed deprecated GHOST_API variables - Updated environment variables to match current .env - Fixed test and production environment setup 🎯 Benefits: - No more failed pushes to GitHub - All checks run locally before push - Same checks as GitHub Actions - Prevents broken code from reaching remote --- .github/workflows/ci-cd.yml | 14 +++-- package.json | 2 + scripts/pre-push.sh | 110 ++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 4 deletions(-) create mode 100755 scripts/pre-push.sh diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 5fb54be..717bf6d 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -31,13 +31,16 @@ jobs: - name: Create test environment file run: | cat > .env < .env < /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 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..."