Skip to content

Commit e343a13

Browse files
authored
feat: add flaky tests and bundle size (#1109)
1 parent 97013c3 commit e343a13

File tree

1 file changed

+119
-38
lines changed

1 file changed

+119
-38
lines changed

.github/workflows/ci.yml

+119-38
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,100 @@ jobs:
9090
9191
if [ -f "playwright-artifacts/test-results.json" ]; then
9292
echo "Parsing JSON file:"
93-
total=$(jq '.stats.expected + .stats.unexpected + .stats.skipped' playwright-artifacts/test-results.json)
93+
total=$(jq '.stats.expected + .stats.unexpected + .stats.flaky + .stats.skipped' playwright-artifacts/test-results.json)
9494
passed=$(jq '.stats.expected' playwright-artifacts/test-results.json)
9595
failed=$(jq '.stats.unexpected' playwright-artifacts/test-results.json)
96+
flaky=$(jq '.stats.flaky' playwright-artifacts/test-results.json)
9697
skipped=$(jq '.stats.skipped' playwright-artifacts/test-results.json)
9798
9899
echo "Parsed values:"
99100
echo "Total: $total"
100101
echo "Passed: $passed"
101102
echo "Failed: $failed"
103+
echo "Flaky: $flaky"
102104
echo "Skipped: $skipped"
103105
else
104106
echo "test-results.json file not found"
105107
total=0
106108
passed=0
107109
failed=0
110+
flaky=0
108111
skipped=0
109112
fi
110113
111114
echo "total=$total" >> $GITHUB_OUTPUT
112115
echo "passed=$passed" >> $GITHUB_OUTPUT
113116
echo "failed=$failed" >> $GITHUB_OUTPUT
117+
echo "flaky=$flaky" >> $GITHUB_OUTPUT
114118
echo "skipped=$skipped" >> $GITHUB_OUTPUT
115119
120+
bundle_size:
121+
name: Check Bundle Size
122+
runs-on: ubuntu-latest
123+
outputs:
124+
current_size: ${{ steps.current_size.outputs.size }}
125+
main_size: ${{ steps.main_size.outputs.size }}
126+
diff: ${{ steps.size_diff.outputs.diff }}
127+
percent: ${{ steps.size_diff.outputs.percent }}
128+
steps:
129+
- uses: actions/checkout@v4
130+
with:
131+
fetch-depth: 0
132+
133+
- name: Setup Node.js
134+
uses: actions/setup-node@v4
135+
with:
136+
node-version: 18
137+
cache: npm
138+
139+
- name: Install dependencies
140+
run: npm ci
141+
142+
- name: Build bundle (current branch)
143+
run: npm run build
144+
145+
- name: Get current bundle size
146+
id: current_size
147+
run: |
148+
size=$(du -sb build | cut -f1)
149+
echo "size=$size" >> $GITHUB_OUTPUT
150+
151+
- name: Checkout main branch
152+
uses: actions/checkout@v4
153+
with:
154+
ref: main
155+
156+
- name: Install dependencies (main)
157+
run: npm ci
158+
159+
- name: Build bundle (main branch)
160+
run: npm run build
161+
162+
- name: Get main bundle size
163+
id: main_size
164+
run: |
165+
size=$(du -sb build | cut -f1)
166+
echo "size=$size" >> $GITHUB_OUTPUT
167+
168+
- name: Calculate size difference
169+
id: size_diff
170+
run: |
171+
current=${{ steps.current_size.outputs.size }}
172+
main=${{ steps.main_size.outputs.size }}
173+
diff=$((current - main))
174+
if [ "$main" -ne "0" ]; then
175+
percent=$(awk "BEGIN {printf \"%.2f\", ($diff/$main) * 100}")
176+
else
177+
percent="N/A"
178+
fi
179+
echo "diff=$diff" >> $GITHUB_OUTPUT
180+
echo "percent=$percent" >> $GITHUB_OUTPUT
181+
116182
deploy_and_update:
117183
name: Deploy and Update PR
118-
needs: e2e_tests
119-
runs-on: ubuntu-latest
184+
needs: [e2e_tests, bundle_size]
120185
if: always() && github.event.pull_request.head.repo.full_name == github.repository
186+
runs-on: ubuntu-latest
121187
permissions:
122188
contents: write
123189
pages: write
@@ -155,46 +221,63 @@ jobs:
155221
const rawData = fs.readFileSync(testResultsPath);
156222
const data = JSON.parse(rawData);
157223
testResults = {
158-
total: data.stats.expected + data.stats.unexpected + data.stats.skipped,
224+
total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
159225
passed: data.stats.expected,
160226
failed: data.stats.unexpected,
227+
flaky: data.stats.flaky,
161228
skipped: data.stats.skipped
162229
};
163230
} else {
164231
console.log('Test results file not found');
165-
testResults = { total: 0, passed: 0, failed: 0, skipped: 0 };
232+
testResults = { total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0 };
166233
}
167234
168235
const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
169-
const status = testResults.failed > 0 ? '❌ FAILED' : '✅ PASSED';
170-
const statusColor = testResults.failed > 0 ? 'red' : 'green';
171-
172-
const testResultsSection = `## Playwright Test Results
173-
174-
**Status**: <span style="color: ${statusColor}; font-weight: bold;">${status}</span>
175-
176-
| Total | Passed | Failed | Skipped |
177-
|-------|--------|--------|---------|
178-
| ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.skipped} |
179-
180-
### 📊 Test Report
181-
182-
For detailed results, please check the [Playwright Report](${reportUrl})
183-
184-
### 🎥 Test Recordings
185-
186-
Video recordings of failed tests (if any) are available in the report.
187-
188-
---
236+
const status = testResults.failed > 0 ? '❌ FAILED' : (testResults.flaky > 0 ? '⚠️ FLAKY' : '✅ PASSED');
237+
const statusColor = testResults.failed > 0 ? 'red' : (testResults.flaky > 0 ? 'orange' : 'green');
238+
239+
const currentSize = parseInt('${{ needs.bundle_size.outputs.current_size }}');
240+
const mainSize = parseInt('${{ needs.bundle_size.outputs.main_size }}');
241+
const diff = parseInt('${{ needs.bundle_size.outputs.diff }}');
242+
const percent = '${{ needs.bundle_size.outputs.percent }}';
243+
244+
const formatSize = (size) => {
245+
if (size >= 1024) {
246+
return `${(size / (1024 * 1024)).toFixed(2)} MB`;
247+
}
248+
return `${(size / 1024).toFixed(2)} KB`;
249+
};
250+
251+
const bundleStatus = percent === 'N/A' ? '⚠️' :
252+
parseFloat(percent) > 0 ? '🔺' :
253+
parseFloat(percent) < 0 ? '🔽' : '✅';
254+
255+
const ciSection = `## CI Results
256+
257+
### Test Status: <span style="color: ${statusColor};">${status}</span>
258+
📊 [Full Report](${reportUrl})
259+
260+
| Total | Passed | Failed | Flaky | Skipped |
261+
|:-----:|:------:|:------:|:-----:|:-------:|
262+
| ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} |
263+
264+
### Bundle Size: ${bundleStatus}
265+
Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
266+
Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})
267+
268+
${
269+
percent === 'N/A' ? '⚠️ Unable to calculate change.' :
270+
parseFloat(percent) > 0 ? '⚠️ Bundle size increased. Please review.' :
271+
parseFloat(percent) < 0 ? '✅ Bundle size decreased.' : '✅ Bundle size unchanged.'
272+
}
189273
190274
<details>
191-
<summary>ℹ️ How to use this report</summary>
192-
193-
1. Click on the "Playwright Report" link above to view the full test results.
194-
2. In the report, you can see a breakdown of all tests, including any failures.
195-
3. For failed tests, you can view screenshots and video recordings to help debug the issues.
196-
4. Use the filters in the report to focus on specific test statuses or suites.
275+
<summary>ℹ️ CI Information</summary>
197276
277+
- Test recordings for failed tests are available in the full report.
278+
- Bundle size is measured for the entire 'dist' directory.
279+
- 📊 indicates links to detailed reports.
280+
- 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.
198281
</details>`;
199282
200283
const { data: pullRequest } = await github.rest.pulls.get({
@@ -204,15 +287,13 @@ jobs:
204287
});
205288
206289
const currentBody = pullRequest.body || '';
207-
const testResultsRegex = /## Playwright Test Results[\s\S]*?(?=\n## |$)/;
290+
const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;
208291
209-
let newBody;
210-
if (testResultsRegex.test(currentBody)) {
211-
// If the section exists, replace it
212-
newBody = currentBody.replace(testResultsRegex, testResultsSection);
292+
let newBody = currentBody;
293+
if (ciSectionRegex.test(newBody)) {
294+
newBody = newBody.replace(ciSectionRegex, ciSection);
213295
} else {
214-
// If the section doesn't exist, add it to the end
215-
newBody = currentBody + '\n\n' + testResultsSection;
296+
newBody += '\n\n' + ciSection;
216297
}
217298
218299
await github.rest.pulls.update({

0 commit comments

Comments
 (0)