#!/bin/bash # Push to Dev Branch - Automated Script # This script performs final checks and pushes changes to the dev branch set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${BLUE}║ Portfolio - Push to Dev Branch ║${NC}" echo -e "${BLUE}╚════════════════════════════════════════════════════════════╝${NC}" echo "" # Check if we're on dev branch CURRENT_BRANCH=$(git branch --show-current) if [ "$CURRENT_BRANCH" != "dev" ]; then echo -e "${YELLOW}⚠️ Warning: You're on branch '${CURRENT_BRANCH}', not 'dev'${NC}" read -p "Do you want to switch to dev branch? (y/n) " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then git checkout dev echo -e "${GREEN}✓ Switched to dev branch${NC}" else echo -e "${RED}✗ Aborted${NC}" exit 1 fi fi echo -e "${BLUE}📋 Running Pre-Push Checks...${NC}" echo "" # Check 1: Build Test echo -e "${YELLOW}[1/5] Building project...${NC}" if npm run build > /dev/null 2>&1; then echo -e "${GREEN}✓ Build successful${NC}" else echo -e "${RED}✗ Build failed${NC}" echo "Run 'npm run build' to see errors" exit 1 fi # Check 2: Lint Test echo -e "${YELLOW}[2/5] Running linter...${NC}" LINT_OUTPUT=$(npm run lint 2>&1) ERROR_COUNT=$(echo "$LINT_OUTPUT" | grep -oP '\d+(?= error)' || echo "0") if [ "$ERROR_COUNT" -eq 0 ]; then echo -e "${GREEN}✓ Lint passed (0 errors)${NC}" else echo -e "${RED}✗ Lint failed ($ERROR_COUNT errors)${NC}" echo "Run 'npm run lint' to see errors" exit 1 fi # Check 3: Check for uncommitted changes echo -e "${YELLOW}[3/5] Checking git status...${NC}" if [ -n "$(git status --porcelain)" ]; then echo -e "${GREEN}✓ Found uncommitted changes${NC}" echo "" echo "Modified files:" git status --short echo "" else echo -e "${YELLOW}⚠️ No uncommitted changes found${NC}" read -p "Push anyway? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}✗ Aborted${NC}" exit 1 fi fi # Check 4: Verify critical files exist echo -e "${YELLOW}[4/5] Verifying critical files...${NC}" REQUIRED_FILES=( "CHANGELOG_DEV.md" "AFTER_PUSH_SETUP.md" "prisma/migrations/create_activity_status.sql" "docs/ai-image-generation/README.md" ) MISSING=0 for file in "${REQUIRED_FILES[@]}"; do if [ ! -f "$file" ]; then echo -e "${RED}✗ Missing: $file${NC}" MISSING=$((MISSING + 1)) fi done if [ $MISSING -eq 0 ]; then echo -e "${GREEN}✓ All critical files present${NC}" else echo -e "${RED}✗ Missing $MISSING critical file(s)${NC}" exit 1 fi # Check 5: Check for .env.local in staging echo -e "${YELLOW}[5/5] Checking for sensitive files...${NC}" if git ls-files --error-unmatch .env.local > /dev/null 2>&1; then echo -e "${RED}✗ DANGER: .env.local is staged for commit!${NC}" echo "Run: git reset HEAD .env.local" exit 1 else echo -e "${GREEN}✓ No sensitive files staged${NC}" fi echo "" echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ All Pre-Push Checks Passed! ✓ ║${NC}" echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}" echo "" # Show what will be committed echo -e "${BLUE}📦 Changes to be committed:${NC}" echo "" git status --short echo "" # Ask for confirmation echo -e "${YELLOW}Ready to commit and push to dev branch?${NC}" read -p "Continue? (y/n) " -n 1 -r echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo -e "${RED}✗ Aborted by user${NC}" exit 1 fi # Stage all changes echo -e "${BLUE}📝 Staging changes...${NC}" git add . # Commit with prepared message echo -e "${BLUE}💾 Committing...${NC}" if [ -f "COMMIT_MESSAGE.txt" ]; then git commit -F COMMIT_MESSAGE.txt echo -e "${GREEN}✓ Committed with prepared message${NC}" else echo -e "${YELLOW}⚠️ COMMIT_MESSAGE.txt not found, using default message${NC}" git commit -m "feat: Fix hydration errors, navbar overlap, and add AI image generation system - Fixed React hydration errors in ActivityFeed - Fixed duplicate keys in About and Projects - Fixed navbar overlapping hero section - Fixed /manage redirect loop - Added complete AI image generation system - Added ActivityStatus database model - Comprehensive documentation included See CHANGELOG_DEV.md for details." echo -e "${GREEN}✓ Committed with default message${NC}" fi # Push to remote echo -e "${BLUE}🚀 Pushing to origin/dev...${NC}" if git push origin dev; then echo "" echo -e "${GREEN}╔════════════════════════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ Successfully Pushed to Dev Branch! 🎉 ║${NC}" echo -e "${GREEN}╚════════════════════════════════════════════════════════════╝${NC}" echo "" echo -e "${BLUE}Next Steps:${NC}" echo " 1. Verify changes on remote: git log origin/dev --oneline -3" echo " 2. Share AFTER_PUSH_SETUP.md with team members" echo " 3. Test in staging environment" echo " 4. Create PR to main when ready" echo "" echo -e "${YELLOW}⚠️ Remember: Team members must run database migration!${NC}" echo " ./prisma/migrations/quick-fix.sh" echo "" else echo "" echo -e "${RED}✗ Push failed${NC}" echo "Check your network connection and remote permissions" exit 1 fi # Show final commit echo -e "${BLUE}📊 Latest commits:${NC}" git log --oneline -3 echo "" echo -e "${GREEN}✅ All done!${NC}"