-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (211 loc) · 8.39 KB
/
Copy pathcoverage-ratchet.yml
File metadata and controls
240 lines (211 loc) · 8.39 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
name: Coverage Ratchet
on:
pull_request:
branches: [main, develop]
push:
branches: [main, develop]
jobs:
# Measure current coverage
measure-coverage:
name: Measure Coverage
runs-on: ubuntu-latest
outputs:
rust-coverage: ${{ steps.rust.outputs.coverage }}
python-coverage: ${{ steps.python.outputs.coverage }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Need history for comparison
- name: Setup Rust
uses: dtolnay/rust-toolchain@4be9e76fd7c4901c61fb841f559994984270fce7
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Measure Rust coverage
id: rust
working-directory: orchestrator
run: |
cargo tarpaulin --out Xml --output-dir coverage \
--exclude-files '*/tests/*' --timeout 600 -- --test-threads=1 || true
COVERAGE=$(python3 <<'EOF'
import xml.etree.ElementTree as ET
import sys
try:
tree = ET.parse('coverage/cobertura.xml')
root = tree.getroot()
pct = float(root.attrib['line-rate']) * 100
print(f"{pct:.1f}")
except:
print("0.0")
EOF
)
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "🦀 Rust coverage: ${COVERAGE}%"
- name: Measure Python coverage
id: python
working-directory: agent
run: |
python -m venv .venv
.venv/bin/pip install -q -e ".[dev]"
.venv/bin/pytest tests/ --cov=. --cov-report=xml -q
COVERAGE=$(python3 <<'EOF'
import xml.etree.ElementTree as ET
tree = ET.parse('coverage.xml')
root = tree.getroot()
pct = float(root.attrib.get('line-rate', 0)) * 100
print(f"{pct:.1f}")
EOF
)
echo "coverage=$COVERAGE" >> $GITHUB_OUTPUT
echo "🐍 Python coverage: ${COVERAGE}%"
# Enforce ratchet (prevent regression)
ratchet-enforcement:
name: Enforce Ratchet
runs-on: ubuntu-latest
needs: measure-coverage
steps:
- uses: actions/checkout@v6
- name: Create baseline if needed
run: |
if [ ! -f .coverage-baseline.json ]; then
cat > .coverage-baseline.json <<'EOF'
{
"rust": "0.0",
"python": "58.0",
"rust_target": "75.0",
"python_target": "75.0",
"rust_ratchet": "0.0",
"python_ratchet": "58.0"
}
EOF
echo "📊 Created initial baseline with Python at 58.0%"
fi
- name: Check Rust ratchet
run: |
CURRENT="${{ needs.measure-coverage.outputs.rust-coverage }}"
RATCHET=$(jq -r '.rust_ratchet' .coverage-baseline.json)
TARGET=$(jq -r '.rust_target' .coverage-baseline.json)
echo "🦀 Current: ${CURRENT}%, Ratchet: ${RATCHET}%, Target: ${TARGET}%"
if (( $(echo "$CURRENT < $RATCHET" | bc -l) )); then
echo "❌ Rust coverage ${CURRENT}% < ratchet ${RATCHET}%"
exit 1
fi
# Update ratchet if coverage improved
if (( $(echo "$CURRENT > $RATCHET" | bc -l) )); then
NEW_RATCHET=$CURRENT
echo "📈 Rust coverage improved, updating ratchet to ${NEW_RATCHET}%"
jq --arg nr "$NEW_RATCHET" '.rust_ratchet = $nr' .coverage-baseline.json > .tmp
mv .tmp .coverage-baseline.json
fi
- name: Check Python ratchet
run: |
CURRENT="${{ needs.measure-coverage.outputs.python-coverage }}"
RATCHET=$(jq -r '.python_ratchet' .coverage-baseline.json)
TARGET=$(jq -r '.python_target' .coverage-baseline.json)
echo "🐍 Current: ${CURRENT}%, Ratchet: ${RATCHET}%, Target: ${TARGET}%"
if (( $(echo "$CURRENT < $RATCHET" | bc -l) )); then
echo "❌ Python coverage ${CURRENT}% < ratchet ${RATCHET}%"
exit 1
fi
# Update ratchet if coverage improved
if (( $(echo "$CURRENT > $RATCHET" | bc -l) )); then
NEW_RATCHET=$CURRENT
echo "📈 Python coverage improved, updating ratchet to ${NEW_RATCHET}%"
jq --arg nr "$NEW_RATCHET" '.python_ratchet = $nr' .coverage-baseline.json > .tmp
mv .tmp .coverage-baseline.json
fi
- name: Configure git for CI
run: |
git config --global --add safe.directory "${GITHUB_WORKSPACE}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Commit updated ratchet
if: github.event_name == 'push'
run: |
git add .coverage-baseline.json
if ! git diff --staged --quiet; then
echo "Committing coverage ratchet update..."
git commit -m "chore: update coverage ratchet [skip ci]" --no-verify || {
echo "❌ Git commit failed"
echo "Current branch: $(git rev-parse --abbrev-ref HEAD)"
echo "Git status:"
git status
exit 1
}
echo "Pushing changes..."
git push || {
echo "⚠️ Git push failed (may retry later)"
# Don't fail the job - coverage measurement is still valid
}
else
echo "No coverage changes to commit"
fi
# Documentation freshness
doc-freshness:
name: Documentation Freshness
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Check doc freshness
run: |
python3 <<'EOF'
import re
from pathlib import Path
issues = []
for md_file in Path('docs').rglob('*.md'):
content = md_file.read_text()
# Check for TODO/FIXME in docs
if re.search(r'TODO|FIXME|XXX', content, re.IGNORECASE):
# Only warn, don't fail
print(f"⚠️ {md_file}: Contains TODO/FIXME markers")
# Check for outdated code examples
if '```' in content:
blocks = re.findall(r'```(\w*)\n(.*?)\n```', content, re.DOTALL)
for lang, code in blocks:
if lang in ['python', 'py']:
# Filter out comments and list items before checking (common in docs)
filtered_lines = []
for line in code.split('\n'):
stripped = line.strip()
if not stripped.startswith('#') and not stripped.startswith('-') and not stripped.startswith('*'):
filtered_lines.append(line)
filtered_code = '\n'.join(filtered_lines)
if filtered_code.strip(): # Only check if there's non-comment/list content
try:
compile(filtered_code, '<string>', 'exec')
except SyntaxError as e:
issues.append(f"{md_file}: Invalid Python code: {e}")
if issues:
print("❌ Documentation issues found:")
for issue in issues:
print(f" - {issue}")
exit(1)
else:
print("✅ Documentation freshness check passed")
EOF
# Stale issue/PR management
stale-management:
name: Stale Management
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/stale@v10
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-stale: 30
days-before-close: 14
stale-issue-label: "stale"
stale-pr-label: "stale"
exempt-issue-labels: "enhancement,good first issue"
exempt-pr-labels: "work-in-progress"
stale-issue-message: |
This issue has been inactive for 30 days. Will close in 14 days if no activity.
stale-pr-message: |
This PR has been inactive for 30 days. Will close in 14 days if no activity.