-
Notifications
You must be signed in to change notification settings - Fork 1
272 lines (229 loc) · 9.03 KB
/
Copy pathci.yml
File metadata and controls
272 lines (229 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: CI
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
workflow_dispatch:
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.10', '3.11', '3.12', '3.13']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install UV
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Install dependencies
run: |
uv sync
# Verify installation
uv run python -c "import mfcqi; print('MFCQI installed successfully')"
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y bc # For numeric comparisons in scripts
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install bc # For numeric comparisons in scripts
- name: Run all quality checks with coverage
shell: bash
env:
MFCQI_DISABLE_KEYRING: "1"
run: |
echo "🔍 Running comprehensive quality checks..."
# Run format and type checks
uv run ruff format --check src/ tests/
uv run mypy --strict src/mfcqi/
# Run tests with coverage (make test-all uses sequential execution to avoid hangs)
echo "🧪 Running test suite with coverage..."
uv run pytest tests/ --cov=src/mfcqi --cov-branch --cov-report=xml --cov-report=term-missing -v
echo "✅ All quality checks passed"
- name: Verify coverage file
if: matrix.os == 'ubuntu-latest'
run: |
ls -lh coverage.xml
echo "Coverage file size: $(stat -c%s coverage.xml 2>/dev/null || stat -f%z coverage.xml) bytes"
- name: Upload coverage reports to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: codecov-${{ matrix.os }}-py${{ matrix.python-version }}
fail_ci_if_error: true
verbose: true
- name: Run MFCQI self-analysis (Unix)
if: matrix.os != 'windows-latest'
env:
MFCQI_DISABLE_KEYRING: "1"
run: |
echo "📊 Running MFCQI analysis on itself..."
MFCQI_SCORE=$(uv run mfcqi-py analyze src/mfcqi --format json --silent | python -c "
import sys, json
try:
data = json.load(sys.stdin)
print(data['mfcqi_score'])
except:
print('0.0')
")
echo "Current MFCQI Score: $MFCQI_SCORE"
# Check if score meets minimum threshold
THRESHOLD="0.75"
if command -v bc >/dev/null 2>&1; then
if (( $(echo "$MFCQI_SCORE < $THRESHOLD" | bc -l) )); then
echo "⚠️ Warning: MFCQI score ($MFCQI_SCORE) is below recommended threshold ($THRESHOLD)"
echo "Code quality should be improved before merging"
else
echo "✅ MFCQI score meets quality threshold"
fi
else
echo "ℹ️ bc not available, skipping threshold check"
fi
- name: Run MFCQI self-analysis (Windows)
if: matrix.os == 'windows-latest'
shell: bash
env:
MFCQI_DISABLE_KEYRING: "1"
run: |
echo "📊 Running MFCQI analysis on itself..."
MFCQI_SCORE=$(uv run mfcqi-py analyze src/mfcqi --format json --silent | python -c "import sys, json; data = json.load(sys.stdin); print(data.get('mfcqi_score', 0.0))")
echo "Current MFCQI Score: $MFCQI_SCORE"
echo "✅ MFCQI analysis complete"
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}-py${{ matrix.python-version }}
path: |
pytest-report.xml
coverage.xml
htmlcov/
quality-gate:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
permissions:
pull-requests: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install UV
uses: astral-sh/setup-uv@v3
- name: Install dependencies
run: |
uv sync
# Verify installation
uv run python -c "import mfcqi; print('MFCQI installed successfully')"
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: test-results-ubuntu-latest-py3.10
path: ./coverage-data
- name: Generate quality report
id: quality
env:
MFCQI_DISABLE_KEYRING: "1"
run: |
# Run comprehensive analysis
echo "📊 Generating comprehensive quality report..."
# Get MFCQI score
MFCQI_OUTPUT=$(uv run mfcqi-py analyze src/mfcqi --format json)
MFCQI_SCORE=$(echo "$MFCQI_OUTPUT" | python -c "import sys, json; data=json.load(sys.stdin); print(data['mfcqi_score'])")
# Get test coverage from artifact (avoid re-running tests)
if [ -f ./coverage-data/coverage.xml ]; then
COVERAGE=$(python -c "import xml.etree.ElementTree as ET; tree = ET.parse('./coverage-data/coverage.xml'); root = tree.getroot(); print(root.attrib['line-rate'])" | awk '{printf "%.0f", $1*100}')
else
echo "⚠️ Coverage report not found, skipping coverage check"
COVERAGE="0"
fi
# Get security issues count
SECURITY_ISSUES=$(uv run bandit -r src/ -f json 2>/dev/null | python -c "import sys, json; data=json.load(sys.stdin); print(len(data.get('results', [])))" || echo "0")
# Store results
echo "mfcqi_score=$MFCQI_SCORE" >> $GITHUB_OUTPUT
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "security_issues=$SECURITY_ISSUES" >> $GITHUB_OUTPUT
# Determine overall status (lowered coverage threshold to 80%)
if (( $(echo "$MFCQI_SCORE >= 0.75" | bc -l) )) && (( $(echo "$COVERAGE >= 80" | bc -l) )) && [ "$SECURITY_ISSUES" -eq 0 ]; then
echo "status=passing" >> $GITHUB_OUTPUT
echo "emoji=✅" >> $GITHUB_OUTPUT
else
echo "status=warning" >> $GITHUB_OUTPUT
echo "emoji=⚠️" >> $GITHUB_OUTPUT
fi
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const mfcqiScore = '${{ steps.quality.outputs.mfcqi_score }}';
const coverage = '${{ steps.quality.outputs.coverage }}';
const securityIssues = '${{ steps.quality.outputs.security_issues }}';
const status = '${{ steps.quality.outputs.status }}';
const emoji = '${{ steps.quality.outputs.emoji }}';
const body = `## ${emoji} Code Quality Report
| Metric | Score | Status |
|--------|-------|--------|
| **MFCQI Score** | ${mfcqiScore} | ${parseFloat(mfcqiScore) >= 0.75 ? '✅ Good' : '⚠️ Needs Work'} |
| **Test Coverage** | ${coverage}% | ${parseFloat(coverage) >= 80 ? '✅ Good' : '⚠️ Needs Work'} |
| **Security Issues** | ${securityIssues} | ${securityIssues === '0' ? '✅ Clean' : '⚠️ Issues Found'} |
### Quality Gates
- **MFCQI Score**: ${parseFloat(mfcqiScore) >= 0.75 ? '✅' : '❌'} Minimum 0.75 (Current: ${mfcqiScore})
- **Test Coverage**: ${parseFloat(coverage) >= 80 ? '✅' : '❌'} Minimum 80% (Current: ${coverage}%)
- **Security**: ${securityIssues === '0' ? '✅' : '❌'} Zero vulnerabilities (Current: ${securityIssues})
${status === 'passing' ?
'🎉 **All quality gates passed!** This PR maintains high code quality standards.' :
'⚠️ **Some quality gates need attention.** Please review the metrics above before merging.'
}
<details>
<summary>📊 View detailed MFCQI breakdown</summary>
Run \`mfcqi-py analyze src/mfcqi\` locally to see detailed metrics breakdown.
</details>
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install build dependencies
run: |
pip install build twine
- name: Build package
run: |
python -m build
- name: Check package
run: |
python -m twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: python-package
path: dist/