Skip to content

Commit 4a74891

Browse files
Anton StandrikAnton Standrik
authored andcommitted
fix: count tests
1 parent 1bb449c commit 4a74891

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

β€Ž.github/workflows/ci.ymlβ€Ž

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ jobs:
196196

197197
steps:
198198
- uses: actions/checkout@v4
199+
with:
200+
fetch-depth: 0
199201

200202
- name: Fetch gh-pages branch
201203
run: |
@@ -222,6 +224,28 @@ jobs:
222224
destination_dir: .
223225
force_orphan: true
224226

227+
- name: Count new tests
228+
id: count_tests
229+
run: |
230+
git fetch origin main:main
231+
232+
# Get list of changed test files
233+
changed_files=$(git diff --name-only main...HEAD | grep -E '.*\.(spec|test)\.(ts|tsx|js|jsx)$' || true)
234+
235+
# Count new test cases
236+
new_tests=0
237+
for file in $changed_files; do
238+
if git show HEAD:$file > /dev/null 2>&1; then
239+
new_cases=$(git show HEAD:$file | grep -c "it\('" || true)
240+
base_cases=$(git show main:$file 2>/dev/null | grep -c "it\('" || true)
241+
((new_tests += new_cases - base_cases))
242+
else
243+
# If file is completely new, count all test cases
244+
new_tests+=$(git show HEAD:$file | grep -c "it\('" || true)
245+
fi
246+
done
247+
echo "new_tests=$new_tests" >> $GITHUB_OUTPUT
248+
225249
- name: Update PR description
226250
uses: actions/github-script@v6
227251
with:
@@ -266,14 +290,17 @@ jobs:
266290
parseFloat(percent) > 0 ? 'πŸ”Ί' :
267291
parseFloat(percent) < 0 ? 'πŸ”½' : 'βœ…';
268292
293+
const newTests = parseInt('${{ steps.count_tests.outputs.new_tests }}');
294+
const testsStatus = newTests > 0 ? '✨' : 'βž–';
295+
269296
const ciSection = `## CI Results
270297
271298
### Test Status: <span style="color: ${statusColor};">${status}</span>
272299
πŸ“Š [Full Report](${reportUrl})
273300
274-
| Total | Passed | Failed | Flaky | Skipped |
275-
|:-----:|:------:|:------:|:-----:|:-------:|
276-
| ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} |
301+
| Total | Passed | Failed | Flaky | Skipped | New Tests |
302+
|:-----:|:------:|:------:|:-----:|:-------:|:---------:|
303+
| ${testResults.total} | ${testResults.passed} | ${testResults.failed} | ${testResults.flaky} | ${testResults.skipped} | ${testsStatus} ${newTests} |
277304
278305
### Bundle Size: ${bundleStatus}
279306
Current: ${formatSize(currentSize)} | Main: ${formatSize(mainSize)}
@@ -292,6 +319,7 @@ jobs:
292319
- Bundle size is measured for the entire 'dist' directory.
293320
- πŸ“Š indicates links to detailed reports.
294321
- πŸ”Ί indicates increase, πŸ”½ decrease, and βœ… no change in bundle size.
322+
- ${testsStatus} indicates ${newTests} new test cases added in this PR.
295323
</details>`;
296324
297325
const { data: pullRequest } = await github.rest.pulls.get({

0 commit comments

Comments
Β (0)