fix: Correct deployment script variable expansion and paths
- Fixed heredoc variable expansion in deploy.sh (was using 'EOF' preventing variable substitution) - Updated pre-deployment-check.sh to look in project root instead of staging-deployment - Fixed validate-templates.sh to use correct templates directory - Removed incorrect directory references that were breaking validation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
815b5fc65b
commit
e3abd18a70
3 changed files with 288 additions and 1 deletions
|
|
@ -149,7 +149,7 @@ sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" <<
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo -e "${GREEN}Step 4: Clearing cache...${NC}"
|
echo -e "${GREEN}Step 4: Clearing cache...${NC}"
|
||||||
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << 'EOF'
|
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no "$SSH_USER@$SERVER_IP" << EOF
|
||||||
cd $SERVER_PATH
|
cd $SERVER_PATH
|
||||||
|
|
||||||
# Clear WordPress cache
|
# Clear WordPress cache
|
||||||
|
|
|
||||||
173
scripts/pre-deployment-check.sh
Executable file
173
scripts/pre-deployment-check.sh
Executable file
|
|
@ -0,0 +1,173 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Pre-Deployment Check Script
|
||||||
|
# Runs all validation before any deployment
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo -e "${BLUE}=== Pre-Deployment Validation Check ===${NC}"
|
||||||
|
echo "Running comprehensive checks before deployment..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Track overall success
|
||||||
|
overall_success=true
|
||||||
|
|
||||||
|
# Check 1: Template Structure Validation
|
||||||
|
echo -e "${BLUE}📋 Step 1: Template Structure Validation${NC}"
|
||||||
|
if "$SCRIPT_DIR/validate-templates.sh"; then
|
||||||
|
echo -e "${GREEN}✅ Template validation passed${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Template validation failed${NC}"
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check 2: CSS File Existence
|
||||||
|
echo -e "${BLUE}📋 Step 2: CSS File Validation${NC}"
|
||||||
|
css_files=(
|
||||||
|
"assets/css/hvac-dashboard.css"
|
||||||
|
"assets/css/hvac-dashboard-enhanced.css"
|
||||||
|
"assets/css/communication-templates.css"
|
||||||
|
)
|
||||||
|
|
||||||
|
missing_css=false
|
||||||
|
for css_file in "${css_files[@]}"; do
|
||||||
|
if [ -f "$PROJECT_DIR/$css_file" ]; then
|
||||||
|
echo -e "${GREEN}✅ Found: $css_file${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Missing: $css_file${NC}"
|
||||||
|
missing_css=true
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$missing_css" = false ]; then
|
||||||
|
echo -e "${GREEN}✅ All required CSS files found${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check 3: PHP Syntax Validation
|
||||||
|
echo -e "${BLUE}📋 Step 3: PHP Syntax Validation${NC}"
|
||||||
|
php_errors=false
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
if ! php -l "$file" >/dev/null 2>&1; then
|
||||||
|
echo -e "${RED}❌ PHP syntax error in: $(basename "$file")${NC}"
|
||||||
|
php -l "$file"
|
||||||
|
php_errors=true
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
done < <(find "$PROJECT_DIR" -name "*.php" -path "*/vendor/*" -prune -o -path "*/node_modules/*" -prune -o -print0)
|
||||||
|
|
||||||
|
if [ "$php_errors" = false ]; then
|
||||||
|
echo -e "${GREEN}✅ All PHP files have valid syntax${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check 4: JavaScript Syntax (basic)
|
||||||
|
echo -e "${BLUE}📋 Step 4: JavaScript Validation${NC}"
|
||||||
|
js_files_found=false
|
||||||
|
js_errors=false
|
||||||
|
|
||||||
|
while IFS= read -r -d '' file; do
|
||||||
|
js_files_found=true
|
||||||
|
# Basic check - just see if file is readable and has content
|
||||||
|
if [ ! -s "$file" ]; then
|
||||||
|
echo -e "${RED}❌ Empty JavaScript file: $(basename "$file")${NC}"
|
||||||
|
js_errors=true
|
||||||
|
overall_success=false
|
||||||
|
else
|
||||||
|
echo -e "${GREEN}✅ Found: $(basename "$file")${NC}"
|
||||||
|
fi
|
||||||
|
done < <(find "$PROJECT_DIR/assets/js" -name "*.js" -print0 2>/dev/null || true)
|
||||||
|
|
||||||
|
if [ "$js_files_found" = false ]; then
|
||||||
|
echo -e "${YELLOW}⚠️ No JavaScript files found${NC}"
|
||||||
|
elif [ "$js_errors" = false ]; then
|
||||||
|
echo -e "${GREEN}✅ JavaScript files validated${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check 5: Required Directories
|
||||||
|
echo -e "${BLUE}📋 Step 5: Directory Structure Validation${NC}"
|
||||||
|
required_dirs=(
|
||||||
|
"includes"
|
||||||
|
"templates"
|
||||||
|
"assets/css"
|
||||||
|
"assets/js"
|
||||||
|
)
|
||||||
|
|
||||||
|
missing_dirs=false
|
||||||
|
for dir in "${required_dirs[@]}"; do
|
||||||
|
if [ -d "$PROJECT_DIR/$dir" ]; then
|
||||||
|
echo -e "${GREEN}✅ Found: $dir${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Missing: $dir${NC}"
|
||||||
|
missing_dirs=true
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$missing_dirs" = false ]; then
|
||||||
|
echo -e "${GREEN}✅ All required directories found${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check 6: Environment Configuration
|
||||||
|
echo -e "${BLUE}📋 Step 6: Environment Configuration${NC}"
|
||||||
|
if [ -f "$PROJECT_DIR/.env" ]; then
|
||||||
|
echo -e "${GREEN}✅ .env file found${NC}"
|
||||||
|
|
||||||
|
# Check for required variables
|
||||||
|
required_vars=("UPSKILL_STAGING_IP" "UPSKILL_STAGING_SSH_USER" "UPSKILL_STAGING_PATH")
|
||||||
|
for var in "${required_vars[@]}"; do
|
||||||
|
if grep -q "^$var=" "$PROJECT_DIR/.env"; then
|
||||||
|
echo -e "${GREEN}✅ Found: $var${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ Missing: $var${NC}"
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ .env file not found${NC}"
|
||||||
|
overall_success=false
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
echo -e "${BLUE}=== Pre-Deployment Check Summary ===${NC}"
|
||||||
|
if [ "$overall_success" = true ]; then
|
||||||
|
echo -e "${GREEN}🎉 ALL CHECKS PASSED!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}✅ Templates validated${NC}"
|
||||||
|
echo -e "${GREEN}✅ CSS files present${NC}"
|
||||||
|
echo -e "${GREEN}✅ PHP syntax correct${NC}"
|
||||||
|
echo -e "${GREEN}✅ JavaScript files ok${NC}"
|
||||||
|
echo -e "${GREEN}✅ Directory structure complete${NC}"
|
||||||
|
echo -e "${GREEN}✅ Environment configured${NC}"
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}🚀 Ready for deployment!${NC}"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo -e "${RED}🚨 DEPLOYMENT BLOCKED!${NC}"
|
||||||
|
echo ""
|
||||||
|
echo "Fix the issues above before deploying."
|
||||||
|
echo "This prevents broken templates from reaching users."
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}💡 Quick fixes:${NC}"
|
||||||
|
echo "• Add get_header()/get_footer() to templates"
|
||||||
|
echo "• Check CSS file paths and names"
|
||||||
|
echo "• Fix PHP syntax errors"
|
||||||
|
echo "• Create missing directories"
|
||||||
|
echo "• Configure environment variables"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
114
scripts/validate-templates.sh
Executable file
114
scripts/validate-templates.sh
Executable file
|
|
@ -0,0 +1,114 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Template Validation Script
|
||||||
|
# Prevents templates from going live without proper structure
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
|
TEMPLATES_DIR="$PROJECT_DIR/templates"
|
||||||
|
|
||||||
|
# Colors
|
||||||
|
RED='\033[0;31m'
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
BLUE='\033[0;34m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
echo -e "${BLUE}=== WordPress Template Validation ===${NC}"
|
||||||
|
echo "Scanning: $TEMPLATES_DIR"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
total_files=0
|
||||||
|
passed_files=0
|
||||||
|
failed_files=0
|
||||||
|
|
||||||
|
# Function to validate a single template
|
||||||
|
validate_template() {
|
||||||
|
local file=$1
|
||||||
|
local filename=$(basename "$file")
|
||||||
|
local issues=()
|
||||||
|
|
||||||
|
echo -n "Validating $filename: "
|
||||||
|
|
||||||
|
# Check 1: Has get_header() call
|
||||||
|
if ! grep -q "get_header()" "$file"; then
|
||||||
|
issues+=("Missing get_header() call")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check 2: Has get_footer() call
|
||||||
|
if ! grep -q "get_footer()" "$file"; then
|
||||||
|
issues+=("Missing get_footer() call")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check 3: Has ABSPATH security check
|
||||||
|
if ! grep -q "ABSPATH" "$file"; then
|
||||||
|
issues+=("Missing ABSPATH security check")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check 4: Uses proper WordPress container structure
|
||||||
|
if ! grep -q "content-area\|site-main" "$file"; then
|
||||||
|
issues+=("Missing proper WordPress container structure")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check 5: Check for inline AJAX (should use wp_ajax hooks)
|
||||||
|
if grep -q "wp_ajax\|DOING_AJAX" "$file" && ! grep -q "wp_ajax_" "$file"; then
|
||||||
|
issues+=("Uses inline AJAX instead of proper wp_ajax hooks")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check 6: Has proper template header
|
||||||
|
if ! grep -q "Template Name:" "$file"; then
|
||||||
|
issues+=("Missing Template Name header")
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#issues[@]} -eq 0 ]; then
|
||||||
|
echo -e "${GREEN}✅ PASSED${NC}"
|
||||||
|
((passed_files++))
|
||||||
|
else
|
||||||
|
echo -e "${RED}❌ FAILED${NC}"
|
||||||
|
((failed_files++))
|
||||||
|
for issue in "${issues[@]}"; do
|
||||||
|
echo -e " ${RED}→ $issue${NC}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
((total_files++))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Find and validate all template files
|
||||||
|
if [ -d "$TEMPLATES_DIR" ]; then
|
||||||
|
# Find all PHP files first, then filter
|
||||||
|
while IFS= read -r file; do
|
||||||
|
filename=$(basename "$file")
|
||||||
|
# Skip non-template files
|
||||||
|
if [[ "$filename" == template-* ]] || [[ "$filename" == page-* ]] || [[ "$filename" == single-* ]]; then
|
||||||
|
validate_template "$file"
|
||||||
|
fi
|
||||||
|
done < <(find "$TEMPLATES_DIR" -name "*.php" -type f)
|
||||||
|
else
|
||||||
|
echo -e "${RED}Templates directory not found: $TEMPLATES_DIR${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo -e "${BLUE}=== Validation Summary ===${NC}"
|
||||||
|
echo "Total templates: $total_files"
|
||||||
|
echo -e "Passed: ${GREEN}$passed_files${NC}"
|
||||||
|
echo -e "Failed: ${RED}$failed_files${NC}"
|
||||||
|
|
||||||
|
if [ $failed_files -gt 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${RED}🚨 VALIDATION FAILED!${NC}"
|
||||||
|
echo "Fix the issues above before deploying templates."
|
||||||
|
echo "See TEMPLATE_VALIDATION_GUIDE.md for requirements."
|
||||||
|
exit 1
|
||||||
|
elif [ $total_files -eq 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}⚠️ No templates found to validate${NC}"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo -e "${GREEN}🎉 ALL TEMPLATES PASSED VALIDATION!${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
Loading…
Reference in a new issue