@@ -221,97 +221,21 @@ jobs:
221221 name : playwright-artifacts
222222 path : playwright-artifacts
223223
224+ - name : Fetch gh-pages branch
225+ run : |
226+ git fetch origin gh-pages:gh-pages
227+ mkdir gh-pages
228+ git --work-tree=gh-pages checkout gh-pages -- .
229+
224230 - name : Update PR description
225231 uses : actions/github-script@v6
232+ env :
233+ CURRENT_SIZE : ${{ needs.bundle_size.outputs.current_size }}
234+ MAIN_SIZE : ${{ needs.bundle_size.outputs.main_size }}
235+ SIZE_DIFF : ${{ needs.bundle_size.outputs.diff }}
236+ SIZE_PERCENT : ${{ needs.bundle_size.outputs.percent }}
226237 with :
227238 github-token : ${{secrets.GITHUB_TOKEN}}
228239 script : |
229- const fs = require('fs');
230- const testResultsPath = 'playwright-artifacts/test-results.json';
231- let testResults;
232-
233- if (fs.existsSync(testResultsPath)) {
234- const rawData = fs.readFileSync(testResultsPath);
235- const data = JSON.parse(rawData);
236- testResults = {
237- total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
238- passed: data.stats.expected,
239- failed: data.stats.unexpected,
240- flaky: data.stats.flaky,
241- skipped: data.stats.skipped
242- };
243- } else {
244- console.log('Test results file not found');
245- testResults = { total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0 };
246- }
247-
248- const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
249- const status = testResults.failed > 0 ? '❌ FAILED' : (testResults.flaky > 0 ? '⚠️ FLAKY' : '✅ PASSED');
250- const statusColor = testResults.failed > 0 ? 'red' : (testResults.flaky > 0 ? 'orange' : 'green');
251-
252- const currentSize = parseInt('${{ needs.bundle_size.outputs.current_size }}');
253- const mainSize = parseInt('${{ needs.bundle_size.outputs.main_size }}');
254- const diff = parseInt('${{ needs.bundle_size.outputs.diff }}');
255- const percent = '${{ needs.bundle_size.outputs.percent }}';
256-
257- const formatSize = (size) => {
258- if (size >= 1024) {
259- return `${(size / (1024 * 1024)).toFixed(2)} MB`;
260- }
261- return `${(size / 1024).toFixed(2)} KB`;
262- };
263-
264- const bundleStatus = percent === 'N/A' ? '⚠️' :
265- parseFloat(percent) > 0 ? '🔺' :
266- parseFloat(percent) < 0 ? '🔽' : '✅';
267-
268- const ciSection = `## CI Results
269-
270- ### Test Status: <span style="color: ${statusColor};">${status}</span>
271- 📊 [Full Report](${reportUrl})
272-
273- | Total | Passed | Failed | Flaky | Skipped |
274- |:-----:|:------:|:------:|:-----:|:-------:|
275- | ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} |
276-
277- ### Bundle Size: ${bundleStatus}
278- Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
279- Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})
280-
281- ${
282- percent === 'N/A' ? '⚠️ Unable to calculate change.' :
283- parseFloat(percent) > 0 ? '⚠️ Bundle size increased. Please review.' :
284- parseFloat(percent) < 0 ? '✅ Bundle size decreased.' : '✅ Bundle size unchanged.'
285- }
286-
287- <details>
288- <summary>ℹ️ CI Information</summary>
289-
290- - Test recordings for failed tests are available in the full report.
291- - Bundle size is measured for the entire 'dist' directory.
292- - 📊 indicates links to detailed reports.
293- - 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.
294- </details>`;
295-
296- const { data: pullRequest } = await github.rest.pulls.get({
297- owner: context.repo.owner,
298- repo: context.repo.repo,
299- pull_number: context.issue.number,
300- });
301-
302- const currentBody = pullRequest.body || '';
303- const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;
304-
305- let newBody = currentBody;
306- if (ciSectionRegex.test(newBody)) {
307- newBody = newBody.replace(ciSectionRegex, ciSection);
308- } else {
309- newBody += '\n\n' + ciSection;
310- }
311-
312- await github.rest.pulls.update({
313- owner: context.repo.owner,
314- repo: context.repo.repo,
315- pull_number: context.issue.number,
316- body: newBody,
317- });
240+ const updatePRDescription = require('./.github/workflows/scripts/update-pr-description.js');
241+ await updatePRDescription(github, context);
0 commit comments