Skip to content

Commit c94de6a

Browse files
committed
Add test report action and integrate into build workflow
1 parent 589e706 commit c94de6a

File tree

3 files changed

+80
-100
lines changed

3 files changed

+80
-100
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: "Test Report"
2+
description: "Generate and publish test reports with summary for Java SDK tests."
3+
inputs:
4+
report-path:
5+
description: "Path to the test report XML files (glob pattern)"
6+
required: false
7+
default: "target/surefire-reports/TEST-*.xml"
8+
check-name:
9+
description: "Name for the check run"
10+
required: false
11+
default: "Java SDK Test Results"
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Generate Test Summary
16+
shell: bash
17+
run: |
18+
echo "## 🧪 Java SDK Test Results" >> $GITHUB_STEP_SUMMARY
19+
echo "" >> $GITHUB_STEP_SUMMARY
20+
21+
REPORT_DIR=$(dirname "${{ inputs.report-path }}")
22+
REPORT_PATTERN=$(basename "${{ inputs.report-path }}")
23+
24+
if [ -d "$REPORT_DIR" ]; then
25+
TESTS_RUN=$(grep -h "tests=" ${{ inputs.report-path }} 2>/dev/null | sed 's/.*tests="\([0-9]*\)".*/\1/' | awk '{s+=$1} END {print s}')
26+
FAILURES=$(grep -h "failures=" ${{ inputs.report-path }} 2>/dev/null | sed 's/.*failures="\([0-9]*\)".*/\1/' | awk '{s+=$1} END {print s}')
27+
ERRORS=$(grep -h "errors=" ${{ inputs.report-path }} 2>/dev/null | sed 's/.*errors="\([0-9]*\)".*/\1/' | awk '{s+=$1} END {print s}')
28+
SKIPPED=$(grep -h "skipped=" ${{ inputs.report-path }} 2>/dev/null | sed 's/.*skipped="\([0-9]*\)".*/\1/' | awk '{s+=$1} END {print s}')
29+
30+
TESTS_RUN=${TESTS_RUN:-0}
31+
FAILURES=${FAILURES:-0}
32+
ERRORS=${ERRORS:-0}
33+
SKIPPED=${SKIPPED:-0}
34+
PASSED=$((TESTS_RUN - FAILURES - ERRORS - SKIPPED))
35+
36+
if [ "$FAILURES" -eq 0 ] && [ "$ERRORS" -eq 0 ]; then
37+
echo "### ✅ All tests passed!" >> $GITHUB_STEP_SUMMARY
38+
else
39+
echo "### ❌ Some tests failed" >> $GITHUB_STEP_SUMMARY
40+
fi
41+
42+
echo "" >> $GITHUB_STEP_SUMMARY
43+
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
44+
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
45+
echo "| ✅ Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY
46+
echo "| ❌ Failed | $FAILURES |" >> $GITHUB_STEP_SUMMARY
47+
echo "| 💥 Errors | $ERRORS |" >> $GITHUB_STEP_SUMMARY
48+
echo "| ⏭️ Skipped | $SKIPPED |" >> $GITHUB_STEP_SUMMARY
49+
echo "| 📊 Total | $TESTS_RUN |" >> $GITHUB_STEP_SUMMARY
50+
51+
echo "" >> $GITHUB_STEP_SUMMARY
52+
echo "### Test Classes" >> $GITHUB_STEP_SUMMARY
53+
echo "" >> $GITHUB_STEP_SUMMARY
54+
echo "| Class | Tests | Passed | Failed | Errors | Time |" >> $GITHUB_STEP_SUMMARY
55+
echo "|-------|-------|--------|--------|--------|------|" >> $GITHUB_STEP_SUMMARY
56+
57+
for file in ${{ inputs.report-path }}; do
58+
if [ -f "$file" ]; then
59+
CLASS=$(basename "$file" .xml | sed 's/TEST-//')
60+
T=$(grep -o 'tests="[0-9]*"' "$file" | head -1 | sed 's/[^0-9]//g')
61+
F=$(grep -o 'failures="[0-9]*"' "$file" | head -1 | sed 's/[^0-9]//g')
62+
E=$(grep -o 'errors="[0-9]*"' "$file" | head -1 | sed 's/[^0-9]//g')
63+
TIME=$(grep -o 'time="[0-9.]*"' "$file" | head -1 | sed 's/[^0-9.]//g')
64+
P=$((T - F - E))
65+
66+
STATUS="✅"
67+
if [ "${F:-0}" -gt 0 ] || [ "${E:-0}" -gt 0 ]; then
68+
STATUS="❌"
69+
fi
70+
71+
echo "| $STATUS $CLASS | ${T:-0} | ${P:-0} | ${F:-0} | ${E:-0} | ${TIME:-0}s |" >> $GITHUB_STEP_SUMMARY
72+
fi
73+
done
74+
else
75+
echo "⚠️ No test reports found at ${{ inputs.report-path }}" >> $GITHUB_STEP_SUMMARY
76+
fi

.github/workflows/build-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ jobs:
7070
COPILOT_CLI_PATH: ${{ steps.setup-copilot.outputs.path }}
7171
run: mvn verify
7272

73+
- name: Generate Test Report Summary
74+
if: always()
75+
uses: ./.github/actions/test-report
76+
7377
- name: Upload Test Reports
7478
uses: actions/upload-artifact@v4
7579
if: always()

.github/workflows/test-report.yml

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)