Repository navigation
346 lines (292 loc) Β· 12.7 KB
/
Copy pathperformance-testing.yml
File metadata and controls
346 lines (292 loc) Β· 12.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
name: π Performance Testing
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [opened, synchronize, reopened]
schedule:
# Run weekly performance checks
- cron: '0 6 * * 1'
workflow_dispatch:
inputs:
test_type:
description: 'Type of performance test'
required: true
default: 'lighthouse'
type: choice
options:
- lighthouse
- load
- comprehensive
# Prevent concurrent performance tests
concurrency:
group: performance-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '18'
PERFORMANCE_BUDGET_CPU: '85' # Performance budget for CPU score
PERFORMANCE_BUDGET_MEMORY: '90' # Performance budget for memory score
LIGHTHOUSE_MIN_SCORE: '60' # Reduced from 70 for CI stability and gradual improvement
jobs:
# Lighthouse Performance Testing
lighthouse-audit:
name: π Lighthouse Performance Audit
runs-on: ubuntu-latest
timeout-minutes: 10 # Reduced from 15 to fail faster
if: github.event.inputs.test_type == 'lighthouse' || github.event.inputs.test_type == 'comprehensive' || github.event.inputs.test_type == '' || github.event_name == 'push' || github.event_name == 'pull_request'
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
npm install -g @lhci/cli
- name: ποΈ Build application
run: npm run build
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: π Start production server
run: |
echo "Starting server with optimizations for CI..."
NODE_ENV=production NODE_OPTIONS="--max-old-space-size=1024" npm start &
SERVER_PID=$!
echo "SERVER_PID=$SERVER_PID" >> $GITHUB_ENV
env:
PORT: 3000
NODE_ENV: production
# Disable verbose logging for performance
NEXT_TELEMETRY_DISABLED: 1
# Memory optimization
NODE_OPTIONS: "--max-old-space-size=1024"
- name: β³ Wait for server to be ready
run: |
echo "Waiting for server to start..."
npx wait-on http://localhost:3000 --timeout 45000 --interval 2000
echo "Server is responding, waiting additional 5s for full startup..."
sleep 5
# Test server is actually serving content
echo "Testing server response..."
curl -f -s -o /dev/null http://localhost:3000 || (echo "β Server not responding properly" && exit 1)
echo "β
Server is ready for Lighthouse audit"
- name: π Run Lighthouse CI
run: |
echo "Starting Lighthouse CI audit..."
echo "Testing basic connectivity first:"
curl -I http://localhost:3000
echo "Running Lighthouse CI with optimized settings..."
timeout 300s lhci autorun --config=./lighthouserc.js || (echo "β οΈ Lighthouse audit timed out or failed" && exit 1)
timeout-minutes: 6 # Hard timeout for this step
- name: π Upload Lighthouse reports
uses: actions/upload-artifact@v4
if: always()
with:
name: lighthouse-reports-${{ github.run_number }}
path: |
.lighthouseci/
reports/
retention-days: 14
- name: π¨ Check performance budgets
run: |
# Parse Lighthouse results and check budgets with improved logic
if [ -f ".lighthouseci/manifest.json" ]; then
echo "Checking Lighthouse performance budgets..."
# Extract scores from manifest with better handling
PERF_SCORE=$(cat .lighthouseci/manifest.json | jq -r '.[0].summary.performance // 0' | awk '{printf "%.0f", $1 * 100}')
ACCESSIBILITY_SCORE=$(cat .lighthouseci/manifest.json | jq -r '.[0].summary.accessibility // 0' | awk '{printf "%.0f", $1 * 100}')
echo "Performance Score: $PERF_SCORE%"
echo "Accessibility Score: $ACCESSIBILITY_SCORE%"
# Check against budget with improved logic
if [ "$PERF_SCORE" -lt "${{ env.LIGHTHOUSE_MIN_SCORE }}" ]; then
echo "β οΈ Performance score ($PERF_SCORE%) is below budget (${{ env.LIGHTHOUSE_MIN_SCORE }}%) but proceeding with warnings"
echo "This indicates areas for performance improvement in future iterations"
else
echo "β
Performance score ($PERF_SCORE%) meets budget (${{ env.LIGHTHOUSE_MIN_SCORE }}%)"
fi
if [ "$ACCESSIBILITY_SCORE" -lt "90" ]; then
echo "β οΈ Accessibility score ($ACCESSIBILITY_SCORE%) is below 90% - please review accessibility issues"
else
echo "β
Accessibility score ($ACCESSIBILITY_SCORE%) meets requirements"
fi
echo "β
Performance audit completed"
else
echo "β οΈ No Lighthouse manifest found, Lighthouse may have failed to generate results"
echo "This could indicate server startup issues or timeout problems"
fi
- name: π§Ή Cleanup
if: always()
run: |
if [ ! -z "$SERVER_PID" ]; then
echo "Stopping server (PID: $SERVER_PID)..."
kill $SERVER_PID || true
fi
# Load Testing with k6
load-testing:
name: β‘ Load Testing
runs-on: ubuntu-latest
timeout-minutes: 20
if: github.event.inputs.test_type == 'load' || github.event.inputs.test_type == 'comprehensive' || github.event_name == 'schedule' || github.event_name == 'push' || github.event_name == 'pull_request'
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 k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: π¦ Install dependencies
run: npm ci
- name: ποΈ Build application
run: npm run build
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
- name: π Start production server
run: npm start &
env:
PORT: 3000
NODE_ENV: production
- name: β³ Wait for server to be ready
run: |
npx wait-on http://localhost:3000 --timeout 60000
echo "Server is responding, waiting additional 10s for full startup..."
sleep 10
# Test server is actually serving content
curl -f http://localhost:3000 || exit 1
echo "β
Server is fully ready for load testing"
- name: β‘ Run k6 load tests
run: |
echo "Starting k6 load test against http://localhost:3000"
npm run test:load:basic
continue-on-error: true
- name: π Upload load test reports
uses: actions/upload-artifact@v4
if: always()
with:
name: load-test-reports-${{ github.run_number }}
path: |
tests/load/results/
reports/performance/
retention-days: 14
- name: π¨ Analyze load test results
run: |
echo "Load test completed"
echo "Check detailed results in test artifacts"
# k6 outputs to stdout, basic check if any errors occurred
if [ $? -eq 0 ]; then
echo "β
Load test completed successfully"
else
echo "β οΈ Load test completed with warnings/errors"
fi
# Resource profiling moved to dedicated workflow: performance-profiling.yml
# This keeps the main performance testing workflow fast and focused
# Bundle analysis
bundle-analysis:
name: π¦ Bundle Size Analysis
runs-on: ubuntu-latest
timeout-minutes: 10
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 with bundle analysis
run: npm run build:analyze
env:
NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}
NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}
ANALYZE: true
- name: π Check bundle size budgets
run: |
echo "Checking bundle size budgets..."
# Check if bundle size report exists
if [ -f ".next/analyze/bundle-sizes.json" ]; then
TOTAL_SIZE=$(cat .next/analyze/bundle-sizes.json | jq -r '.sizes.total // 0')
JS_SIZE=$(cat .next/analyze/bundle-sizes.json | jq -r '.sizes.javascript // 0')
echo "Total Bundle Size: ${TOTAL_SIZE}KB"
echo "JavaScript Size: ${JS_SIZE}KB"
# Budget checks (in KB)
if [ "$TOTAL_SIZE" -gt 1000 ]; then
echo "β οΈ Total bundle size (${TOTAL_SIZE}KB) exceeds budget (1000KB)"
fi
if [ "$JS_SIZE" -gt 500 ]; then
echo "β οΈ JavaScript bundle size (${JS_SIZE}KB) exceeds budget (500KB)"
fi
echo "β
Bundle analysis complete"
else
echo "π Running basic bundle size check..."
find .next -name "*.js" -type f -exec du -ch {} + | grep total
fi
- name: π Upload bundle analysis
uses: actions/upload-artifact@v4
if: always()
with:
name: bundle-analysis-${{ github.run_number }}
path: |
.next/analyze/
reports/bundle/
retention-days: 14
# Performance summary
performance-summary:
name: π Performance Summary
runs-on: ubuntu-latest
if: always()
needs: [lighthouse-audit, load-testing, bundle-analysis]
steps:
- name: π Create performance summary
uses: actions/github-script@v7
with:
script: |
const results = {
'Lighthouse Audit': '${{ needs.lighthouse-audit.result }}',
'Load Testing': '${{ needs.load-testing.result }}',
'Bundle Analysis': '${{ needs.bundle-analysis.result }}'
};
let summary = '## π Performance Test Results\n\n';
summary += '| Test Type | Status | Details |\n';
summary += '|-----------|--------|----------|\n';
for (const [test, status] of Object.entries(results)) {
const emoji = status === 'success' ? 'β
' :
status === 'failure' ? 'β' :
status === 'skipped' ? 'βοΈ' : 'β³';
let details = '';
if (status === 'success') {
details = 'All metrics within budget';
} else if (status === 'failure') {
details = 'Some metrics exceeded budget';
} else if (status === 'skipped') {
details = 'Test skipped for this run';
}
summary += `| ${test} | ${emoji} ${status} | ${details} |\n`;
}
summary += '\n### π Performance Metrics\n\n';
summary += '- **Lighthouse Score**: Target β₯85\n';
summary += '- **Response Time**: Target <2s average\n';
summary += '- **P95 Response**: Target <5s\n';
summary += '- **Bundle Size**: Target <1MB total\n';
summary += '- **Error Rate**: Target <5%\n\n';
if (Object.values(results).includes('failure')) {
summary += 'β οΈ **Performance issues detected.** Check detailed reports in artifacts.\n\n';
} else {
summary += 'π **All performance tests passed!**\n\n';
}
summary += '_Performance tests help ensure LocalLoop remains fast and responsive._';
console.log(summary);