Skip to content

debug: Add more detailed error handling logging for region saving #313

debug: Add more detailed error handling logging for region saving

debug: Add more detailed error handling logging for region saving #313

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
NODE_VERSION: '18'
# Cache version - increment to bust cache
CACHE_VERSION: 'v1'
jobs:
# Combined job for efficiency
build-and-test:
name: Build, Lint, and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache dependencies
uses: actions/cache@v3
id: npm-cache
with:
path: |
~/.npm
node_modules
apps/*/node_modules
packages/*/node_modules
key: ${{ runner.os }}-node-${{ env.CACHE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.CACHE_VERSION }}-
- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci
- name: Run linting
run: npm run lint
- name: Type check
run: npm run type-check
- name: Run tests
run: npm test
env:
CI: true
- name: Security audit
run: |
npm audit --audit-level=high
npx audit-ci --config audit-ci.json
- name: Build application
run: npm run build
env:
VITE_API_URL: 'http://localhost:8000/api'
# Supabase credentials are only available in production environment
# The production deployment job will build with the actual credentials
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: apps/frontend/dist/
retention-days: 7
# Deploy preview for PRs
deploy-preview:
name: Deploy Preview
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Clear build cache
run: |
echo "Clearing any cached build artifacts..."
rm -rf apps/frontend/dist
rm -rf apps/frontend/.vite
rm -rf apps/frontend/node_modules/.vite
npm cache clean --force
- name: Override environment files
run: |
echo "Creating production .env file to override any local settings..."
cat > apps/frontend/.env << EOF
VITE_API_URL=${{ secrets.PROD_API_URL || 'http://74.208.126.44:8000/api' }}
VITE_SUPABASE_URL=${{ secrets.SUPABASE_URL || '' }}
VITE_SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY || '' }}
VITE_DISABLE_AUTH=true
VITE_ENVIRONMENT=production
EOF
echo "Contents of production .env file:"
cat apps/frontend/.env
- name: Build preview with correct API URL
run: npm run build
env:
VITE_API_URL: ${{ secrets.PROD_API_URL || 'http://74.208.126.44:8000/api' }}
VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
VITE_DISABLE_AUTH: 'true'
- name: Debug build environment
run: |
echo "Debugging environment variables during build..."
echo "VITE_API_URL that was used: ${{ secrets.PROD_API_URL || 'http://74.208.126.44:8000/api' }}"
echo "Checking if build files contain the expected API URL..."
echo "Contents of dist directory:"
ls -la apps/frontend/dist/ || echo "No dist directory found"
echo "Contents of assets directory:"
ls -la apps/frontend/dist/assets/ || echo "No assets directory found"
echo "Searching for API URLs in all JS files:"
find apps/frontend/dist -name "*.js" -exec grep -l "api\|localhost\|http" {} \; || echo "No JS files with API URLs found"
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Verify preview build environment variables
run: |
echo "Checking if API URL was properly embedded in preview build..."
if grep -q "74.208.126.44:8000" apps/frontend/dist/assets/*.js 2>/dev/null; then
echo "✅ Found correct API URL in preview build files"
else
echo "❌ Correct API URL not found in preview build files"
echo "Checking what API URL is in the build..."
grep -o "http[s]*://[^/]*[^\"']*" apps/frontend/dist/assets/*.js 2>/dev/null | head -5 || echo "No URLs found"
fi
- name: Deploy preview
run: |
netlify deploy --dir=apps/frontend/dist --filter=@wildeditor/frontend --site=${{ secrets.NETLIFY_PROD_SITE_ID }} --auth=${{ secrets.NETLIFY_AUTH_TOKEN }} --message="PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_PROD_SITE_ID }}
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
const output = `#### Netlify Preview Deployment 🚀\n
Preview URL will be available shortly.\n
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
# Production deployment
deploy-production:
name: Deploy to Production
runs-on: ubuntu-latest
needs: build-and-test
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
environment:
name: production
url: https://wildeditor.luminari.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.npm
node_modules
apps/*/node_modules
packages/*/node_modules
key: ${{ runner.os }}-node-${{ env.CACHE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.CACHE_VERSION }}-
- name: Install dependencies
run: npm ci
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Debug environment secrets
run: |
echo "Checking if environment secrets are accessible..."
echo "SUPABASE_URL is set: ${{ secrets.SUPABASE_URL != '' }}"
echo "SUPABASE_ANON_KEY is set: ${{ secrets.SUPABASE_ANON_KEY != '' }}"
echo "Using production environment: ${{ github.event.deployment.environment || 'production' }}"
echo "Note: These will be exposed as VITE_ prefixed variables during build"
- name: Clean previous build artifacts
run: |
echo "Cleaning any previous build artifacts to ensure fresh production build..."
rm -rf apps/frontend/dist
rm -rf apps/frontend/.vite
rm -rf apps/frontend/node_modules/.vite
npm cache clean --force
- name: Override environment files for production
run: |
echo "Creating production .env file to override any local settings..."
cat > apps/frontend/.env << EOF
VITE_API_URL=${{ secrets.PROD_API_URL || 'http://74.208.126.44:8000/api' }}
VITE_SUPABASE_URL=${{ secrets.SUPABASE_URL || '' }}
VITE_SUPABASE_ANON_KEY=${{ secrets.SUPABASE_ANON_KEY || '' }}
VITE_DISABLE_AUTH=true
VITE_ENVIRONMENT=production
EOF
echo "Contents of production .env file:"
cat apps/frontend/.env
- name: Verify source code before build
run: |
echo "=== CHECKING SOURCE CODE BEFORE BUILD ==="
echo "Contents of api.ts file (first 10 lines):"
cat apps/frontend/src/services/api.ts | head -10
echo ""
echo "Environment variables available during build:"
echo "VITE_API_URL: ${VITE_API_URL}"
echo "NODE_ENV: ${NODE_ENV}"
echo "All VITE_ variables:"
env | grep VITE_ || echo "No VITE_ variables found"
env:
VITE_API_URL: ${{ secrets.PROD_API_URL || 'https://api.wildedit.luminarimud.com/api' }}
VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
VITE_DISABLE_AUTH: 'true'
- name: Build production
run: npm run build
env:
VITE_API_URL: ${{ secrets.PROD_API_URL || 'https://api.wildedit.luminarimud.com/api' }}
VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
VITE_DISABLE_AUTH: 'true'
- name: Verify build environment variables
run: |
echo "Checking if environment variables were properly embedded in build..."
echo "Checking for API URL in build files..."
echo "=== SEARCHING FOR ALL HTTP URLs IN BUILD FILES ==="
find apps/frontend/dist -name "*.js" -exec grep -H "http[^\"']*" {} \; || echo "No HTTP URLs found"
echo ""
echo "=== SEARCHING FOR SPECIFIC PATTERNS ==="
find apps/frontend/dist -name "*.js" -exec grep -H "localhost\|127.0.0.1\|3001\|8000\|74.208.126.44" {} \; || echo "No localhost/IP patterns found"
echo ""
echo "=== CHECKING FOR API_BASE_URL ==="
find apps/frontend/dist -name "*.js" -exec grep -H "API_BASE_URL\|api/health" {} \; || echo "No API_BASE_URL found"
if grep -q "74.208.126.44:8000" apps/frontend/dist/assets/*.js 2>/dev/null; then
echo "✅ Found correct API URL in build files"
else
echo "❌ Correct API URL not found in build files"
echo "Checking what API URL is in the build..."
grep -o "http[s]*://[^/]*[^\"']*" apps/frontend/dist/assets/*.js 2>/dev/null | head -10 || echo "No URLs found"
fi
if grep -q "supabase.co" apps/frontend/dist/assets/*.js 2>/dev/null; then
echo "✅ Found Supabase URL in build files"
else
echo "❌ Supabase URL not found in build files - environment variables may not be set correctly"
fi
echo "Checking for masked values (asterisks)..."
if grep -q "\*\*\*\*\*\*\*\*" apps/frontend/dist/assets/*.js 2>/dev/null; then
echo "⚠️ WARNING: Found asterisk patterns in build files - possible masked secrets!"
echo "This indicates environment variables may have been masked during build"
exit 1
else
echo "✅ No masked values found in build files"
fi
- name: Deploy to Netlify
run: |
echo "=== PRE-DEPLOYMENT FINAL CHECK ==="
echo "Final verification of what's being deployed:"
find apps/frontend/dist -name "*.js" -exec grep -l "3001\|localhost:3001" {} \; && echo "❌ FOUND localhost:3001 in build!" || echo "✅ No localhost:3001 found"
find apps/frontend/dist -name "*.js" -exec grep -l "74.208.126.44" {} \; && echo "✅ FOUND correct API URL" || echo "❌ Correct API URL not found"
echo ""
netlify deploy --prod --dir=apps/frontend/dist --filter=@wildeditor/frontend --site=${{ secrets.NETLIFY_PROD_SITE_ID }} --auth=${{ secrets.NETLIFY_AUTH_TOKEN }} --message="Production deploy from ${{ github.sha }}"
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_PROD_SITE_ID }}
- name: Create GitHub Release
if: startsWith(github.ref, 'refs/tags/')
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
# Notify on deployment
notify:
name: Notify Deployment
runs-on: ubuntu-latest
needs: [deploy-production]
if: always() && github.ref == 'refs/heads/main'
steps:
- name: Notify Slack on Success
if: needs.deploy-production.result == 'success'
uses: 8398a7/action-slack@v3
with:
status: success
text: '🚀 Wildeditor deployed successfully to production!'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
- name: Notify Slack on Failure
if: needs.deploy-production.result == 'failure'
uses: 8398a7/action-slack@v3
with:
status: failure
text: '❌ Wildeditor deployment to production failed!'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}