|
| 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 |
0 commit comments