Skip to content

Commit 0fac3ab

Browse files
committed
feat(tests): enhance GitHub Actions workflow to parse and report test results and coverage summary
1 parent d3f8f82 commit 0fac3ab

File tree

1 file changed

+49
-26
lines changed

1 file changed

+49
-26
lines changed

.github/workflows/pr-test.yml

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: PR Test & Coverage Report
33
on:
44
pull_request:
55
branches:
6-
- main # 필요시 변경
6+
- main
77

88
jobs:
99
test:
@@ -35,21 +35,50 @@ jobs:
3535
run: |
3636
poetry run coverage xml -o coverage.xml
3737
38-
- name: Parse Coverage and Write Summary
38+
- name: Parse Coverage for Comment
39+
id: coverage-comment
3940
run: |
40-
poetry run python -c "
41+
percentage=$(poetry run python -c "
4142
import xml.etree.ElementTree as ET
4243
tree = ET.parse('coverage.xml')
4344
root = tree.getroot()
4445
line_rate = float(root.attrib['line-rate'])
45-
percentage = line_rate * 100
46-
with open('${{ github.step_summary }}', 'a') as f:
47-
f.write('| Metric | Value |\n')
48-
f.write('|--------|-----|\n')
49-
f.write(f'| 📊 Line Coverage | {percentage:.2f}% |\n')
50-
"
51-
52-
- name: Publish Test Results Summary
46+
print(f'{line_rate * 100:.2f}')
47+
")
48+
echo "COVERAGE_PERCENT=$percentage" >> "$GITHUB_OUTPUT"
49+
50+
- name: Parse JUnit Results for Summary
51+
id: junit-summary
52+
run: |
53+
summary=$(poetry run python -c "
54+
import xml.etree.ElementTree as ET
55+
import glob
56+
57+
total_tests = 0
58+
total_failures = 0
59+
total_skipped = 0
60+
total_errors = 0
61+
total_time = 0.0
62+
63+
for file in glob.glob('test-results/*.xml'):
64+
tree = ET.parse(file)
65+
root = tree.getroot()
66+
total_tests += int(root.attrib['tests'])
67+
total_failures += int(root.attrib['failures'])
68+
total_skipped += int(root.attrib['skipped'])
69+
total_errors += int(root.attrib.get('errors', 0))
70+
total_time += float(root.attrib.get('time', 0))
71+
72+
passed = total_tests - total_failures - total_skipped
73+
print(f'PASSED={passed}')
74+
print(f'FAILED={total_failures}')
75+
print(f'SKIPPED={total_skipped}')
76+
print(f'TIME={total_time:.2f}')
77+
")
78+
79+
echo "$summary" >> "$GITHUB_OUTPUT"
80+
81+
- name: Publish Test Results Summary (optional)
5382
uses: test-summary/action@v2
5483
with:
5584
paths: "test-results/*.xml"
@@ -67,25 +96,19 @@ jobs:
6796
name: junit-xml-reports
6897
path: test-results/
6998

70-
- name: Parse Coverage for Comment
71-
id: coverage-comment
72-
run: |
73-
percentage=$(poetry run python -c "
74-
import xml.etree.ElementTree as ET
75-
tree = ET.parse('coverage.xml')
76-
root = tree.getroot()
77-
line_rate = float(root.attrib['line-rate'])
78-
print(f'{line_rate * 100:.2f}')
79-
")
80-
echo "COVERAGE_PERCENT=$percentage" >> "$GITHUB_OUTPUT"
81-
82-
- name: Add Coverage Comment to PR
99+
- name: Add Test & Coverage Summary Comment to PR
83100
uses: peter-evans/create-or-update-comment@v4
84101
with:
85102
issue-number: ${{ github.event.pull_request.number }}
86103
body: |
87-
## 📝 Coverage Report
88-
| Metric | Value |
104+
## 📝 Test & Coverage Report
105+
106+
| Metric | Value |
89107
|--------|-----|
108+
| ✅ Passed | ${{ steps.junit-summary.outputs.PASSED }} |
109+
| ❌ Failed | ${{ steps.junit-summary.outputs.FAILED }} |
110+
| ⏩ Skipped | ${{ steps.junit-summary.outputs.SKIPPED }} |
111+
| ⏱️ Time | ${{ steps.junit-summary.outputs.TIME }}s |
90112
| 📊 Line Coverage | ${{ steps.coverage-comment.outputs.COVERAGE_PERCENT }}% |
113+
91114
token: ${{ secrets.PAT_TOKEN }}

0 commit comments

Comments
 (0)