Skip to content

Commit 8aec33b

Browse files
feat: enhance pip-audit workflow to output JSON summaries and improve vulnerability reporting
Signed-off-by: kmilo <kmilo.denis.glez@yandex.com>
1 parent 86d9b43 commit 8aec33b

1 file changed

Lines changed: 55 additions & 4 deletions

File tree

‎.github/workflows/scan.yml‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,59 @@ jobs:
4545
- name: Install pip-audit
4646
run: python -m pip install pip-audit
4747

48-
- name: Audit requirements.txt
49-
run: pip-audit -r requirements.txt
48+
- name: Audit requirements.txt (JSON)
49+
run: |
50+
pip-audit -r requirements.txt --format json --output audit-requirements.json
51+
52+
- name: Audit installed environment (JSON)
53+
run: |
54+
pip-audit --format json --output audit-env.json
55+
56+
- name: Publish pip-audit summary to run summary
57+
env:
58+
GITHUB_STEP_SUMMARY: ${{ github.step_summary }}
59+
run: |
60+
python - <<'PY'
61+
import json, os, pathlib
62+
63+
def summarize(path):
64+
p = pathlib.Path(path)
65+
if not p.exists():
66+
return 0
67+
try:
68+
d = json.loads(p.read_text())
69+
if isinstance(d, list):
70+
return len(d)
71+
if isinstance(d, dict):
72+
for k in ('vulns','vulnerabilities','results'):
73+
if k in d and isinstance(d[k], list):
74+
return len(d[k])
75+
# Fallback: count top-level list-like values
76+
total = 0
77+
for v in d.values():
78+
if isinstance(v, list):
79+
total += len(v)
80+
return total
81+
except Exception:
82+
return 0
5083
51-
- name: Audit installed environment
52-
run: pip-audit
84+
req = summarize('audit-requirements.json')
85+
env = summarize('audit-env.json')
86+
summary = f"## pip-audit summary\n- requirements.txt vulnerabilities: {req}\n- installed environment vulnerabilities: {env}\n"
87+
print(summary)
88+
target = os.environ.get('GITHUB_STEP_SUMMARY')
89+
if target:
90+
with open(target, 'a') as fh:
91+
fh.write(summary)
92+
else:
93+
# Fallback to printing if summary file not available in older runners
94+
print('GITHUB_STEP_SUMMARY not set; summary printed above')
95+
PY
96+
97+
- name: Upload pip-audit JSON artifacts
98+
uses: actions/upload-artifact@v4
99+
with:
100+
name: pip-audit-results
101+
path: |
102+
audit-requirements.json
103+
audit-env.json

0 commit comments

Comments
 (0)