-
Notifications
You must be signed in to change notification settings - Fork 0
536 lines (460 loc) · 16.7 KB
/
e2e-testing.yml
File metadata and controls
536 lines (460 loc) · 16.7 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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
name: E2E Testing Pipeline
on:
push:
branches: [ main, develop, feature/* ]
pull_request:
branches: [ main, develop ]
schedule:
# Run nightly at 2 AM UTC for comprehensive testing
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
test_suite:
description: 'Test suite to run'
required: true
default: 'all'
type: choice
options:
- all
- marketplace
- performance
- chaos
- resilience
environment:
description: 'Environment to test against'
required: true
default: 'development'
type: choice
options:
- development
- staging
- production
chaos_intensity:
description: 'Chaos testing intensity'
required: false
default: 'medium'
type: choice
options:
- low
- medium
- high
- extreme
env:
NODE_VERSION: '18'
PLAYWRIGHT_VERSION: '1.40.0'
jobs:
# Job 1: Basic validation and setup
setup-and-validate:
name: Setup and Validate Environment
runs-on: ubuntu-latest
outputs:
test-matrix: ${{ steps.test-matrix.outputs.matrix }}
should-run-chaos: ${{ steps.conditions.outputs.chaos }}
should-run-performance: ${{ steps.conditions.outputs.performance }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps
- name: Validate test environment
run: |
npm run type-check
npm run lint
npx playwright --version
- name: Build application
run: npm run build
- name: Determine test conditions
id: conditions
run: |
# Determine what tests to run based on trigger and inputs
if [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "chaos=true" >> $GITHUB_OUTPUT
echo "performance=true" >> $GITHUB_OUTPUT
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.inputs.test_suite }}" == "all" || "${{ github.event.inputs.test_suite }}" == "chaos" ]]; then
echo "chaos=true" >> $GITHUB_OUTPUT
else
echo "chaos=false" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.event.inputs.test_suite }}" == "all" || "${{ github.event.inputs.test_suite }}" == "performance" ]]; then
echo "performance=true" >> $GITHUB_OUTPUT
else
echo "performance=false" >> $GITHUB_OUTPUT
fi
else
echo "chaos=false" >> $GITHUB_OUTPUT
echo "performance=true" >> $GITHUB_OUTPUT
fi
- name: Generate test matrix
id: test-matrix
run: |
# Generate dynamic test matrix based on conditions
MATRIX='{"include":['
# Always run marketplace tests
MATRIX+='{
"suite": "marketplace",
"browser": "chromium",
"organization": "swaggystacks",
"timeout": 300000
},'
MATRIX+='{
"suite": "marketplace",
"browser": "chromium",
"organization": "scientia",
"timeout": 300000
},'
# Add performance tests if needed
if [[ "${{ steps.conditions.outputs.performance }}" == "true" ]]; then
MATRIX+='{
"suite": "performance",
"browser": "chromium",
"organization": "swaggystacks",
"timeout": 600000
},'
fi
# Add chaos tests if needed
if [[ "${{ steps.conditions.outputs.chaos }}" == "true" ]]; then
MATRIX+='{
"suite": "chaos",
"browser": "chromium",
"organization": "swaggystacks",
"timeout": 900000
},'
fi
# Remove trailing comma and close matrix
MATRIX=${MATRIX%,}
MATRIX+=']}'
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
echo "Generated test matrix: $MATRIX"
# Job 2: Core marketplace testing
marketplace-tests:
name: Marketplace Tests (${{ matrix.organization }})
runs-on: ubuntu-latest
needs: setup-and-validate
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
organization: [swaggystacks, scientia]
browser: [chromium, firefox, webkit]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps ${{ matrix.browser }}
- name: Start development server
run: |
npm run dev &
sleep 10
curl -f http://localhost:3001 || exit 1
- name: Run marketplace E2E tests
env:
TEST_ORGANIZATION: ${{ matrix.organization }}
PLAYWRIGHT_BROWSER: ${{ matrix.browser }}
run: |
npx playwright test tests/e2e/marketplace/ \
--reporter=html,junit \
--output-dir=test-results/${{ matrix.organization }}-${{ matrix.browser }}
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: marketplace-results-${{ matrix.organization }}-${{ matrix.browser }}
path: |
test-results/
playwright-report/
retention-days: 7
# Job 3: Performance testing
performance-tests:
name: Performance Tests
runs-on: ubuntu-latest
needs: [setup-and-validate]
if: needs.setup-and-validate.outputs.should-run-performance == 'true'
timeout-minutes: 45
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Start development server
run: |
npm run dev &
sleep 15
curl -f http://localhost:3001 || exit 1
- name: Run performance tests
env:
PERFORMANCE_BUDGET_MS: 3000
MEMORY_THRESHOLD_MB: 100
run: |
npx playwright test tests/e2e/performance/ \
--reporter=html,json \
--output-dir=test-results/performance
- name: Analyze performance metrics
run: |
# Extract performance metrics from test results
node -e "
const fs = require('fs');
try {
const results = JSON.parse(fs.readFileSync('test-results/performance/results.json', 'utf8'));
console.log('Performance Test Summary:');
console.log('- Tests run:', results.stats.total);
console.log('- Tests passed:', results.stats.passed);
console.log('- Average duration:', Math.round(results.stats.duration / results.stats.total), 'ms');
} catch (e) {
console.log('No performance results to analyze');
}
"
- name: Upload performance results
uses: actions/upload-artifact@v4
if: always()
with:
name: performance-results
path: |
test-results/performance/
playwright-report/
retention-days: 14
# Job 4: Chaos and resilience testing
chaos-tests:
name: Chaos & Resilience Tests
runs-on: ubuntu-latest
needs: [setup-and-validate]
if: needs.setup-and-validate.outputs.should-run-chaos == 'true'
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: |
npm ci
npx playwright install --with-deps chromium
- name: Start development server
run: |
npm run dev &
sleep 15
curl -f http://localhost:3001 || exit 1
- name: Run chaos testing
env:
CHAOS_INTENSITY: ${{ github.event.inputs.chaos_intensity || 'medium' }}
MAX_RECOVERY_TIME_MS: 30000
run: |
npx playwright test tests/e2e/chaos/ \
--reporter=html,json \
--output-dir=test-results/chaos \
--timeout=900000
- name: Analyze resilience metrics
run: |
# Extract resilience metrics
node -e "
const fs = require('fs');
try {
const results = JSON.parse(fs.readFileSync('test-results/chaos/results.json', 'utf8'));
console.log('Chaos Testing Summary:');
console.log('- Scenarios tested:', results.stats.total);
console.log('- Recovery success rate:', Math.round((results.stats.passed / results.stats.total) * 100), '%');
// Check for SLA compliance
if (results.stats.passed / results.stats.total < 0.8) {
console.error('❌ Resilience SLA not met (< 80% success rate)');
process.exit(1);
} else {
console.log('✅ Resilience SLA met (≥ 80% success rate)');
}
} catch (e) {
console.log('No chaos results to analyze');
}
"
- name: Upload chaos test results
uses: actions/upload-artifact@v4
if: always()
with:
name: chaos-results
path: |
test-results/chaos/
playwright-report/
retention-days: 30
# Job 5: Test result aggregation and reporting
aggregate-results:
name: Aggregate Test Results
runs-on: ubuntu-latest
needs: [marketplace-tests, performance-tests, chaos-tests]
if: always()
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all test artifacts
uses: actions/download-artifact@v4
with:
path: all-test-results/
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Generate comprehensive test report
run: |
node -e "
const fs = require('fs');
const path = require('path');
console.log('# E2E Test Pipeline Summary');
console.log('');
console.log('## Test Execution Results');
let totalTests = 0;
let totalPassed = 0;
let totalFailed = 0;
// Aggregate results from all test suites
const resultDirs = fs.readdirSync('all-test-results/', { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
for (const dir of resultDirs) {
console.log(\`### \${dir.replace(/-/g, ' ').toUpperCase()}\`);
try {
const resultFiles = fs.readdirSync(\`all-test-results/\${dir}/test-results/\`);
console.log(\`- Artifacts found: \${resultFiles.length} files\`);
// Look for JUnit XML files for more detailed analysis
const junitFiles = resultFiles.filter(f => f.endsWith('.xml'));
if (junitFiles.length > 0) {
console.log(\`- JUnit reports: \${junitFiles.length}\`);
}
} catch (e) {
console.log('- No detailed results available');
}
console.log('');
}
console.log('## Pipeline Status');
console.log('- Marketplace Tests: ${{ needs.marketplace-tests.result }}');
console.log('- Performance Tests: ${{ needs.performance-tests.result }}');
console.log('- Chaos Tests: ${{ needs.chaos-tests.result }}');
console.log('');
// Determine overall pipeline result
const results = [
'${{ needs.marketplace-tests.result }}',
'${{ needs.performance-tests.result }}',
'${{ needs.chaos-tests.result }}'
].filter(r => r !== 'skipped');
const hasFailures = results.includes('failure');
const hasCancelled = results.includes('cancelled');
if (hasFailures) {
console.log('❌ **PIPELINE FAILED** - Critical test failures detected');
process.exit(1);
} else if (hasCancelled) {
console.log('⚠️ **PIPELINE INCOMPLETE** - Some tests were cancelled');
} else {
console.log('✅ **PIPELINE PASSED** - All tests completed successfully');
}
" > test-summary.md
- name: Upload aggregated results
uses: actions/upload-artifact@v4
with:
name: pipeline-summary
path: |
test-summary.md
all-test-results/
retention-days: 30
- name: Comment test results on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const summary = fs.readFileSync('test-summary.md', 'utf8');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## 🧪 E2E Test Pipeline Results\n\n${summary}`
});
# Job 6: Deployment validation (only on main branch)
deployment-validation:
name: Deployment Validation
runs-on: ubuntu-latest
needs: [marketplace-tests, performance-tests]
if: |
github.ref == 'refs/heads/main' &&
needs.marketplace-tests.result == 'success' &&
(needs.performance-tests.result == 'success' || needs.performance-tests.result == 'skipped')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build for production
run: npm run build
- name: Validate deployment readiness
run: |
echo "🚀 Validating deployment readiness..."
# Check if build artifacts exist
if [[ ! -d ".next" ]]; then
echo "❌ Build artifacts not found"
exit 1
fi
# Check build size
BUILD_SIZE=$(du -sh .next | cut -f1)
echo "📦 Build size: $BUILD_SIZE"
# Run basic smoke tests on production build
npm run start &
SERVER_PID=$!
sleep 15
# Test both organization routes
curl -f http://localhost:3000/swaggystacks || exit 1
curl -f http://localhost:3000/scientia || exit 1
curl -f http://localhost:3000/marketplace || exit 1
kill $SERVER_PID
echo "✅ Deployment validation passed"
- name: Set deployment status
run: |
echo "DEPLOYMENT_READY=true" >> $GITHUB_ENV
echo "🎯 Ready for deployment to production"
# Notification job for important events
notify-results:
name: Notify Results
runs-on: ubuntu-latest
needs: [marketplace-tests, performance-tests, chaos-tests, aggregate-results]
if: always() && (github.event_name == 'schedule' || github.ref == 'refs/heads/main')
steps:
- name: Send notification
run: |
# Determine notification level
if [[ "${{ needs.marketplace-tests.result }}" == "failure" ]]; then
LEVEL="🚨 CRITICAL"
MESSAGE="Marketplace tests failed - immediate attention required"
elif [[ "${{ needs.chaos-tests.result }}" == "failure" ]]; then
LEVEL="⚠️ WARNING"
MESSAGE="Resilience tests failed - system may not handle failures gracefully"
elif [[ "${{ needs.performance-tests.result }}" == "failure" ]]; then
LEVEL="📊 PERFORMANCE"
MESSAGE="Performance tests failed - system may not meet SLA requirements"
else
LEVEL="✅ SUCCESS"
MESSAGE="All E2E tests passed successfully"
fi
echo "$LEVEL: $MESSAGE"
echo "GitHub Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"