@@ -36,340 +36,3 @@ jobs:
36
36
node-version : 18
37
37
- run : npm ci
38
38
- run : npm test
39
-
40
- e2e_tests :
41
- name : Playwright Tests
42
- runs-on : ubuntu-latest
43
- permissions :
44
- contents : read
45
-
46
- services :
47
- backend :
48
- image : ghcr.io/ydb-platform/local-ydb:nightly
49
- ports :
50
- - 2135:2135
51
- - 8765:8765
52
- options : --hostname localhost -e YDB_ALLOW_ORIGIN="http://localhost:3000"
53
-
54
- steps :
55
- - uses : actions/checkout@v4
56
- with :
57
- fetch-depth : 0
58
-
59
- - name : Setup Node.js
60
- uses : actions/setup-node@v4
61
- with :
62
- node-version : 18
63
- cache : npm
64
-
65
- - name : Install dependencies
66
- run : npm ci
67
-
68
- - name : Install Playwright deps
69
- run : npm run test:e2e:install
70
-
71
- - name : Run Playwright tests
72
- id : run_tests
73
- run : npm run test:e2e
74
- env :
75
- CI : true
76
- PLAYWRIGHT_VIDEO : ' on'
77
-
78
- - name : Upload Playwright artifacts
79
- if : always()
80
- uses : actions/upload-artifact@v3
81
- with :
82
- name : playwright-artifacts
83
- path : playwright-artifacts
84
- retention-days : 5
85
-
86
- - name : Get test results
87
- if : always()
88
- id : test-results
89
- run : |
90
- echo "Current directory: $(pwd)"
91
- echo "Listing playwright-artifacts directory:"
92
- ls -R playwright-artifacts
93
-
94
- if [ -f "playwright-artifacts/test-results.json" ]; then
95
- echo "Parsing JSON file:"
96
- total=$(jq '.stats.expected + .stats.unexpected + .stats.flaky + .stats.skipped' playwright-artifacts/test-results.json)
97
- passed=$(jq '.stats.expected' playwright-artifacts/test-results.json)
98
- failed=$(jq '.stats.unexpected' playwright-artifacts/test-results.json)
99
- flaky=$(jq '.stats.flaky' playwright-artifacts/test-results.json)
100
- skipped=$(jq '.stats.skipped' playwright-artifacts/test-results.json)
101
-
102
- echo "Parsed values:"
103
- echo "Total: $total"
104
- echo "Passed: $passed"
105
- echo "Failed: $failed"
106
- echo "Flaky: $flaky"
107
- echo "Skipped: $skipped"
108
- else
109
- echo "test-results.json file not found"
110
- total=0
111
- passed=0
112
- failed=0
113
- flaky=0
114
- skipped=0
115
- fi
116
-
117
- echo "total=$total" >> $GITHUB_OUTPUT
118
- echo "passed=$passed" >> $GITHUB_OUTPUT
119
- echo "failed=$failed" >> $GITHUB_OUTPUT
120
- echo "flaky=$flaky" >> $GITHUB_OUTPUT
121
- echo "skipped=$skipped" >> $GITHUB_OUTPUT
122
-
123
- bundle_size :
124
- name : Check Bundle Size
125
- runs-on : ubuntu-latest
126
- if : ${{github.event.action != 'checks_requested'}}
127
- outputs :
128
- current_size : ${{ steps.current_size.outputs.size }}
129
- main_size : ${{ steps.main_size.outputs.size }}
130
- diff : ${{ steps.size_diff.outputs.diff }}
131
- percent : ${{ steps.size_diff.outputs.percent }}
132
- steps :
133
- - uses : actions/checkout@v4
134
- with :
135
- fetch-depth : 0
136
-
137
- - name : Setup Node.js
138
- uses : actions/setup-node@v4
139
- with :
140
- node-version : 18
141
- cache : npm
142
-
143
- - name : Install dependencies
144
- run : npm ci
145
-
146
- - name : Build bundle (current branch)
147
- run : npm run build
148
-
149
- - name : Get current bundle size
150
- id : current_size
151
- run : |
152
- size=$(du -sb build | cut -f1)
153
- echo "size=$size" >> $GITHUB_OUTPUT
154
-
155
- - name : Checkout main branch
156
- uses : actions/checkout@v4
157
- with :
158
- ref : main
159
-
160
- - name : Install dependencies (main)
161
- run : npm ci
162
-
163
- - name : Build bundle (main branch)
164
- run : npm run build
165
-
166
- - name : Get main bundle size
167
- id : main_size
168
- run : |
169
- size=$(du -sb build | cut -f1)
170
- echo "size=$size" >> $GITHUB_OUTPUT
171
-
172
- - name : Calculate size difference
173
- id : size_diff
174
- run : |
175
- current=${{ steps.current_size.outputs.size }}
176
- main=${{ steps.main_size.outputs.size }}
177
- diff=$((current - main))
178
- if [ "$main" -ne "0" ]; then
179
- percent=$(awk "BEGIN {printf \"%.2f\", ($diff/$main) * 100}")
180
- else
181
- percent="N/A"
182
- fi
183
- echo "diff=$diff" >> $GITHUB_OUTPUT
184
- echo "percent=$percent" >> $GITHUB_OUTPUT
185
-
186
- deploy_report :
187
- name : Deploy Test Report
188
- needs : [e2e_tests]
189
- if : ${{always() && (github.ref == 'refs/heads/main' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository))}}
190
- runs-on : ubuntu-latest
191
- permissions :
192
- contents : write
193
- pages : write
194
-
195
- steps :
196
- - uses : actions/checkout@v4
197
- with :
198
- fetch-depth : 0
199
-
200
- - name : Fetch gh-pages branch
201
- run : |
202
- git fetch origin gh-pages:gh-pages
203
- mkdir gh-pages
204
- git --work-tree=gh-pages checkout gh-pages -- .
205
-
206
- - name : Download Playwright artifacts
207
- uses : actions/download-artifact@v3
208
- with :
209
- name : playwright-artifacts
210
- path : playwright-artifacts
211
-
212
- - name : Copy new report
213
- run : |
214
- if [ "${{ github.event_name }}" = "pull_request" ]; then
215
- REPORT_DIR="${{ github.event.pull_request.number }}"
216
- else
217
- REPORT_DIR="main"
218
- fi
219
- rm -rf gh-pages/$REPORT_DIR
220
- mkdir -p gh-pages/$REPORT_DIR
221
- cp -r playwright-artifacts/playwright-report/* gh-pages/$REPORT_DIR/
222
-
223
- - name : Deploy report to GitHub Pages
224
- uses : peaceiris/actions-gh-pages@v3
225
- with :
226
- github_token : ${{ secrets.GITHUB_TOKEN }}
227
- publish_dir : gh-pages
228
- destination_dir : .
229
- force_orphan : true
230
-
231
- update_pr :
232
- name : Update PR Description
233
- needs : [e2e_tests, bundle_size]
234
- if : ${{always() && github.event_name == 'pull_request'}}
235
- runs-on : ubuntu-latest
236
- permissions :
237
- pull-requests : write
238
-
239
- steps :
240
- - uses : actions/checkout@v4
241
- with :
242
- fetch-depth : 0
243
-
244
- - name : Download Playwright artifacts
245
- uses : actions/download-artifact@v3
246
- with :
247
- name : playwright-artifacts
248
- path : playwright-artifacts
249
-
250
- - name : Count new tests
251
- id : count_tests
252
- run : |
253
- git fetch origin main:main
254
- new_tests=0
255
-
256
- # Get list of changed test files
257
- for file in $(git diff --name-only main...HEAD | grep -E '^tests/suites/.*\.(spec|test)\.(ts|tsx|js|jsx)$'); do
258
- # Count tests in current version
259
- if git show HEAD:"$file" > /dev/null 2>&1; then
260
- current_tests=$(git show HEAD:"$file" | grep -E "test\([\'\"]" | wc -l)
261
- else
262
- current_tests=0
263
- fi
264
-
265
- # Count tests in main version
266
- if git show main:"$file" > /dev/null 2>&1; then
267
- base_tests=$(git show main:"$file" | grep -E "test\([\'\"]" | wc -l)
268
- else
269
- base_tests=0
270
- fi
271
-
272
- # Add difference to total
273
- ((new_tests += current_tests - base_tests))
274
- done
275
-
276
- echo "new_tests=$new_tests" >> $GITHUB_OUTPUT
277
-
278
- - name : Update PR description
279
- uses : actions/github-script@v6
280
- with :
281
- github-token : ${{secrets.GITHUB_TOKEN}}
282
- script : |
283
- const fs = require('fs');
284
- const testResultsPath = 'playwright-artifacts/test-results.json';
285
- let testResults;
286
-
287
- if (fs.existsSync(testResultsPath)) {
288
- const rawData = fs.readFileSync(testResultsPath);
289
- const data = JSON.parse(rawData);
290
- testResults = {
291
- total: data.stats.expected + data.stats.unexpected + data.stats.flaky + data.stats.skipped,
292
- passed: data.stats.expected,
293
- failed: data.stats.unexpected,
294
- flaky: data.stats.flaky,
295
- skipped: data.stats.skipped
296
- };
297
- } else {
298
- console.log('Test results file not found');
299
- testResults = { total: 0, passed: 0, failed: 0, flaky: 0, skipped: 0 };
300
- }
301
-
302
- const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`;
303
- const status = testResults.failed > 0 ? '❌ FAILED' : (testResults.flaky > 0 ? '⚠️ FLAKY' : '✅ PASSED');
304
- const statusColor = testResults.failed > 0 ? 'red' : (testResults.flaky > 0 ? 'orange' : 'green');
305
-
306
- const currentSize = parseInt('${{ needs.bundle_size.outputs.current_size }}');
307
- const mainSize = parseInt('${{ needs.bundle_size.outputs.main_size }}');
308
- const diff = parseInt('${{ needs.bundle_size.outputs.diff }}');
309
- const percent = '${{ needs.bundle_size.outputs.percent }}';
310
-
311
- const formatSize = (size) => {
312
- if (size >= 1024) {
313
- return `${(size / (1024 * 1024)).toFixed(2)} MB`;
314
- }
315
- return `${(size / 1024).toFixed(2)} KB`;
316
- };
317
-
318
- const bundleStatus = percent === 'N/A' ? '⚠️' :
319
- parseFloat(percent) > 0 ? '🔺' :
320
- parseFloat(percent) < 0 ? '🔽' : '✅';
321
-
322
- const newTests = parseInt('${{ steps.count_tests.outputs.new_tests }}');
323
- const testsStatus = newTests > 0 ? '✨' : '➖';
324
-
325
- const ciSection = `## CI Results
326
-
327
- ### Test Status: <span style="color: ${statusColor};">${status}</span>
328
- 📊 [Full Report](${reportUrl})
329
-
330
- | Total | Passed | Failed | Flaky | Skipped | New Tests |
331
- |:-----:|:------:|:------:|:-----:|:-------:|:---------:|
332
- | ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} | ${testsStatus} ${newTests} |
333
-
334
- ### Bundle Size: ${bundleStatus}
335
- Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
336
- Diff: ${diff > 0 ? '+' : ''}${formatSize(Math.abs(diff))} (${percent === 'N/A' ? 'N/A' : `${percent}%`})
337
-
338
- ${
339
- percent === 'N/A' ? '⚠️ Unable to calculate change.' :
340
- parseFloat(percent) > 0 ? '⚠️ Bundle size increased. Please review.' :
341
- parseFloat(percent) < 0 ? '✅ Bundle size decreased.' : '✅ Bundle size unchanged.'
342
- }
343
-
344
- <details>
345
- <summary>ℹ️ CI Information</summary>
346
-
347
- - Test recordings for failed tests are available in the full report.
348
- - Bundle size is measured for the entire 'dist' directory.
349
- - 📊 indicates links to detailed reports.
350
- - 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size.
351
- - ${testsStatus} indicates ${newTests} new test cases added in this PR.
352
- </details>`;
353
-
354
- const { data: pullRequest } = await github.rest.pulls.get({
355
- owner: context.repo.owner,
356
- repo: context.repo.repo,
357
- pull_number: context.issue.number,
358
- });
359
-
360
- const currentBody = pullRequest.body || '';
361
- const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/;
362
-
363
- let newBody = currentBody;
364
- if (ciSectionRegex.test(newBody)) {
365
- newBody = newBody.replace(ciSectionRegex, ciSection);
366
- } else {
367
- newBody += '\n\n' + ciSection;
368
- }
369
-
370
- await github.rest.pulls.update({
371
- owner: context.repo.owner,
372
- repo: context.repo.repo,
373
- pull_number: context.issue.number,
374
- body: newBody,
375
- });
0 commit comments