@@ -252,26 +252,61 @@ jobs:
252252 - name : Install Vercel CLI
253253 run : npm install -g vercel@latest
254254
255- - name : Debug Vercel Org/Project IDs
255+ - name : Validate Vercel Secrets
256256 run : |
257- echo "VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}"
258- echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}"
257+ if [ -z "${{ secrets.VERCEL_TOKEN }}" ]; then
258+ echo "❌ VERCEL_TOKEN is not set"
259+ exit 1
260+ fi
261+ if [ -z "${{ secrets.VERCEL_ORG_ID }}" ]; then
262+ echo "❌ VERCEL_ORG_ID is not set"
263+ exit 1
264+ fi
265+ if [ -z "${{ secrets.VERCEL_PROJECT_ID }}" ]; then
266+ echo "❌ VERCEL_PROJECT_ID is not set"
267+ exit 1
268+ fi
269+ echo "✅ All Vercel secrets are configured"
259270
260- - name : Vercel whoami
261- run : vercel whoami --token ${{ secrets.VERCEL_TOKEN }}
271+ - name : Setup Vercel Configuration
272+ run : |
273+ chmod +x scripts/setup-vercel-config.sh
274+ export VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}
275+ export VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}
276+ export VERCEL_TOKEN=${{ secrets.VERCEL_TOKEN }}
277+ ./scripts/setup-vercel-config.sh
278+
279+ - name : Build for Vercel
280+ run : |
281+ npm run build
282+ env :
283+ NODE_ENV : production
284+ NEXT_PUBLIC_SUPABASE_URL : ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
285+ NEXT_PUBLIC_SUPABASE_ANON_KEY : ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
286+ SUPABASE_SERVICE_ROLE_KEY : ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
262287
263288 - name : Deploy to Vercel (Staging)
289+ id : deploy-staging
264290 run : |
265- rm -rf .vercel
266- vercel --token ${{ secrets.VERCEL_TOKEN }} --scope ${{ secrets.VERCEL_ORG_ID }} --project ${{ secrets.VERCEL_PROJECT_ID }} --yes
291+ DEPLOYMENT_URL=$(vercel deploy --prebuilt --token ${{ secrets.VERCEL_TOKEN }} --yes)
292+ echo "deployment-url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
293+ echo "🚀 Staging deployment URL: $DEPLOYMENT_URL"
267294 env :
268295 VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
269296 VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
270297
271298 - name : Run smoke tests
272299 run : |
300+ echo "⏳ Waiting for deployment to be ready..."
273301 sleep 30
274- curl -f ${{ secrets.STAGING_URL }}/api/health || exit 1
302+ echo "🔍 Testing health endpoint..."
303+ if curl -f -s --max-time 30 "${{ secrets.STAGING_URL }}/api/health"; then
304+ echo "✅ Staging health check passed"
305+ else
306+ echo "❌ Staging health check failed"
307+ echo "Deployment URL: ${{ steps.deploy-staging.outputs.deployment-url }}"
308+ exit 1
309+ fi
275310
276311 # Deploy to Production
277312 deploy-production :
@@ -293,33 +328,68 @@ jobs:
293328 - name : Install Vercel CLI
294329 run : npm install -g vercel@latest
295330
296- - name : Debug Vercel Org/Project IDs
331+ - name : Validate Vercel Secrets
332+ run : |
333+ if [ -z "${{ secrets.VERCEL_TOKEN }}" ]; then
334+ echo "❌ VERCEL_TOKEN is not set"
335+ exit 1
336+ fi
337+ if [ -z "${{ secrets.VERCEL_ORG_ID }}" ]; then
338+ echo "❌ VERCEL_ORG_ID is not set"
339+ exit 1
340+ fi
341+ if [ -z "${{ secrets.VERCEL_PROJECT_ID }}" ]; then
342+ echo "❌ VERCEL_PROJECT_ID is not set"
343+ exit 1
344+ fi
345+ echo "✅ All Vercel secrets are configured"
346+
347+ - name : Setup Vercel Configuration
297348 run : |
298- echo "VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}"
299- echo "VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}"
349+ chmod +x scripts/setup-vercel-config.sh
350+ export VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}
351+ export VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}
352+ export VERCEL_TOKEN=${{ secrets.VERCEL_TOKEN }}
353+ ./scripts/setup-vercel-config.sh
300354
301- - name : Vercel whoami
302- run : vercel whoami --token ${{ secrets.VERCEL_TOKEN }}
355+ - name : Build for Vercel
356+ run : |
357+ npm run build
358+ env :
359+ NODE_ENV : production
360+ NEXT_PUBLIC_SUPABASE_URL : ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
361+ NEXT_PUBLIC_SUPABASE_ANON_KEY : ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
362+ SUPABASE_SERVICE_ROLE_KEY : ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
303363
304364 - name : Deploy to Vercel (Production)
365+ id : deploy-production
305366 run : |
306- rm -rf .vercel
307- vercel --prod --token ${{ secrets.VERCEL_TOKEN }} --scope ${{ secrets.VERCEL_ORG_ID }} --project ${{ secrets.VERCEL_PROJECT_ID }} --yes
367+ DEPLOYMENT_URL=$(vercel deploy --prebuilt --prod --token ${{ secrets.VERCEL_TOKEN }} --yes)
368+ echo "deployment-url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT
369+ echo "🚀 Production deployment URL: $DEPLOYMENT_URL"
308370 env :
309371 VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
310372 VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
311373
312374 - name : Run production health check
313375 run : |
376+ echo "⏳ Waiting for production deployment to be ready..."
314377 sleep 30
315- curl -f ${{ secrets.PRODUCTION_URL }}/api/health || exit 1
378+ echo "🔍 Testing production health endpoint..."
379+ if curl -f -s --max-time 30 "${{ secrets.PRODUCTION_URL }}/api/health"; then
380+ echo "✅ Production health check passed"
381+ else
382+ echo "❌ Production health check failed"
383+ echo "Deployment URL: ${{ steps.deploy-production.outputs.deployment-url }}"
384+ exit 1
385+ fi
316386
317387 - name : Notify deployment success via email
318388 run : |
319389 curl -X POST "https://api.resend.com/emails" \
320390 -H "Authorization: Bearer ${{ secrets.RESEND_API_KEY }}" \
321391 -H "Content-Type: application/json" \
322- -d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"🚀 Production Deployment Successful\",\"html\":\"<h2>Production Deployment Successful</h2><p>Your Codeunia application has been successfully deployed to production.</p><p><strong>Branch:</strong> ${{ github.ref_name }}</p><p><strong>Commit:</strong> ${{ github.sha }}</p><p><strong>Deployed by:</strong> ${{ github.actor }}</p>\"}"
392+ -d "{\"from\":\"alerts@codeunia.com\",\"to\":[\"connect@codeunia.com\"],\"subject\":\"🚀 Production Deployment Successful\",\"html\":\"<h2>Production Deployment Successful</h2><p>Your Codeunia application has been successfully deployed to production.</p><p><strong>Deployment URL:</strong> <a href='${{ steps.deploy-production.outputs.deployment-url }}'>${{ steps.deploy-production.outputs.deployment-url }}</a></p><p><strong> Branch:</strong> ${{ github.ref_name }}</p><p><strong>Commit:</strong> ${{ github.sha }}</p><p><strong>Deployed by:</strong> ${{ github.actor }}</p>\"}"
323393
324394 # Rollback on Failure
325395 rollback :
@@ -335,10 +405,17 @@ jobs:
335405 - name : Install Vercel CLI
336406 run : npm install -g vercel@latest
337407
408+ - name : Setup Vercel Configuration
409+ run : |
410+ chmod +x scripts/setup-vercel-config.sh
411+ export VERCEL_ORG_ID=${{ secrets.VERCEL_ORG_ID }}
412+ export VERCEL_PROJECT_ID=${{ secrets.VERCEL_PROJECT_ID }}
413+ export VERCEL_TOKEN=${{ secrets.VERCEL_TOKEN }}
414+ ./scripts/setup-vercel-config.sh
415+
338416 - name : Rollback deployment
339417 run : |
340- rm -rf .vercel
341- vercel rollback --token ${{ secrets.VERCEL_TOKEN }} --scope ${{ secrets.VERCEL_ORG_ID }} --yes
418+ vercel rollback --token ${{ secrets.VERCEL_TOKEN }} --yes
342419 env :
343420 VERCEL_ORG_ID : ${{ secrets.VERCEL_ORG_ID }}
344421 VERCEL_PROJECT_ID : ${{ secrets.VERCEL_PROJECT_ID }}
0 commit comments