Skip to content

Commit 0b8f79a

Browse files
committed
feat(ci): Add native test result summaries
Enhances CI workflow with automated reporting for better visibility: **Native Test Result Summaries:** - Adds GitHub job summary showing test pass/fail status - Displays formatted table with total/passed/failed test counts - Uses only native GitHub features ($GITHUB_STEP_SUMMARY) - No third-party actions required for test reporting **Benefits:** - Test results summary on workflow run page - Maintains existing artifact upload for manual inspection - All reporting uses native or org-approved tools
1 parent 9597dfa commit 0b8f79a

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

.github/workflows/ci.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,82 @@ jobs:
3838
run: npm ci
3939

4040
- name: Run tests with coverage
41-
run: npm run test:coverage
41+
run: |
42+
npm run test:coverage 2>&1 | tee test-output.log
43+
echo "TEST_EXIT_CODE=${PIPESTATUS[0]}" >> $GITHUB_ENV
44+
45+
- name: Parse test results
46+
if: always()
47+
id: test-results
48+
run: |
49+
# Extract test results from web-test-runner output
50+
# Format: "Chrome: |████| 7/7 test files | 182 passed, 0 failed"
51+
if grep -q "passed" test-output.log; then
52+
PASSED=$(grep -oP '\d+ passed' test-output.log | tail -1 | grep -oP '\d+' || echo "0")
53+
FAILED=$(grep -oP '\d+ failed' test-output.log | tail -1 | grep -oP '\d+' || echo "0")
54+
TOTAL=$((PASSED + FAILED))
55+
56+
echo "passed=$PASSED" >> $GITHUB_OUTPUT
57+
echo "failed=$FAILED" >> $GITHUB_OUTPUT
58+
echo "total=$TOTAL" >> $GITHUB_OUTPUT
59+
else
60+
echo "passed=0" >> $GITHUB_OUTPUT
61+
echo "failed=0" >> $GITHUB_OUTPUT
62+
echo "total=0" >> $GITHUB_OUTPUT
63+
fi
64+
65+
- name: Generate test summary
66+
if: always()
67+
run: |
68+
echo "### Test Results 📊" >> $GITHUB_STEP_SUMMARY
69+
echo "" >> $GITHUB_STEP_SUMMARY
70+
71+
PASSED="${{ steps.test-results.outputs.passed }}"
72+
FAILED="${{ steps.test-results.outputs.failed }}"
73+
TOTAL="${{ steps.test-results.outputs.total }}"
74+
75+
if [ "$FAILED" = "0" ] && [ "$TOTAL" != "0" ]; then
76+
echo "✅ **All tests passed!**" >> $GITHUB_STEP_SUMMARY
77+
elif [ "$TOTAL" = "0" ]; then
78+
echo "⚠️ **Could not parse test results**" >> $GITHUB_STEP_SUMMARY
79+
else
80+
echo "❌ **Some tests failed**" >> $GITHUB_STEP_SUMMARY
81+
fi
82+
83+
echo "" >> $GITHUB_STEP_SUMMARY
84+
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
85+
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
86+
echo "| Total Tests | $TOTAL |" >> $GITHUB_STEP_SUMMARY
87+
echo "| Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY
88+
echo "| Failed | $FAILED |" >> $GITHUB_STEP_SUMMARY
89+
90+
exit $TEST_EXIT_CODE
91+
92+
- name: Create test results check
93+
if: always() && github.event_name == 'pull_request'
94+
uses: actions/github-script@v7
95+
with:
96+
script: |
97+
const passed = '${{ steps.test-results.outputs.passed }}';
98+
const failed = '${{ steps.test-results.outputs.failed }}';
99+
const total = '${{ steps.test-results.outputs.total }}';
100+
101+
const conclusion = failed === '0' && total !== '0' ? 'success' : (total === '0' ? 'neutral' : 'failure');
102+
const summary = `${total} tests run, ${passed} passed, ${failed} failed`;
103+
104+
await github.rest.checks.create({
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
name: 'Test Results',
108+
head_sha: context.payload.pull_request.head.sha,
109+
status: 'completed',
110+
conclusion: conclusion,
111+
output: {
112+
title: summary,
113+
summary: summary,
114+
text: `**Test Execution Summary**\n\n- Total: ${total}\n- Passed: ${passed} ✅\n- Failed: ${failed} ${failed === '0' ? '✅' : '❌'}`
115+
}
116+
});
42117
43118
- name: Upload coverage to Codecov
44119
uses: codecov/codecov-action@v4

0 commit comments

Comments
 (0)