@@ -90,34 +90,100 @@ jobs:
90
90
91
91
if [ -f "playwright-artifacts/test-results.json" ]; then
92
92
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)
94
94
passed=$(jq '.stats.expected' playwright-artifacts/test-results.json)
95
95
failed=$(jq '.stats.unexpected' playwright-artifacts/test-results.json)
96
+ flaky=$(jq '.stats.flaky' playwright-artifacts/test-results.json)
96
97
skipped=$(jq '.stats.skipped' playwright-artifacts/test-results.json)
97
98
98
99
echo "Parsed values:"
99
100
echo "Total: $total"
100
101
echo "Passed: $passed"
101
102
echo "Failed: $failed"
103
+ echo "Flaky: $flaky"
102
104
echo "Skipped: $skipped"
103
105
else
104
106
echo "test-results.json file not found"
105
107
total=0
106
108
passed=0
107
109
failed=0
110
+ flaky=0
108
111
skipped=0
109
112
fi
110
113
111
114
echo "total=$total" >> $GITHUB_OUTPUT
112
115
echo "passed=$passed" >> $GITHUB_OUTPUT
113
116
echo "failed=$failed" >> $GITHUB_OUTPUT
117
+ echo "flaky=$flaky" >> $GITHUB_OUTPUT
114
118
echo "skipped=$skipped" >> $GITHUB_OUTPUT
115
119
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
+
116
182
deploy_and_update :
117
183
name : Deploy and Update PR
118
- needs : e2e_tests
119
- runs-on : ubuntu-latest
184
+ needs : [e2e_tests, bundle_size]
120
185
if : always() && github.event.pull_request.head.repo.full_name == github.repository
186
+ runs-on : ubuntu-latest
121
187
permissions :
122
188
contents : write
123
189
pages : write
@@ -155,46 +221,63 @@ jobs:
155
221
const rawData = fs.readFileSync(testResultsPath);
156
222
const data = JSON.parse(rawData);
157
223
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,
159
225
passed: data.stats.expected,
160
226
failed: data.stats.unexpected,
227
+ flaky: data.stats.flaky,
161
228
skipped: data.stats.skipped
162
229
};
163
230
} else {
164
231
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 };
166
233
}
167
234
168
235
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
+ }
189
273
190
274
<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>
197
276
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.
198
281
</details>`;
199
282
200
283
const { data: pullRequest } = await github.rest.pulls.get({
@@ -204,15 +287,13 @@ jobs:
204
287
});
205
288
206
289
const currentBody = pullRequest.body || '';
207
- const testResultsRegex = /## Playwright Test Results[\s\S]*?(?=\n## |$)/;
290
+ const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results) |$)/;
208
291
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);
213
295
} else {
214
- // If the section doesn't exist, add it to the end
215
- newBody = currentBody + '\n\n' + testResultsSection;
296
+ newBody += '\n\n' + ciSection;
216
297
}
217
298
218
299
await github.rest.pulls.update({
0 commit comments