Repository navigation
199 lines (176 loc) · 6.86 KB
/
Copy pathci.yml
File metadata and controls
199 lines (176 loc) · 6.86 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
# Lint, type-check and test on every push and pull request.
#
# The package has no runtime dependencies, so the matrix is cheap: every
# supported Python, the full test suite with the coverage floor from
# pyproject.toml, and a wheel smoke test on one of them. poppler is
# installed so the PDF tests run rather than skip.
#
# Test (Python X) ruff, mypy, pytest with coverage, the wheel,
# and 30 seconds of the header fuzzer on one Python
# Lockfile is current uv.lock matches pyproject.toml
# Trivy scan HIGH/CRITICAL fixed vulnerabilities in what
# uv.lock resolves
# Security zizmor on the workflows, gitleaks on the
# whole history
# Shared templates are current cliff.toml and .githooks/commit-msg match
# scattercode/release-pipelines
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
name: Test (Python ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ["3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/checkout@v7
with:
# hatch-vcs derives the version from `git describe --tags`; a
# shallow clone has no tags reachable and the package would
# report 0.1.dev1+g<sha>.
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
cache: pip
- name: Install poppler, for the PDF tests
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends poppler-utils
- name: Install the package with the development extra
run: pip install -e '.[dev]'
- name: Lint
run: |
ruff check .
ruff format --check .
- name: Type-check
run: mypy
- name: Test
run: pytest --cov --cov-report=term-missing
# A short run of the header fuzzer on one Python: well-formed files
# damaged at random, every outcome a verdict. The weekly run in
# security.yml is the long one. The run id seeds it, so a failure
# can be repeated with `--seed <run id>`; the id goes through the
# environment, never into the script text.
- name: Fuzz the header readers for 30 seconds
if: matrix.python == '3.12'
env:
FUZZ_SEED: ${{ github.run_id }}
run: python scripts/fuzz_headers.py --seconds 30 --seed "$FUZZ_SEED"
# The wheel, not the editable install: catches files that work from
# `pip install -e .` but were left out of the wheel.
- name: Build and smoke-test the wheel
if: matrix.python == '3.12'
run: |
pip install --quiet build twine
python -m build
twine check --strict dist/*
python -m venv /tmp/smoke
/tmp/smoke/bin/pip install --quiet dist/*.whl
printf '%%!PS-Adobe-3.0 EPSF-3.0\n' > /tmp/page.png
if /tmp/smoke/bin/sillybos /tmp/page.png; then echo "::error::a PostScript file passed"; exit 1; fi
/tmp/smoke/bin/python -c "import sillybos; print(sillybos.__version__)"
lockfile:
name: Lockfile is current
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
# uv.lock pins the resolved development tooling so scanners see real
# versions, not ranges. Regenerate with `uv lock` after any
# pyproject.toml change.
- uses: astral-sh/setup-uv@v7
- run: uv lock --check
# Same arrangement as the sibling repositories. The committed uv.lock is
# what makes the scan worthwhile for Python: pyproject.toml declares
# ranges, but the lock carries every resolved version.
trivy:
name: Trivy scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Scan for vulnerabilities
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: fs
scan-ref: .
format: table
exit-code: "1"
ignore-unfixed: true
vuln-type: library
severity: HIGH,CRITICAL
- name: Generate SBOM
uses: aquasecurity/trivy-action@v0.36.0
if: always()
with:
scan-type: fs
scan-ref: .
format: cyclonedx
output: sbom.cdx.json
exit-code: "0"
- name: Upload SBOM
uses: actions/upload-artifact@v7
if: always()
with:
name: sbom-source-tree
path: sbom.cdx.json
retention-days: 90
# Static analysis of the workflows (zizmor: injection, unpinned actions,
# over-broad permissions) and a scan of the whole history for secrets
# (gitleaks). Both run before push and commit through lefthook too; this
# is the backstop for a laptop without the hooks.
security:
name: Security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- uses: astral-sh/setup-uv@v7
- name: Workflows
run: uvx zizmor --min-severity medium .github/workflows
# The gitleaks binary rather than gitleaks/gitleaks-action, which
# needs a licence key (GITLEAKS_LICENSE) in a repository owned by an
# organisation. Pinned to a release and its checksum.
- name: Secrets in the history
env:
GITLEAKS_VERSION: 8.30.1
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
run: |
set -euo pipefail
tarball="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
curl -fsSLO "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/${tarball}"
echo "${GITLEAKS_SHA256} ${tarball}" | sha256sum --check -
tar -xzf "$tarball" gitleaks
./gitleaks git --no-banner --redact --verbose .
# cliff.toml and .githooks/commit-msg are copies of the shared templates in
# scattercode/release-pipelines. They have to be real files here -- git-cliff
# reads one from the repository root and git runs the other from the checkout
# -- so they cannot be referenced remotely the way the next-version action
# is. This is what stops a copy drifting unnoticed.
templates:
name: Shared templates are current
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Check out the shared templates
uses: actions/checkout@v7
with:
repository: scattercode/release-pipelines
ref: v1
path: .release-pipelines
persist-credentials: false
- name: Compare
run: ./.release-pipelines/sync.sh --check .