-
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
239 lines (203 loc) · 8.4 KB
/
auto-copilot-test-review-playwright.yml
File metadata and controls
239 lines (203 loc) · 8.4 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
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: ubuntu-latest
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: ubuntu-latest
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
# Note: GitHub Copilot CLI action is not available as a public action
# Test analysis is already performed in the previous step
- 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']
});
}