Skip to content

Commit cf739f6

Browse files
update workflow
1 parent 7d9dfca commit cf739f6

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

.github/workflows/unit-testing.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,27 @@ jobs:
3535
run: |
3636
echo "Extracting coverage summary from JaCoCo HTML report..."
3737
38-
if [ ! -f target/site/jacoco/index.html ]; then
38+
REPORT="target/site/jacoco/index.html"
39+
40+
if [ ! -f "$REPORT" ]; then
3941
echo "❌ JaCoCo HTML report not found!"
4042
exit 1
4143
fi
4244
43-
# Extract coverage percentages using awk for more reliable extraction
44-
COVERAGE_VALUES=$(grep -A10 '<td>Total</td>' target/site/jacoco/index.html | grep -E 'class="ctr2".*[0-9]+%' | sed -E 's/.*>([0-9]+)%<.*/\1/')
45-
46-
echo "Debug: All coverage values found:"
47-
echo "$COVERAGE_VALUES"
48-
49-
INSTRUCTION=$(echo "$COVERAGE_VALUES" | awk 'NR==1')
50-
BRANCH=$(echo "$COVERAGE_VALUES" | awk 'NR==2')
45+
# Extract the <tfoot> Total row and clean it up
46+
TOTAL_ROW=$(grep -A2 "<td>Total</td>" "$REPORT" | tr -d '\n')
47+
48+
# Extract numeric percentages in order (Instruction first, Branch second)
49+
PERCENTAGES=($(echo "$TOTAL_ROW" | grep -oE '[0-9]+%' | sed 's/%//g'))
50+
51+
INSTRUCTION=${PERCENTAGES[0]:-0}
52+
BRANCH=${PERCENTAGES[1]:-0}
5153
52-
echo "📘 Instruction Coverage: ${INSTRUCTION:-0}%"
53-
echo "🌿 Branch Coverage: ${BRANCH:-0}%"
54+
echo "📘 Instruction Coverage: ${INSTRUCTION}%"
55+
echo "🌿 Branch Coverage: ${BRANCH}%"
5456
55-
echo "instruction=${INSTRUCTION:-0}" >> $GITHUB_OUTPUT
56-
echo "branch=${BRANCH:-0}" >> $GITHUB_OUTPUT
57+
echo "instruction=${INSTRUCTION}" >> $GITHUB_OUTPUT
58+
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
5759
5860
- name: 💬 Post coverage summary as PR comment
5961
uses: marocchino/sticky-pull-request-comment@v2

0 commit comments

Comments
 (0)