-
-
Notifications
You must be signed in to change notification settings - Fork 11
474 lines (415 loc) · 15.9 KB
/
test.yml
File metadata and controls
474 lines (415 loc) · 15.9 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
name: 🧪 Test
on:
workflow_dispatch:
inputs:
frameworks:
description: 'Frameworks to test (comma-separated, see frameworks.json for available options)'
required: false
default: 'all'
type: string
pull_request:
branches: [ main, dev ]
types: [ opened, synchronize, reopened ]
push:
branches: [ main ]
paths:
- 'apps/**'
- 'frameworks.json'
- 'config.json'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
actions: read
env:
NODE_VERSION: '18'
PYTHON_VERSION: '3.9'
jobs:
setup:
name: Setup and Sync Assets
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
frameworks: ${{ steps.matrix.outputs.frameworks }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: scripts/requirements.txt
- name: Install Python dependencies
run: pip install -r scripts/requirements.txt
- name: Install root dependencies
run: |
npm ci
npx playwright install --with-deps
- name: Run Python setup script
run: python scripts/setup/main.py --skip-build
- name: Cache node_modules and Playwright browsers
uses: actions/cache@v4
with:
path: |
node_modules
apps/*/node_modules
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-playwright-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-modules-playwright-
${{ runner.os }}-node-modules-
- name: Determine frameworks to test
id: matrix
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.frameworks }}" != "all" ]; then
frameworks="${{ github.event.inputs.frameworks }}"
else
# Get framework list from Python config
frameworks=$(python scripts/get_frameworks.py)
fi
echo "frameworks=$(echo "[$frameworks]" | sed 's/,/", "/g' | sed 's/\[/[\"/ ; s/\]/\"]/')" >> $GITHUB_OUTPUT
echo "Testing frameworks: $frameworks"
test:
name: Test ${{ matrix.framework }}
needs: setup
if: fromJSON(needs.setup.outputs.frameworks)[0] != ''
runs-on: ubuntu-latest
timeout-minutes: 15
continue-on-error: true
strategy:
fail-fast: false
matrix:
framework: ${{ fromJSON(needs.setup.outputs.frameworks) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: scripts/requirements.txt
- name: Install Python dependencies
run: pip install -r scripts/requirements.txt
- name: Restore dependencies cache
uses: actions/cache@v4
with:
path: |
node_modules
apps/*/node_modules
~/.cache/ms-playwright
key: ${{ runner.os }}-node-modules-playwright-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies (if cache miss)
run: |
if [ ! -d "node_modules" ]; then
echo "Dependencies cache miss - installing"
npm ci
else
echo "Dependencies cache hit"
fi
- name: Add node_modules/.bin to PATH
run: echo "${{ github.workspace }}/node_modules/.bin" >> $GITHUB_PATH
- name: Install Playwright browsers (if cache miss)
run: |
if [ ! -d ~/.cache/ms-playwright ]; then
echo "Playwright cache miss - installing browsers"
npx playwright install --with-deps
else
echo "Playwright cache hit - skipping browser installation"
fi
- name: Verify Playwright installation
run: |
echo "Checking @playwright/test availability..."
if [ -f "node_modules/@playwright/test/package.json" ]; then
echo "✅ @playwright/test found in node_modules"
else
echo "❌ @playwright/test not found, forcing npm ci"
npm ci
fi
- name: Run setup for project preparation
run: |
python scripts/setup/main.py --skip-build
- name: Run tests for ${{ matrix.framework }}
id: test-run
uses: nick-fields/retry@v2
with:
timeout_minutes: 10
max_attempts: 4
retry_wait_seconds: 30
command: |
echo "🧪 Running ${{ matrix.framework }} tests (attempt ${{ github.run_attempt }})"
# Add framework context to test output for better annotations
echo "::group::${{ matrix.framework }} Framework Tests"
npm run test:${{ matrix.framework }} -- --reporter=github --reporter=list
echo "::endgroup::"
- name: Create detailed result file
if: always()
run: |
mkdir -p test-status test-details
# Determine final status (failed if all retries exhausted)
if [[ "${{ steps.test-run.outcome }}" == "success" ]]; then
status="passed"
icon="✅"
else
status="failed"
icon="❌"
fi
# Create status file
echo "$status" > test-status/${{ matrix.framework }}.txt
# Create detailed results file
cat > test-details/${{ matrix.framework }}.json << EOF
{
"framework": "${{ matrix.framework }}",
"status": "$status",
"icon": "$icon",
"attempts": ${{ steps.test-run.outputs.total_attempts || '1' }},
"final_attempt": ${{ steps.test-run.outputs.exit_code || '0' }},
"duration": "${{ steps.test-run.outputs.elapsed_time || 'unknown' }}",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"runner": "${{ runner.os }}",
"node_version": "$(node --version)",
"playwright_version": "$(npx playwright --version | head -1)"
}
EOF
- name: Upload test results (conditional)
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.framework }}-test-results
path: |
playwright-report/
test-results/
if-no-files-found: ignore
retention-days: 30
- name: Upload test status and details
if: always()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.framework }}-status
path: |
test-status/${{ matrix.framework }}.txt
test-details/${{ matrix.framework }}.json
retention-days: 7
- name: Generate test badge
if: always()
run: |
# Determine badge status and color
if [[ "${{ steps.test-run.outcome }}" == "success" ]]; then
status="Passing"
color="3cd96b"
label_color="33b348"
else
attempts="${{ steps.test-run.outputs.total_attempts || '1' }}"
if [[ "$attempts" -gt "1" ]]; then
status="Unstable"
color="fb974e"
label_color="d58144"
else
status="Failing"
color="ff5666"
label_color="d5334a"
fi
fi
# Generate badge
badge_url="https://img.shields.io/badge/Tests-${status}-${color}?logo=vitest&logoColor=fff&labelColor=${label_color}"
curl -o "test-${{ matrix.framework }}.svg" "$badge_url"
- name: Upload badge
if: always()
uses: actions/upload-artifact@v4
with:
name: badge-test-${{ matrix.framework }}
path: test-${{ matrix.framework }}.svg
retention-days: 1
summary:
name: Test Summary
needs: [setup, test]
if: always()
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Download all test status artifacts
if: always()
uses: actions/download-artifact@v4
with:
pattern: "*-status"
path: test-artifacts
merge-multiple: true
- name: Generate test summary
run: |
cd test-artifacts || exit 1
# Get frameworks and initialize counters
frameworks="${{ needs.setup.outputs.frameworks }}"
frameworks_array=($(echo "$frameworks" | tr -d '[]"' | tr ',' '\n' | xargs))
passed_count=0
failed_count=0
total_count=${#frameworks_array[@]}
# Generate summary header
{
echo "# 🧪 Test Results Summary"
echo ""
success_rate=$(( (total_count - failed_count) * 100 / total_count ))
if [[ $failed_count -eq 0 ]]; then
echo "> 🎉 **Perfect score!** All ${total_count} frameworks passed their tests."
elif [[ $success_rate -ge 80 ]]; then
echo "> ✅ **${success_rate}% success rate** - ${passed_count}/${total_count} frameworks passing."
else
echo "> ⚠️ **${success_rate}% success rate** - ${failed_count} frameworks need attention."
fi
echo ""
echo "| Framework | Status | Attempts |"
echo "|-----------|--------|----------|"
} >> "$GITHUB_STEP_SUMMARY"
# Process each framework
for framework in "${frameworks_array[@]}"; do
status_file="test-status/${framework}.txt"
details_file="test-details/${framework}.json"
if [[ -f "$status_file" ]]; then
status=$(cat "$status_file" 2>/dev/null || echo "unknown")
# Parse JSON details
attempts="1"
if [[ -f "$details_file" ]] && command -v jq >/dev/null 2>&1; then
attempts=$(jq -r '.attempts // "1"' "$details_file" 2>/dev/null || echo "1")
fi
# Build table row
if [[ "$status" == "passed" ]]; then
icon="✅"
passed_count=$((passed_count + 1))
else
icon="❌"
failed_count=$((failed_count + 1))
fi
echo "| **${framework}** | ${icon} **${status^}** | ${attempts} |" >> "$GITHUB_STEP_SUMMARY"
else
echo "| **${framework}** | ⚠️ **Missing** | - |" >> "$GITHUB_STEP_SUMMARY"
failed_count=$((failed_count + 1))
fi
done
# Add workflow information
{
echo ""
echo "**Workflow Info:** Triggered by ${{ github.event_name }} on \`${{ github.ref_name }}\` by @${{ github.actor }} | [View Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
} >> "$GITHUB_STEP_SUMMARY"
# Set environment variables
success_rate=$(( passed_count * 100 / total_count ))
echo "FAILED_COUNT=$failed_count" >> $GITHUB_ENV
echo "PASSED_COUNT=$passed_count" >> $GITHUB_ENV
echo "SUCCESS_RATE=$success_rate" >> $GITHUB_ENV
cd ..
- name: Set workflow status
run: |
echo "📊 Final Results:"
echo " ✅ Passed: $PASSED_COUNT"
echo " ❌ Failed: $FAILED_COUNT"
echo " 📈 Success Rate: $SUCCESS_RATE%"
if [[ "$FAILED_COUNT" -gt 0 ]]; then
echo ""
echo "❌ Some framework tests failed."
echo "ℹ️ This is expected behavior - the workflow continues even when individual frameworks fail."
echo "📋 Check the summary above for detailed results."
# Don't exit 1 here since we want the workflow to show as successful
# if it completed (even with some framework failures)
else
echo ""
echo "✅ All framework tests passed successfully. Party time! 🎉"
fi
- name: Create status badge data
if: always()
run: |
mkdir -p badge-data
# Calculate total frameworks from the array
frameworks="${{ needs.setup.outputs.frameworks }}"
frameworks_array=($(echo "$frameworks" | tr -d '[]"' | tr ',' '\n' | xargs))
total_count=${#frameworks_array[@]}
# Determine badge color (with null checks)
if [[ -z "$FAILED_COUNT" || -z "$SUCCESS_RATE" ]]; then
badge_color="lightgrey"
badge_message="unknown"
elif [ $FAILED_COUNT -eq 0 ]; then
badge_color="brightgreen"
badge_message="${PASSED_COUNT}/${total_count} passed"
elif [ $SUCCESS_RATE -ge 80 ]; then
badge_color="green"
badge_message="${PASSED_COUNT}/${total_count} passed"
elif [ $SUCCESS_RATE -ge 50 ]; then
badge_color="yellow"
badge_message="${PASSED_COUNT}/${total_count} passed"
else
badge_color="red"
badge_message="${PASSED_COUNT}/${total_count} passed"
fi
# Create badge JSON
cat > badge-data/test-results.json << EOF
{
"schemaVersion": 1,
"label": "tests",
"message": "${badge_message}",
"color": "${badge_color}",
"namedLogo": "playwright",
"logoColor": "white"
}
EOF
- name: Upload badge data
if: always()
uses: actions/upload-artifact@v4
with:
name: badge-data
path: badge-data/test-results.json
retention-days: 90
badges:
name: Update Test Badges
needs: [setup, test]
if: always()
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout with bot token
uses: actions/checkout@v4
with:
token: ${{ secrets.BOT_TOKEN }}
fetch-depth: 0
- name: Download all badges
uses: actions/download-artifact@v4
with:
pattern: badge-test-*
path: badges
merge-multiple: true
- name: Commit badges
run: |
git config user.name 'liss-bot'
git config user.email 'alicia-gh-bot@mail.as93.net'
# Switch to badges branch
git fetch origin badges:badges 2>/dev/null || git checkout --orphan badges
git checkout badges 2>/dev/null || true
git pull origin badges 2>/dev/null || true
# Copy badges and commit
cp badges/*.svg . 2>/dev/null || echo "⚠️ No badge files found"
if git add *.svg && git diff --staged --quiet; then
echo "ℹ️ No badge changes to commit"
else
git commit -m "Update test badges"
if git push origin badges; then
echo "✅ Successfully updated test badges"
else
echo "⚠️ Failed to push badge updates"
exit 1
fi
fi