Skip to content

Commit 36cfc3b

Browse files
authored
Merge pull request #21 from beneite/featurebranch
adding pipeline support for unit test
2 parents 4c07354 + ee65a13 commit 36cfc3b

1 file changed

Lines changed: 41 additions & 5 deletions

File tree

.github/workflows/unitTestPipeline.yaml

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: p23_slack_notification
1+
name: Unit-Test pipeline and publish results
22

33
on:
44
workflow_dispatch:
@@ -37,10 +37,46 @@ jobs:
3737
id: test_summary
3838
if: always()
3939
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
4480
4581
- name: Set Slack Color
4682
id: slack_color

0 commit comments

Comments
 (0)