#!/bin/bash # Pre-Flight Check Script # Validates that it's safe to start implementing a new task # Usage: ./scripts/pre-flight-check.sh set -e # Exit on error # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Track if any checks fail FAILED=0 echo "🔍 Pre-Flight Check - Validation avant implémentation" echo "==================================================" echo "" # Function to print success print_success() { echo -e "${GREEN}✅ $1${NC}" } # Function to print error print_error() { echo -e "${RED}❌ $1${NC}" FAILED=1 } # Function to print warning print_warning() { echo -e "${YELLOW}⚠️ $1${NC}" } # Check 1: Verify we're in the project root if [ ! -f "go.work" ] && [ ! -f "package.json" ]; then print_error "Not in project root. Please run from project root directory." exit 1 fi print_success "Project root verified" # Check 2: Check for existing errors (P0/P1 only) echo "" echo "📋 Check 1: Vérification des erreurs existantes (P0/P1)..." if [ -f "./scripts/discover-errors.sh" ]; then # Run discover-errors and check for P0/P1 errors ERROR_COUNT=$(./scripts/discover-errors.sh 2>&1 | grep -c "P0\|P1" || echo "0") if [ "$ERROR_COUNT" -gt 0 ]; then print_warning "Erreurs P0/P1 détectées. Il est recommandé de les corriger d'abord." print_warning "Continuer quand même? (y/N)" read -r response if [[ ! "$response" =~ ^[Yy]$ ]]; then print_error "Pre-flight check annulé. Corrigez les erreurs P0/P1 d'abord." exit 1 fi else print_success "Aucune erreur P0/P1 détectée" fi else print_warning "Script discover-errors.sh non trouvé. Skip cette vérification." fi # Check 3: Backend Go - Build check echo "" echo "📋 Check 2: Backend Go - Vérification build..." if [ -d "veza-backend-api" ]; then cd veza-backend-api if go build ./... > /dev/null 2>&1; then print_success "Backend Go compile sans erreur" else print_error "Backend Go ne compile pas. Corrigez les erreurs d'abord." cd .. exit 1 fi cd .. else print_warning "veza-backend-api non trouvé. Skip cette vérification." fi # Check 4: Backend Go - Import cycles echo "" echo "📋 Check 3: Backend Go - Vérification import cycles..." if [ -d "veza-backend-api" ]; then cd veza-backend-api CYCLES=$(go list -f '{{join .DepsErrors "\n"}}' ./... 2>&1 | grep -i "cycle" || echo "") if [ -z "$CYCLES" ]; then print_success "Aucun import cycle détecté" else print_error "Import cycles détectés:" echo "$CYCLES" cd .. exit 1 fi cd .. fi # Check 5: Backend Go - Tests (short mode) echo "" echo "📋 Check 4: Backend Go - Tests unitaires (mode rapide)..." if [ -d "veza-backend-api" ]; then cd veza-backend-api if go test ./... -short > /dev/null 2>&1; then print_success "Tests backend passent" else print_warning "Certains tests backend échouent. Vérifiez avant de continuer." fi cd .. fi # Check 6: Frontend - TypeScript check echo "" echo "📋 Check 5: Frontend - Vérification TypeScript..." if [ -d "apps/web" ]; then cd apps/web if npx tsc --noEmit --skipLibCheck > /dev/null 2>&1; then print_success "TypeScript compile sans erreur" else print_warning "Erreurs TypeScript détectées. Vérifiez avant de continuer." # Don't fail, just warn fi cd ../.. fi # Check 7: Frontend - Lint check echo "" echo "📋 Check 6: Frontend - Vérification lint..." if [ -d "apps/web" ]; then cd apps/web LINT_ERRORS=$(npm run lint 2>&1 | grep -c "error" || echo "0") if [ "$LINT_ERRORS" -eq 0 ]; then print_success "Linter frontend: aucune erreur" else print_warning "Erreurs lint détectées. Considérez les corriger d'abord." fi cd ../.. fi # Check 8: Frontend - Tests (if fast enough) echo "" echo "📋 Check 7: Frontend - Tests unitaires..." if [ -d "apps/web" ]; then cd apps/web # Run tests in run mode (not watch) but timeout after 30s if timeout 30 npm test -- --run --reporter=verbose > /dev/null 2>&1; then print_success "Tests frontend passent" else print_warning "Tests frontend prennent trop de temps ou échouent. Vérifiez manuellement." fi cd ../.. fi # Check 9: Git status echo "" echo "📋 Check 8: Vérification Git..." if git rev-parse --git-dir > /dev/null 2>&1; then # Check if working directory is clean if [ -z "$(git status --porcelain)" ]; then print_success "Working directory propre" else print_warning "Working directory contient des modifications non commitées" echo " Considérez commiter ou stasher vos changements avant de commencer une nouvelle tâche." fi # Check if we're on main/master BRANCH=$(git rev-parse --abbrev-ref HEAD) if [ "$BRANCH" = "main" ] || [ "$BRANCH" = "master" ]; then print_warning "Vous êtes sur la branche $BRANCH. Créez une nouvelle branche pour votre tâche." else print_success "Branche actuelle: $BRANCH" fi else print_warning "Pas un dépôt Git. Skip cette vérification." fi # Final summary echo "" echo "==================================================" if [ $FAILED -eq 0 ]; then echo -e "${GREEN}✅ Pre-Flight Check PASSED${NC}" echo "" echo "Vous pouvez maintenant commencer l'implémentation de votre tâche." echo "" echo "Prochaines étapes:" echo " 1. Utiliser un template depuis dev-environment/templates/" echo " 2. Suivre les patterns sûrs dans ORIGIN_ERROR_PREVENTION_GUIDE.md" echo " 3. Écrire les tests en TDD" echo " 4. Valider avec les quality gates avant commit" exit 0 else echo -e "${RED}❌ Pre-Flight Check FAILED${NC}" echo "" echo "Corrigez les erreurs ci-dessus avant de continuer." echo "Consultez ORIGIN_ERROR_PREVENTION_GUIDE.md pour plus d'informations." exit 1 fi