-
Notifications
You must be signed in to change notification settings - Fork 0
281 lines (267 loc) · 9.94 KB
/
Copy pathtest-deploy.yml
File metadata and controls
281 lines (267 loc) · 9.94 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: Test & Deploy
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
permissions:
contents: read
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
jobs:
# -------------------------
# Server: test & build
# -------------------------
test-server:
name: Test Server
runs-on: ubuntu-latest
timeout-minutes: 20
env:
CI: true
ADMIN_SECRET: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install, lint, test, build
working-directory: server
run: |
npm ci
npm run lint
npm test
npm run build
- name: Upload server build
uses: actions/upload-artifact@v4
with:
name: server-build
path: server/dist
# -------------------------
# Mobile: test Flutter web build
# -------------------------
test-mobile:
name: Test Mobile (Flutter Web)
runs-on: ubuntu-latest
timeout-minutes: 20
env:
CI: true
steps:
- uses: actions/checkout@v4
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.3
channel: stable
cache: true
- name: Ensure Flutter web is enabled
working-directory: mobile
run: flutter config --enable-web
- name: Setup environment file
run: cp mobile/.env.example mobile/.env
- name: Test mobile app
working-directory: mobile
run: |
flutter pub get
flutter analyze
flutter test
flutter build web --release --no-wasm-dry-run
- name: Upload web build
uses: actions/upload-artifact@v4
with:
name: web-build
path: mobile/build/web
# -------------------------
# Server: deploy (requires BOTH tests, only on main)
# -------------------------
deploy-server:
name: Deploy Server (traceoffapi)
runs-on: ubuntu-latest
needs: [test-server, test-mobile]
if: github.ref == 'refs/heads/main'
outputs:
deploy-url: ${{ steps.deploy.outputs.deploy_url }}
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_API_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} # optional for Personal
VERCEL_TELEMETRY_DISABLED: "1"
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
# Deploy from server directory
- name: Vercel pull (production)
working-directory: server
run: npx vercel pull --yes --environment=production --token="$VERCEL_TOKEN"
- name: Deploy to Vercel (prod)
working-directory: server
id: deploy
run: |
set -e
DEPLOY_OUTPUT=$(npx vercel deploy --prod --yes --token="$VERCEL_TOKEN")
echo "$DEPLOY_OUTPUT"
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -E "Production:" | grep -Eo 'https://[^[:space:]]+' | head -1)
if [ -z "$DEPLOY_URL" ]; then
# Fallback: take last https URL in output
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -Eo 'https://[^[:space:]]+' | tail -1)
fi
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
echo "Deployed to: $DEPLOY_URL"
- name: Health check server
run: |
echo "Waiting for deployment to be ready..."
DEPLOY_URL="${{ steps.deploy.outputs.deploy_url }}"
HOST_HEADER=$(echo "$DEPLOY_URL" | awk -F/ '{print $3}')
echo "Testing health at: $DEPLOY_URL/api/health (Host: $HOST_HEADER)"
# Initial wait to allow cold start and DNS propagation
sleep 15
for i in {1..30}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Host: $HOST_HEADER" \
-H "Accept: application/json" \
-H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" \
"$DEPLOY_URL/api/health")
if [ "$STATUS" = "200" ]; then
echo "✅ Server health check passed (200)"
exit 0
fi
echo "Attempt $i failed; status=$STATUS; retrying in 5s..."
sleep 5
done
echo "❌ Server health check failed"
exit 1
# -------------------------
# Web: deploy Flutter web (requires BOTH tests, only on main)
# -------------------------
deploy-web:
name: Deploy Flutter Web (traceoff)
runs-on: ubuntu-latest
needs: [test-server, test-mobile]
if: github.ref == 'refs/heads/main'
outputs:
deploy-url: ${{ steps.deploy-mobile.outputs.deploy_url }}
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_WEB_ID }}
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} # optional
VERCEL_TELEMETRY_DISABLED: "1"
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
# Build Flutter web bundle directly in this job (tests temporarily disabled)
- uses: subosito/flutter-action@v2
with:
flutter-version: 3.35.3
channel: stable
cache: true
- name: Ensure Flutter web is enabled
working-directory: mobile
run: flutter config --enable-web
- name: Setup environment file
run: cp mobile/.env.example mobile/.env
- name: Build Flutter web
working-directory: mobile
run: |
flutter pub get
flutter build web --release --no-wasm-dry-run
- name: Verify web build files exist
working-directory: mobile
run: |
if [ ! -d "build/web" ]; then
echo "❌ Error: build/web directory not found after build."
exit 1
fi
echo "✅ Web build files found"
ls -la build/web/
- name: Vercel pull (production)
working-directory: mobile
run: npx vercel pull --yes --environment=production --token="$VERCEL_TOKEN"
- name: Deploy to Vercel (prod)
working-directory: mobile
id: deploy-mobile
run: |
set -e
DEPLOY_OUTPUT=$(npx vercel deploy --prod --yes --token="$VERCEL_TOKEN")
echo "$DEPLOY_OUTPUT"
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -E "Production:" | grep -Eo 'https://[^[:space:]]+' | head -1)
if [ -z "$DEPLOY_URL" ]; then
DEPLOY_URL=$(echo "$DEPLOY_OUTPUT" | grep -Eo 'https://[^[:space:]]+' | tail -1)
fi
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
echo "Deployed to: $DEPLOY_URL"
- name: Health check mobile app
run: |
echo "Waiting for deployment to be ready..."
DEPLOY_URL="${{ steps.deploy-mobile.outputs.deploy_url }}"
HOST_HEADER=$(echo "$DEPLOY_URL" | awk -F/ '{print $3}')
echo "Testing mobile app at: $DEPLOY_URL (Host: $HOST_HEADER)"
sleep 15
for i in {1..30}; do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Host: $HOST_HEADER" \
-H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" \
"$DEPLOY_URL")
if [ "$STATUS" = "200" ]; then
echo "✅ Mobile app health check passed (200)"
exit 0
fi
echo "Attempt $i failed; status=$STATUS; retrying in 5s..."
sleep 5
done
echo "❌ Mobile app health check failed"
exit 1
# -------------------------
# Integration tests after deployment
# -------------------------
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: [deploy-server, deploy-web]
if: github.ref == 'refs/heads/main'
env:
VERCEL_AUTOMATION_BYPASS_SECRET: ${{ secrets.VERCEL_AUTOMATION_BYPASS_SECRET }}
steps:
- uses: actions/checkout@v4
- name: Test API endpoints
run: |
echo "🧪 Testing API endpoints..."
API_URL="${{ needs.deploy-server.outputs.deploy-url }}"
echo "Testing API at: $API_URL"
# Test health endpoint
curl -f \
-H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" \
-H "Accept: application/json" \
"$API_URL/api/health"
echo "✅ Health endpoint working"
# Test clean endpoint
curl -f -X POST "$API_URL/api/clean" \
-H "Content-Type: application/json" \
-H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" \
-d '{"url": "https://example.com?utm_source=test"}'
echo "✅ Clean endpoint working"
- name: Test mobile app
run: |
echo "🧪 Testing mobile app..."
MOBILE_URL="${{ needs.deploy-web.outputs.deploy-url }}"
echo "Testing mobile app at: $MOBILE_URL"
# Test mobile app loads
curl -f -H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" "$MOBILE_URL"
echo "✅ Mobile app loading"
# Test mobile app assets
curl -f -H "x-vercel-protection-bypass: $VERCEL_AUTOMATION_BYPASS_SECRET" "$MOBILE_URL/manifest.json"
echo "✅ Mobile app assets working"
- name: Deployment summary
run: |
echo "🎉 All deployments successful!"
echo "📱 Mobile App: ${{ needs.deploy-web.outputs.deploy-url }}"
echo "🔧 API Server: ${{ needs.deploy-server.outputs.deploy-url }}"
echo "🏥 Health Check: ${{ needs.deploy-server.outputs.deploy-url }}/api/health"
echo ""
echo "Production URLs (after promotion):"
echo "📱 Mobile App: https://traceoff.vercel.app"
echo "🔧 API Server: https://traceoffapi.vercel.app"