-
Notifications
You must be signed in to change notification settings - Fork 10
157 lines (142 loc) · 5.43 KB
/
Copy pathdependency-audit.yml
File metadata and controls
157 lines (142 loc) · 5.43 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
name: Dependency Audit
env:
PYTHON_VERSION: "3.12"
# pip-audit compares the lockfile against advisory databases that publish
# continuously, so the result tracks the clock, not the commit. Hence the cron.
on:
schedule:
- cron: "17 6 * * *"
# Unfiltered: a required check behind a paths filter never reports on a
# pull request that misses the filter, which blocks the merge.
pull_request:
push:
branches: [main]
paths:
- "pyproject.toml"
- "uv.lock"
- ".github/workflows/dependency-audit.yml"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: dependency-audit-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
dependency-audit:
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
issues: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
persist-credentials: false
- name: 🐍 setup python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: 🛠️ install uv
run: |
python -m pip install --upgrade pip
pip install uv
- name: 🛡️ pip-audit (known CVEs in the locked deps)
id: audit
run: |
uv export --no-hashes --no-emit-project --format requirements-txt > /tmp/req-audit.txt
set +e
uvx pip-audit --strict --progress-spinner off --disable-pip --no-deps \
-r /tmp/req-audit.txt 2>&1 | tee /tmp/audit.log
status=${PIPESTATUS[0]}
set -e
# Written before the exit so the next step can quote it.
{
echo 'report<<AUDIT_REPORT_EOF'
cat /tmp/audit.log
echo 'AUDIT_REPORT_EOF'
} >> "$GITHUB_OUTPUT"
exit "$status"
# A scheduled run has no pull request to turn red, so record it instead.
- name: 📮 open or update the tracking issue
if: always() && steps.audit.outcome == 'failure' && github.event_name == 'schedule'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
AUDIT_REPORT: ${{ steps.audit.outputs.report }}
with:
script: |
const marker = '<!-- dependency-audit-tracking-issue -->';
const title = 'Dependency audit: known vulnerabilities in the locked dependencies';
const runUrl =
`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +
`/actions/runs/${context.runId}`;
const body = [
marker,
'`pip-audit` found known vulnerabilities in the locked dependency set.',
'',
'Bump the affected pins in `pyproject.toml`, run `uv lock`, and open a PR.',
'',
'```',
process.env.AUDIT_REPORT.trim(),
'```',
'',
`Run: ${runUrl}`,
`Last checked: ${new Date().toISOString()}`,
].join('\n');
const existing = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
const tracking = existing.find(
(issue) => !issue.pull_request && issue.body && issue.body.includes(marker),
);
if (tracking) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: tracking.number,
body,
});
core.notice(`Updated tracking issue #${tracking.number}`);
} else {
const created = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['dependencies'],
});
core.notice(`Opened tracking issue #${created.data.number}`);
}
- name: ✅ close the tracking issue once the audit is clean
if: always() && steps.audit.outcome == 'success' && github.event_name == 'schedule'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const marker = '<!-- dependency-audit-tracking-issue -->';
const existing = await github.paginate(github.rest.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
});
const tracking = existing.find(
(issue) => !issue.pull_request && issue.body && issue.body.includes(marker),
);
if (!tracking) {
return;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: tracking.number,
body: 'The scheduled audit is clean again. Closing.',
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: tracking.number,
state: 'closed',
});