Skip to content

Commit 121e734

Browse files
committed
Use Python to generate surefire test summary
Replace the test-summary/action step with an inline Bash step that runs a Python script to parse Surefire XML reports (target/surefire-reports/TEST-*.xml). The script aggregates totals (passed, failed, errors, skipped, total), lists up to 20 failed test cases, and appends a Markdown-formatted summary to the GitHub Actions step summary (GITHUB_STEP_SUMMARY) or prints it if unavailable. Keeps existing subsequent steps intact.
1 parent 86742d4 commit 121e734

1 file changed

Lines changed: 63 additions & 6 deletions

File tree

.github/workflows/snapshot.yml

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,70 @@ jobs:
4040
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
4141

4242
- name: Test Summary
43-
id: test_summary
44-
uses: test-summary/action@v2
45-
with:
46-
paths: |
47-
target/surefire-reports/TEST-*.xml
48-
target/surefire-reports/**/TEST-*.xml
4943
if: always()
44+
shell: bash
45+
run: |
46+
python3 <<'PY'
47+
import os
48+
from pathlib import Path
49+
import xml.etree.ElementTree as ET
50+
51+
reports = sorted(Path("target/surefire-reports").rglob("TEST-*.xml"))
52+
lines = ["### Test Summary", ""]
53+
54+
if not reports:
55+
lines.append("No Surefire XML reports found.")
56+
else:
57+
total = failures = errors = skipped = 0
58+
failed_cases = []
59+
60+
for report in reports:
61+
root = ET.parse(report).getroot()
62+
suites = [root] if root.tag == "testsuite" else root.findall("testsuite")
63+
64+
for suite in suites:
65+
total += int(suite.get("tests", 0))
66+
failures += int(suite.get("failures", 0))
67+
errors += int(suite.get("errors", 0))
68+
skipped += int(suite.get("skipped", 0))
69+
70+
for case in suite.findall("testcase"):
71+
if case.find("failure") is None and case.find("error") is None:
72+
continue
73+
74+
class_name = case.get("classname", "")
75+
test_name = case.get("name", "")
76+
failed_cases.append(f"`{class_name}.{test_name}`".strip("."))
77+
78+
passed = total - failures - errors - skipped
79+
lines.extend(
80+
[
81+
"| Outcome | Count |",
82+
"| --- | ---: |",
83+
f"| Passed | {passed} |",
84+
f"| Failed | {failures} |",
85+
f"| Errors | {errors} |",
86+
f"| Skipped | {skipped} |",
87+
f"| Total | {total} |",
88+
]
89+
)
90+
91+
if failed_cases:
92+
lines.extend(["", "#### Failed Tests"])
93+
lines.extend(f"- {test}" for test in failed_cases[:20])
94+
if len(failed_cases) > 20:
95+
remaining = len(failed_cases) - 20
96+
lines.append(f"- ... and {remaining} more")
97+
98+
summary_path = os.environ.get("GITHUB_STEP_SUMMARY")
99+
output = "\n".join(lines) + "\n"
100+
101+
if summary_path:
102+
with open(summary_path, "a", encoding="utf-8") as summary:
103+
summary.write(output)
104+
else:
105+
print(output)
106+
PY
50107
51108
- uses: qltysh/qlty-action/coverage@main
52109
if: github.event_name != 'pull_request'

0 commit comments

Comments
 (0)