-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (152 loc) · 5.4 KB
/
Copy pathcd.yml
File metadata and controls
174 lines (152 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: CD - Deploy to Cloud
on:
push:
branches: [main]
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'staging'
type: choice
options:
- staging
- production
env:
NODE_VERSION: '20.x'
jobs:
# Build job - reusable build step
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: |
backend/package-lock.json
frontend/package-lock.json
# Backend build
- name: Install backend dependencies
run: npm ci
working-directory: ./backend
- name: Build backend
run: npm run build
working-directory: ./backend
# Frontend build
- name: Install frontend dependencies
run: npm ci
working-directory: ./frontend
- name: Build frontend for production
run: npm run build -- --configuration=production
working-directory: ./frontend
# Upload artifacts
- name: Upload backend artifacts
uses: actions/upload-artifact@v4
with:
name: backend-dist
path: backend/dist
retention-days: 1
- name: Upload frontend artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist
retention-days: 1
# Deploy Backend to Render
deploy-backend:
name: Deploy Backend to Render
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' || github.event.inputs.environment != ''
steps:
- name: Trigger Render Deploy
run: |
if [ -n "${{ secrets.RENDER_DEPLOY_HOOK_URL }}" ]; then
echo "🚀 Triggering Render deployment..."
curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}"
echo "✅ Render deployment triggered"
else
echo "⚠️ RENDER_DEPLOY_HOOK_URL secret not set"
echo "To enable auto-deploy:"
echo "1. Go to Render Dashboard → Your Service → Settings → Deploy Hook"
echo "2. Copy the deploy hook URL"
echo "3. Add it as RENDER_DEPLOY_HOOK_URL secret in GitHub repo settings"
fi
# Deploy Frontend to Vercel
deploy-frontend:
name: Deploy Frontend to Vercel
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' || github.event.inputs.environment != ''
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install Vercel CLI
run: npm install -g vercel@latest
- name: Pull Vercel Environment Information
run: |
if [ -n "${{ secrets.VERCEL_TOKEN }}" ]; then
cd frontend
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
else
echo "⚠️ VERCEL_TOKEN not set - skipping Vercel pull"
fi
- name: Build Project Artifacts
run: |
if [ -n "${{ secrets.VERCEL_TOKEN }}" ]; then
cd frontend
vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
else
echo "⚠️ VERCEL_TOKEN not set - skipping Vercel build"
fi
- name: Deploy to Vercel
run: |
if [ -n "${{ secrets.VERCEL_TOKEN }}" ]; then
cd frontend
vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
echo "✅ Vercel deployment complete"
else
echo "⚠️ VERCEL_TOKEN secret not set"
echo ""
echo "To enable auto-deploy to Vercel:"
echo "1. Go to https://vercel.com/account/tokens"
echo "2. Create a new token"
echo "3. Add it as VERCEL_TOKEN secret in GitHub repo settings"
echo ""
echo "Also add these secrets:"
echo "- VERCEL_ORG_ID: Your Vercel team/org ID"
echo "- VERCEL_PROJECT_ID: Your Vercel project ID"
echo ""
echo "You can find these IDs by running 'vercel link' locally"
fi
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
# Deployment summary
deploy-summary:
name: Deployment Summary
runs-on: ubuntu-latest
needs: [deploy-backend, deploy-frontend]
if: always()
steps:
- name: Summary
run: |
echo "## Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Service | Status |" >> $GITHUB_STEP_SUMMARY
echo "|---------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Backend (Render) | ${{ needs.deploy-backend.result }} |" >> $GITHUB_STEP_SUMMARY
echo "| Frontend (Vercel) | ${{ needs.deploy-frontend.result }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### URLs" >> $GITHUB_STEP_SUMMARY
echo "- Backend API: https://dev-onboarding-api.onrender.com" >> $GITHUB_STEP_SUMMARY
echo "- Frontend App: https://dev-onboarding.vercel.app" >> $GITHUB_STEP_SUMMARY