Skip to content

Commit 07e3fb2

Browse files
Ashish MishraAshish Mishra
authored andcommitted
fixing the pipeline slack message test cases count
1 parent ee65a13 commit 07e3fb2

1 file changed

Lines changed: 24 additions & 37 deletions

File tree

.github/workflows/unitTestPipeline.yaml

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,33 @@ jobs:
3737
id: test_summary
3838
if: always()
3939
run: |
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
40+
total=0
41+
failures=0
42+
errors=0
43+
skipped=0
44+
45+
for file in target/surefire-reports/*.txt; do
46+
if [ -f "$file" ]; then
47+
# Grab the FIRST "Tests run:" line only
48+
line=$(grep -m1 "Tests run:" "$file")
49+
if [ -n "$line" ]; then
50+
t=$(echo "$line" | sed -E 's/.*Tests run: *([0-9]+).*/\1/')
51+
f=$(echo "$line" | sed -E 's/.*Failures: *([0-9]+).*/\1/')
52+
e=$(echo "$line" | sed -E 's/.*Errors: *([0-9]+).*/\1/')
53+
s=$(echo "$line" | sed -E 's/.*Skipped: *([0-9]+).*/\1/')
54+
55+
total=$((total + t))
56+
failures=$((failures + f))
57+
errors=$((errors + e))
58+
skipped=$((skipped + s))
59+
fi
6060
fi
61+
done
6162
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
63+
passed=$((total - failures - errors - skipped))
64+
failed=$((failures + errors))
7665
77-
IFS='|' read total failures errors skipped passed <<< "$sums"
78-
fails=$((failures + errors))
79-
echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $fails" >> $GITHUB_OUTPUT
66+
echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $failed" >> $GITHUB_OUTPUT
8067
8168
- name: Set Slack Color
8269
id: slack_color

0 commit comments

Comments
 (0)