-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathauto-copilot-test-review-playwright.yml
More file actions
476 lines (218 loc) · 9.38 KB
/
auto-copilot-test-review-playwright.yml
File metadata and controls
476 lines (218 loc) · 9.38 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
name: "Comprehensive Test Review with Playwright"
on:
push:
branches:
- main
- master
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: write
pull-requests: write
checks: write
jobs:
test-review-and-execution:
runs-on: self-hosted
strategy:
matrix:
browser: [chromium, firefox, webkit]
mode: [headed, headless]
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Setup Node.js
uses: actions/setup-node@main
with:
node-version: '20'
cache: 'npm'
continue-on-error: true
- name: Setup Python
uses: actions/setup-python@main
with:
python-version: '3.11'
cache: 'pip'
continue-on-error: true
- name: Install Node.js dependencies
run: |
if [ -f "package.json" ]; then
npm install
npm install -D @playwright/test playwright
fi
continue-on-error: true
- name: Install Python dependencies
run: |
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
fi
pip install pytest playwright pytest-playwright
continue-on-error: true
- name: Install Playwright browsers
run: |
npx playwright install --with-deps ${{ matrix.browser }} || python -m playwright install --with-deps ${{ matrix.browser }}
continue-on-error: true
- name: Verify Playwright installation
run: |
echo "Checking Playwright installation..."
npx playwright --version || python -m playwright --version || echo "Playwright not installed"
- name: Run Playwright Tests (Headless)
if: matrix.mode == 'headless'
run: |
if [ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]; then
npx playwright test --browser=${{ matrix.browser }}
elif [ -d "tests" ] && find tests -name "*test*.py" -o -name "*_test.py" | grep -q .; then
pytest tests/ --browser ${{ matrix.browser }} --headed=false
else
echo "No Playwright tests found - this is OK if not a web project"
fi
env:
CI: true
continue-on-error: true
- name: Run Playwright Tests (Headed)
if: matrix.mode == 'headed'
run: |
if [ -f "playwright.config.ts" ] || [ -f "playwright.config.js" ]; then
npx playwright test --browser=${{ matrix.browser }} --headed
elif [ -d "tests" ] && find tests -name "*test*.py" -o -name "*_test.py" | grep -q .; then
pytest tests/ --browser ${{ matrix.browser }} --headed=true
else
echo "No Playwright tests found - this is OK if not a web project"
fi
env:
CI: true
DISPLAY: :99
continue-on-error: true
- name: Upload Playwright Test Results
uses: actions/upload-artifact@main
if: always()
with:
name: playwright-results-${{ matrix.browser }}-${{ matrix.mode }}
path: |
playwright-report/
test-results/
playwright-traces/
retention-days: 30
continue-on-error: true
- name: Upload Playwright Screenshots on Failure
uses: actions/upload-artifact@main
if: failure()
with:
name: playwright-screenshots-${{ matrix.browser }}-${{ matrix.mode }}
path: |
screenshots/
test-results/**/screenshots/
retention-days: 7
continue-on-error: true
test-coverage-review:
runs-on: self-hosted
needs: test-review-and-execution
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Analyze Test Coverage
id: coverage
run: |
echo "## Test Coverage Analysis" > /tmp/test-analysis.md
echo "" >> /tmp/test-analysis.md
# Find test files
echo "### Test Files Found:" >> /tmp/test-analysis.md
find . -type f \( -name "*test*.js" -o -name "*test*.ts" -o -name "*test*.py" -o -name "*spec*.js" -o -name "*spec*.ts" \) \
! -path "*/node_modules/*" \
! -path "*/dist/*" \
! -path "*/.venv/*" \
-exec echo "- {}" \; >> /tmp/test-analysis.md || echo "No test files found" >> /tmp/test-analysis.md
echo "" >> /tmp/test-analysis.md
echo "### Source Files Without Tests:" >> /tmp/test-analysis.md
# Find source files that might need tests
for file in $(find . -type f \( -name "*.js" -o -name "*.ts" -o -name "*.py" \) \
! -path "*/node_modules/*" \
! -path "*/dist/*" \
! -path "*/build/*" \
! -path "*/.venv/*" \
! -path "*/vendor/*" \
! -name "*test*" \
! -name "*spec*"); do
basename=$(basename "$file" | sed 's/\.[^.]*$//')
# Check if corresponding test file exists
if ! find . -name "*${basename}*test*" -o -name "*${basename}*spec*" 2>/dev/null | grep -q .; then
echo "- $file (no corresponding test found)" >> /tmp/test-analysis.md
fi
done
cat /tmp/test-analysis.md
- name: GitHub Copilot Test Review
uses: github/copilot-cli-action@main
with:
query: |
Review the test suite for this repository:
1. Verify all web-based functionality has Playwright tests (both headed and headless)
2. Identify missing test coverage for critical functionality
3. Check test quality and maintainability
4. Suggest improvements for test organization
5. Verify tests follow best practices (isolation, clarity, proper assertions)
6. Check for flaky tests or tests with timing issues
7. Ensure tests are running in CI/CD pipeline
For any web tests not using Playwright, recommend migration.
Provide specific, actionable recommendations with file names.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Create or Update Test Review Issue
uses: actions/github-script@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const analysis = fs.readFileSync('/tmp/test-analysis.md', 'utf8');
const date = new Date().toISOString().split('T')[0];
const title = `Test Coverage Review - ${date}`;
const body = `# Comprehensive Test Review
This automated review ensures proper test coverage with Playwright for web tests.
${analysis}
## Playwright Test Status
✅ Tests run in multiple browsers: Chromium, Firefox, WebKit
✅ Tests run in both headed and headless modes
## Recommendations
1. **Add Playwright tests** for all web-based functionality
2. **Migrate existing web tests** to Playwright if not already using it
3. **Add tests** for source files without coverage
4. **Review test quality** and maintainability
5. **Fix flaky tests** and timing issues
6. **Ensure CI/CD integration** for all tests
## Action Items
- [ ] Review files without tests and add coverage
- [ ] Migrate non-Playwright web tests to Playwright
- [ ] Fix any failing tests
- [ ] Add documentation for test setup and execution
---
*This issue was automatically generated by the Test Review workflow.*
`;
// Check if similar issue exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: ['test-coverage', 'automated'],
per_page: 10
});
const recentIssue = issues.data.find(issue => {
const createdAt = new Date(issue.created_at);
const daysSinceCreation = (Date.now() - createdAt) / (1000 * 60 * 60 * 24);
return daysSinceCreation < 7;
});
if (recentIssue) {
console.log(`Recent issue found: #${recentIssue.number}, updating`);
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: recentIssue.number,
body: `## Updated Analysis (${date})\n\n${analysis}`
});
} else {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['test-coverage', 'automated', 'playwright', 'needs-review']
});
}