|
1 | | -name: p23_slack_notification |
| 1 | +name: Unit-Test pipeline and publish results |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: |
@@ -37,10 +37,46 @@ jobs: |
37 | 37 | id: test_summary |
38 | 38 | if: always() |
39 | 39 | run: | |
40 | | - total=$(grep -o "Tests run:" target/surefire-reports/*.txt | wc -l || true) |
41 | | - passed=$(grep -o "BUILD SUCCESS" target/surefire-reports/*.txt | wc -l || true) |
42 | | - failed=$(grep -o "Failures:" target/surefire-reports/*.txt | wc -l || true) |
43 | | - echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $failed" >> $GITHUB_OUTPUT |
| 40 | + # use bash features |
| 41 | + shopt -s nullglob |
| 42 | +
|
| 43 | + # Look for text reports first (common) |
| 44 | + files=(target/surefire-reports/*Test.txt target/surefire-reports/*.txt) |
| 45 | +
|
| 46 | + if [ ${#files[@]} -eq 0 ]; then |
| 47 | + # fallback to XML reports if txt not present |
| 48 | + xml_files=(target/surefire-reports/TEST-*.xml) |
| 49 | + if [ ${#xml_files[@]} -eq 0 ]; then |
| 50 | + echo "summary=⚠️ No test result files found." >> $GITHUB_OUTPUT |
| 51 | + exit 0 |
| 52 | + fi |
| 53 | +
|
| 54 | + sums=$(sed -n 's/.*tests="\([0-9]\+\)".*failures="\([0-9]\+\)".*errors="\([0-9]\+\)".*skipped="\([0-9]\+\)".*/\1 \2 \3 \4/p' "${xml_files[@]}" \ |
| 55 | + | awk '{t+=$1;f+=$2;e+=$3;s+=$4} END {p=t-f-e-s; printf "%d|%d|%d|%d|%d", t, f, e, s, p}') |
| 56 | +
|
| 57 | + if [ -z "$sums" ]; then |
| 58 | + echo "summary=⚠️ Could not parse XML test results." >> $GITHUB_OUTPUT |
| 59 | + exit 0 |
| 60 | + fi |
| 61 | +
|
| 62 | + IFS='|' read total failures errors skipped passed <<< "$sums" |
| 63 | + fails=$((failures + errors)) |
| 64 | + echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $fails" >> $GITHUB_OUTPUT |
| 65 | + exit 0 |
| 66 | + fi |
| 67 | +
|
| 68 | + # Parse human-readable .txt surefire reports |
| 69 | + sums=$(sed -n 's/.*Tests run:[[:space:]]*\([0-9]\+\)[[:space:]]*,[[:space:]]*Failures:[[:space:]]*\([0-9]\+\)[[:space:]]*,[[:space:]]*Errors:[[:space:]]*\([0-9]\+\)[[:space:]]*,[[:space:]]*Skipped:[[:space:]]*\([0-9]\+\).*/\1 \2 \3 \4/p' "${files[@]}" \ |
| 70 | + | awk '{t+=$1;f+=$2;e+=$3;s+=$4} END {p=t-f-e-s; printf "%d|%d|%d|%d|%d", t, f, e, s, p}') |
| 71 | +
|
| 72 | + if [ -z "$sums" ]; then |
| 73 | + echo "summary=⚠️ Could not parse text test results." >> $GITHUB_OUTPUT |
| 74 | + exit 0 |
| 75 | + fi |
| 76 | +
|
| 77 | + IFS='|' read total failures errors skipped passed <<< "$sums" |
| 78 | + fails=$((failures + errors)) |
| 79 | + echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $fails" >> $GITHUB_OUTPUT |
44 | 80 |
|
45 | 81 | - name: Set Slack Color |
46 | 82 | id: slack_color |
|
0 commit comments