Skip to content

Commit 2e32ec9

Browse files
authored
Merge pull request #211 from codeunia-dev/production-readiness-improvements
feat: Complete CI/CD pipeline migration to Vercel CLI v47+ compatible
2 parents c5c0d8d + 25e860d commit 2e32ec9

5 files changed

Lines changed: 228 additions & 27 deletions

File tree

.github/workflows /keep-alive.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
keep-alive:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313

1414
- name: Setup Node.js
15-
uses: actions/setup-node@v3
15+
uses: actions/setup-node@v4
1616
with:
17-
node-version: '18'
17+
node-version: '20'
1818

1919
- name: Install dependencies
2020
run: |

.github/workflows/ci-cd.yml

Lines changed: 96 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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 }}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"test:local": "./scripts/test-ci-local.sh all",
2929
"test:local:security": "./scripts/test-ci-local.sh security",
3030
"test:local:build": "./scripts/test-ci-local.sh build",
31-
"test:local:vercel": "./scripts/test-ci-local.sh vercel"
31+
"test:local:vercel": "./scripts/test-ci-local.sh vercel",
32+
"vercel:setup": "./scripts/setup-vercel-config.sh"
3233
},
3334
"dependencies": {
3435
"@google/generative-ai": "^0.24.1",

scripts/setup-vercel-config.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
3+
# Setup Vercel Configuration Script
4+
# This script helps set up the .vercel/project.json file for CI/CD deployments
5+
6+
set -e
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
BLUE='\033[0;34m'
13+
NC='\033[0m' # No Color
14+
15+
print_status() {
16+
echo -e "${BLUE}[INFO]${NC} $1"
17+
}
18+
19+
print_success() {
20+
echo -e "${GREEN}[SUCCESS]${NC} $1"
21+
}
22+
23+
print_warning() {
24+
echo -e "${YELLOW}[WARNING]${NC} $1"
25+
}
26+
27+
print_error() {
28+
echo -e "${RED}[ERROR]${NC} $1"
29+
}
30+
31+
# Function to setup Vercel configuration
32+
setup_vercel_config() {
33+
print_status "Setting up Vercel configuration..."
34+
35+
# Check if required environment variables are set
36+
if [ -z "$VERCEL_ORG_ID" ] || [ -z "$VERCEL_PROJECT_ID" ]; then
37+
print_error "VERCEL_ORG_ID and VERCEL_PROJECT_ID environment variables are required"
38+
print_status "Please set these variables:"
39+
echo " export VERCEL_ORG_ID=your_org_id"
40+
echo " export VERCEL_PROJECT_ID=your_project_id"
41+
exit 1
42+
fi
43+
44+
# Validate format of IDs
45+
if [[ ! "$VERCEL_ORG_ID" =~ ^team_ ]]; then
46+
print_warning "VERCEL_ORG_ID should start with 'team_' (current: $VERCEL_ORG_ID)"
47+
fi
48+
49+
if [[ ! "$VERCEL_PROJECT_ID" =~ ^prj_ ]]; then
50+
print_warning "VERCEL_PROJECT_ID should start with 'prj_' (current: $VERCEL_PROJECT_ID)"
51+
fi
52+
53+
# Create .vercel directory if it doesn't exist
54+
mkdir -p .vercel
55+
56+
# Create project.json with actual values
57+
cat > .vercel/project.json << EOF
58+
{
59+
"orgId": "$VERCEL_ORG_ID",
60+
"projectId": "$VERCEL_PROJECT_ID"
61+
}
62+
EOF
63+
64+
# Verify the file was created correctly
65+
if [ ! -f ".vercel/project.json" ]; then
66+
print_error "Failed to create .vercel/project.json"
67+
exit 1
68+
fi
69+
70+
print_success "Vercel configuration created successfully!"
71+
print_status "Configuration file: .vercel/project.json"
72+
print_status "Org ID: $VERCEL_ORG_ID"
73+
print_status "Project ID: $VERCEL_PROJECT_ID"
74+
75+
# Display the created configuration
76+
print_status "Configuration content:"
77+
cat .vercel/project.json
78+
}
79+
80+
# Function to validate Vercel CLI installation
81+
validate_vercel_cli() {
82+
print_status "Validating Vercel CLI installation..."
83+
84+
if ! command -v vercel &> /dev/null; then
85+
print_warning "Vercel CLI not found. Installing..."
86+
npm install -g vercel@latest
87+
fi
88+
89+
print_status "Vercel CLI version:"
90+
vercel --version
91+
92+
print_success "Vercel CLI validation completed!"
93+
}
94+
95+
# Function to test Vercel authentication
96+
test_vercel_auth() {
97+
print_status "Testing Vercel authentication..."
98+
99+
if [ -z "$VERCEL_TOKEN" ]; then
100+
print_warning "VERCEL_TOKEN not set. Authentication test skipped."
101+
return
102+
fi
103+
104+
vercel whoami --token "$VERCEL_TOKEN"
105+
print_success "Vercel authentication test completed!"
106+
}
107+
108+
# Main execution
109+
main() {
110+
print_status "Starting Vercel configuration setup..."
111+
112+
validate_vercel_cli
113+
test_vercel_auth
114+
setup_vercel_config
115+
116+
print_success "Vercel configuration setup completed!"
117+
print_status "You can now run deployment commands without deprecated flags."
118+
}
119+
120+
# Run main function
121+
main "$@"

scripts/test-ci-local.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ test_vercel_commands() {
9797
print_status "Vercel CLI version:"
9898
vercel --version
9999

100-
# Test direct deployment with scope flag
101-
print_status "Testing Vercel direct deployment with scope flag..."
102-
echo "vercel --token \$VERCEL_TOKEN --scope \$VERCEL_ORG_ID --yes"
103-
echo "vercel --prod --token \$VERCEL_TOKEN --scope \$VERCEL_ORG_ID --yes"
100+
# Test direct deployment with environment variables
101+
print_status "Testing Vercel direct deployment with environment variables..."
102+
echo "export VERCEL_ORG_ID=\$VERCEL_ORG_ID"
103+
echo "export VERCEL_PROJECT_ID=\$VERCEL_PROJECT_ID"
104+
echo "vercel --token \$VERCEL_TOKEN --yes"
105+
echo "vercel --prod --token \$VERCEL_TOKEN --yes"
104106

105107
print_success "Vercel command testing completed!"
106108
}

0 commit comments

Comments
 (0)