-
Notifications
You must be signed in to change notification settings - Fork 19
444 lines (360 loc) · 14.7 KB
/
Copy pathci.yml
File metadata and controls
444 lines (360 loc) · 14.7 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: "17 4 * * 1"
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies
run: uv sync --locked --extra test
- name: Run tests with coverage
run: uv run pytest --cov --cov-report=xml --cov-report=term-missing
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
lint:
runs-on: ubuntu-latest
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies
run: uv sync --locked --extra lint
- name: Run ruff format
run: uv run ruff format --check src/ tests/
- name: Run ruff
run: uv run ruff check src/ tests/
- name: Run prospector
run: uv run prospector src/
- name: Install opengrep
run: |
curl -sSL https://github.com/opengrep/opengrep/releases/latest/download/opengrep-linux-x64 -o /usr/local/bin/opengrep
chmod +x /usr/local/bin/opengrep
- name: Run opengrep
run: opengrep scan --config=auto --severity=ERROR src/
- name: Run mypy
run: uv run mypy src/
- name: Run vulture
run: uv run vulture --min-confidence 90 .
test-languages:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies (with language support)
run: uv sync --locked --extra test --extra languages
- name: Run tests with coverage
run: uv run pytest --cov --cov-report=xml --cov-report=term-missing
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
- name: Run vulture
run: vulture --min-confidence 90 .
test-languages:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies (with language support)
run: uv pip install --system -e ".[all]"
- name: Run tests with coverage
run: pytest --cov --cov-report=xml --cov-report=term-missing
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: false
build:
runs-on: ubuntu-latest
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build package
run: |
uv sync --locked
uv run python -m pip install build
uv run python -m build
- name: Check package
run: uv run python -m pip install twine && uv run python -m twine check dist/*
smoke:
runs-on: ubuntu-latest
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies
run: uv sync --locked --extra test
- name: Run smoke tests (no skips allowed)
run: |
uv run pytest tests/test_reliability_smoke.py -q -rs --junitxml=smoke.xml
uv run python - <<'PY'
import sys
import xml.etree.ElementTree as ET
root = ET.parse("smoke.xml").getroot()
skipped = sum(int(s.attrib.get("skipped", "0")) for s in root.iter("testsuite"))
if skipped:
print(f"Smoke suite contains skipped tests ({skipped}), failing.")
sys.exit(1)
PY
robustness:
runs-on: ubuntu-latest
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies
run: uv sync --locked --extra test --extra languages
- name: Run tests with JUnit output
run: uv run pytest --junitxml=test-results.xml --cov --cov-report=xml
- name: Compute robustness metrics
run: |
uv run python - <<'PY'
import json, sys, subprocess, xml.etree.ElementTree as ET
from pathlib import Path
tree = ET.parse("test-results.xml")
total = 0; adv_total = 0; adv_passed = 0; norm_passed = 0
for suite in tree.iter("testsuite"):
name = suite.get("name","")
tests = int(suite.get("tests",0))
failures = int(suite.get("failures",0))
errors = int(suite.get("errors",0))
passed = tests - failures - errors
total += tests
if "adversarial" in name.lower():
adv_total += tests; adv_passed += passed
else:
norm_passed += passed
cov = 0.0
cov_path = Path("coverage.xml")
if cov_path.exists():
line_rate = float(ET.parse(str(cov_path)).getroot().get("line-rate",0))
cov = round(line_rate * 100, 1)
print(f"Total: {total} | Adversarial: {adv_total}/{adv_passed} passed | Normal: {norm_passed} passed | Coverage: {cov}%")
result = subprocess.run(
[sys.executable, "tools/robustness_evaluator.py",
"--n-total", str(total), "--n-adversarial", str(adv_total),
"--passing-adv", str(adv_passed), "--passing-norm", str(norm_passed),
"--coverage", str(cov), "--output-json"],
capture_output=True, text=True, check=False)
print(result.stdout)
if result.stderr:
print(result.stderr, file=sys.stderr)
data = json.loads(result.stdout)
if not data["meets_adversarial_minimum"]:
print("::warning::Adversarial minimum not met (below 25%)")
print(f"R={data['robustness_score']:.4f} [{data['robustness_label']}] | F={data['fragility_index']:.4f} [{data['fragility_label']}]")
PY
impactguard:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: cicd-sensor
uses: cicd-sensor/cicd-sensor-action@1935de498397aa7b9bf6ac7ca822ddb430a34843 # v0.0.31
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for git comparisons
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Install dependencies
run: uv sync --locked --extra test
- name: Run ImpactGuard analysis
id: impactguard
run: |
# Run ImpactGuard on the PR diff
uv run python -m impactguard check-commits \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }} \
--enforce-gate \
--strict-analysis \
--block-unknown \
-o impactguard-output
- name: Generate changelog from signature diffs
if: always()
run: |
uv run python -m impactguard generate-changelog \
${{ github.event.pull_request.base.sha }} \
${{ github.event.pull_request.head.sha }} \
CHANGELOG_PR.md
- name: Verify ImpactGuard artifacts exist
if: always()
run: |
test -f impactguard-output/risk_report.json
test -f impactguard-output/analysis_summary.json
test -f impactguard-output/gate_summary.json
- name: Append analysis summary
if: always()
run: |
{
echo "## ImpactGuard analysis summary"
if [ -f impactguard-output/analysis_summary.json ]; then
uv run python - <<'PY'
import json
from pathlib import Path
summary = json.loads(Path("impactguard-output/analysis_summary.json").read_text())
counters = summary.get("counters", {})
print(f"- status: {summary.get('status')}")
print(f"- parse_failures: {counters.get('parse_failures', 0)}")
print(f"- skipped_files: {counters.get('skipped_files', 0)}")
print(f"- unsupported_files: {counters.get('unsupported_files', 0)}")
print(f"- call_extraction_failures: {counters.get('call_extraction_failures', 0)}")
print(f"- runtime_data_issues: {counters.get('runtime_data_issues', 0)}")
print(f"- fqname_collision_risk: {counters.get('fqname_collision_risk', 0)}")
runtime = summary.get("runtime", {})
print(f"- runtime_state: {runtime.get('state', 'unknown')}")
policy = summary.get("policy", {})
violations = policy.get("violations", {})
print(f"- policy_violations: {len(violations)}")
if violations:
for key, detail in violations.items():
print(f" - {key}: {detail.get('value')} > {detail.get('max_allowed')}")
PY
else
echo "analysis_summary.json missing"
fi
if [ -f impactguard-output/gate_summary.json ]; then
echo ""
echo "### Gate"
uv run python - <<'PY'
import json
from pathlib import Path
gate = json.loads(Path("impactguard-output/gate_summary.json").read_text())
print(f"- blocked: {gate.get('blocked', False)}")
print(f"- high: {gate.get('risk', {}).get('high', 0)}")
print(f"- unknown: {gate.get('risk', {}).get('unknown', 0)}")
reasons = gate.get("reasons", [])
if reasons:
print("- reasons:")
for reason in reasons:
print(f" - {reason}")
PY
fi
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload ImpactGuard report
if: always()
uses: actions/upload-artifact@v4
with:
name: impactguard-report
path: |
impactguard-output/
CHANGELOG_PR.md
retention-days: 30
- name: Comment PR with summary
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let comment = '## ImpactGuard Analysis\n\n';
if (fs.existsSync('impactguard-output/risk_report.json')) {
const report = JSON.parse(fs.readFileSync('impactguard-output/risk_report.json', 'utf8'));
comment += '### Risk Summary\n';
comment += `- Total items: ${report.length}\n`;
const high = report.filter(i => i.risk === 'HIGH').length;
const medium = report.filter(i => i.risk === 'MEDIUM').length;
const low = report.filter(i => i.risk === 'LOW').length;
comment += `- HIGH risk: ${high}\n`;
comment += `- MEDIUM risk: ${medium}\n`;
comment += `- LOW risk: ${low}\n`;
}
if (fs.existsSync('impactguard-output/analysis_summary.json')) {
const analysis = JSON.parse(fs.readFileSync('impactguard-output/analysis_summary.json', 'utf8'));
const counters = analysis.counters || {};
comment += '\n### Analysis Coverage\n';
comment += `- Status: ${analysis.status || 'unknown'}\n`;
comment += `- parse_failures: ${counters.parse_failures || 0}\n`;
comment += `- skipped_files: ${counters.skipped_files || 0}\n`;
comment += `- call_extraction_failures: ${counters.call_extraction_failures || 0}\n`;
comment += `- runtime_data_issues: ${counters.runtime_data_issues || 0}\n`;
}
if (fs.existsSync('impactguard-output/gate_summary.json')) {
const gate = JSON.parse(fs.readFileSync('impactguard-output/gate_summary.json', 'utf8'));
comment += '\n### Gate\n';
comment += `- Blocked: ${gate.blocked ? 'yes' : 'no'}\n`;
if (Array.isArray(gate.reasons) && gate.reasons.length > 0) {
comment += '- Reasons:\n';
for (const reason of gate.reasons) comment += ` - ${reason}\n`;
}
}
if (fs.existsSync('CHANGELOG_PR.md')) {
const changelog = fs.readFileSync('CHANGELOG_PR.md', 'utf8');
comment += '\n### Changelog (Signature Changes)\n```\n' + changelog + '\n```\n';
}
comment += '\n📊 [View full report in artifacts](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})\n';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});