Skip to content

Commit b75f4d2

Browse files
committed
Enforced a minimum coverage percentage threshold of 85 percentage
1 parent cec9644 commit b75f4d2

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

.github/workflows/coverage-check.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,44 @@ jobs:
8888
#----------------------------------------------
8989
# check coverage percentage
9090
#----------------------------------------------
91-
- name: Report coverage percentage
91+
- name: Check coverage percentage
92+
if: steps.override.outputs.override == 'false'
9293
run: |
9394
COVERAGE_FILE="coverage.xml"
9495
if [ ! -f "$COVERAGE_FILE" ]; then
9596
echo "ERROR: Coverage file not found at $COVERAGE_FILE"
9697
exit 1
9798
fi
98-
99+
99100
# Install xmllint if not available
100101
if ! command -v xmllint &> /dev/null; then
101102
sudo apt-get update && sudo apt-get install -y libxml2-utils
102103
fi
103-
104+
104105
COVERED=$(xmllint --xpath "string(//coverage/@lines-covered)" "$COVERAGE_FILE")
105106
TOTAL=$(xmllint --xpath "string(//coverage/@lines-valid)" "$COVERAGE_FILE")
106-
107-
# Calculate percentage using Python for precision
108107
PERCENTAGE=$(python3 -c "covered=${COVERED}; total=${TOTAL}; print(round((covered/total)*100, 2))")
109-
110-
echo "📊 Branch Coverage: ${PERCENTAGE}%"
108+
109+
echo "Branch Coverage: $PERCENTAGE%"
110+
echo "Required Coverage: 85%"
111+
112+
# Use Python to compare the coverage with 85
113+
python3 -c "import sys; sys.exit(0 if float('$PERCENTAGE') >= 85 else 1)"
114+
if [ $? -eq 1 ]; then
115+
echo "ERROR: Coverage is $PERCENTAGE%, which is less than the required 85%"
116+
exit 1
117+
else
118+
echo "SUCCESS: Coverage is $PERCENTAGE%, which meets the required 85%"
119+
fi
120+
121+
#----------------------------------------------
122+
# coverage enforcement summary
123+
#----------------------------------------------
124+
- name: Coverage enforcement summary
125+
run: |
126+
if [ "${{ steps.override.outputs.override }}" == "true" ]; then
127+
echo "⚠️ Coverage checks bypassed: ${{ steps.override.outputs.reason }}"
128+
echo "Please ensure this override is justified and temporary"
129+
else
130+
echo "✅ Coverage checks enforced - minimum 85% required"
131+
fi

0 commit comments

Comments
 (0)