Skip to content

Commit 8d8ef39

Browse files
committed
Improve maintainability index parsing and scoring
Enhanced the workflow to robustly parse both numeric and letter grade maintainability index outputs from Radon. Adjusted the overall quality score calculation to handle a 0-20 maintainability scale and added error handling for missing or invalid metrics.
1 parent 4857f98 commit 8d8ef39

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

.github/workflows/quality-gates.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,24 @@ jobs:
8989
# Maintainability Index
9090
echo "### Maintainability Index" >> quality-report.md
9191
radon mi src/ --show >> maintainability.txt
92-
MI_SCORE=$(radon mi src/ | grep -o '[0-9]\+\.[0-9]\+' | head -1)
92+
93+
# Parse maintainability - handle both numeric scores and letter grades
94+
MI_RAW=$(radon mi src/ | grep -E '(^|:)[A-Z]|[0-9]+\.[0-9]+' | head -1)
95+
MI_SCORE=$(python -c "
96+
import re
97+
raw = '${MI_RAW}'
98+
# Try to extract numeric score first
99+
numeric = re.search(r'([0-9]+\.?[0-9]*)', raw)
100+
if numeric:
101+
score = float(numeric.group(1))
102+
else:
103+
# Convert letter grade to numeric score
104+
grade_map = {'A': 20, 'B': 15, 'C': 10, 'D': 5, 'F': 0}
105+
grade = re.search(r'([A-F])', raw)
106+
score = grade_map.get(grade.group(1) if grade else 'F', 10)
107+
print(score)
108+
")
109+
93110
echo "- Maintainability Index: ${MI_SCORE}" >> quality-report.md
94111
echo "- Target: > ${{ env.MINIMUM_QUALITY_SCORE }}" >> quality-report.md
95112
echo "- Status: $(python -c "print('✅ PASS' if float('${MI_SCORE}') > ${{ env.MINIMUM_QUALITY_SCORE }} else '❌ FAIL')")" >> quality-report.md
@@ -135,19 +152,22 @@ jobs:
135152
run: |
136153
# Calculate overall quality score
137154
SCORE=$(python -c "
138-
coverage = float('${COVERAGE}')
139-
complexity = float('${COMPLEXITY}')
140-
maintainability = float('${MAINTAINABILITY}')
141-
security = int('${SECURITY_ISSUES}')
142-
143-
# Scoring algorithm
144-
cov_score = min(coverage / ${{ env.MINIMUM_COVERAGE }}, 1.0) * 25
145-
comp_score = max(0, (6.0 - complexity) / 6.0) * 25
146-
maint_score = min(maintainability / 10.0, 1.0) * 25
147-
sec_score = 25 if security == 0 else max(0, 25 - security * 5)
148-
149-
total = cov_score + comp_score + maint_score + sec_score
150-
print(f'{total:.1f}')
155+
try:
156+
coverage = float('${COVERAGE}' or '0')
157+
complexity = float('${COMPLEXITY}' or '0')
158+
maintainability = float('${MAINTAINABILITY}' or '0')
159+
security = int('${SECURITY_ISSUES}' or '0')
160+
161+
# Scoring algorithm (0-100 scale)
162+
cov_score = min(coverage / ${{ env.MINIMUM_COVERAGE }}, 1.0) * 25
163+
comp_score = max(0, (6.0 - complexity) / 6.0) * 25
164+
maint_score = min(maintainability / 20.0, 1.0) * 25 # Adjusted for 0-20 scale
165+
sec_score = 25 if security == 0 else max(0, 25 - security * 5)
166+
167+
total = cov_score + comp_score + maint_score + sec_score
168+
print(f'{total:.1f}')
169+
except (ValueError, TypeError) as e:
170+
print('0.0') # Fallback score
151171
")
152172
153173
echo "### Overall Quality Score: ${SCORE}/100" >> quality-report.md

0 commit comments

Comments
 (0)