-
Notifications
You must be signed in to change notification settings - Fork 548
261 lines (226 loc) · 8.73 KB
/
Copy pathtests.yml
File metadata and controls
261 lines (226 loc) · 8.73 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
name: Tests
on:
push:
branches: [main]
pull_request:
jobs:
changes:
runs-on: ubuntu-latest
outputs:
code: ${{ steps.filter.outputs.code }}
test_matrix: ${{ steps.matrix.outputs.include }}
steps:
- name: Check out the repository
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Detect changed paths
id: filter
uses: dorny/paths-filter@v4
with:
predicate-quantifier: every
filters: |
code:
- "**"
- "!docs/**"
- "!*.md"
- "!*.rst"
- name: Select Nox matrix
id: matrix
shell: python
run: |
import json
import os
checks = [
{"python": "3.10", "os": "ubuntu-latest", "session": "pre-commit"},
{"python": "3.10", "os": "ubuntu-latest", "session": "safety"},
{
"python": "3.11",
"os": "ubuntu-latest",
"session": "mypy",
"posargs": [
"camelot",
"tests",
"docs/conf.py",
"--allow-untyped-globals",
],
},
]
test_sessions = [
{"python": "3.12", "os": "ubuntu-latest", "session": "tests"},
{"python": "3.11", "os": "ubuntu-latest", "session": "tests"},
{"python": "3.10", "os": "ubuntu-latest", "session": "tests"},
{"python": "3.13", "os": "ubuntu-latest", "session": "tests"},
{"python": "3.14", "os": "ubuntu-latest", "session": "tests"},
{
"python": "3.15",
"os": "ubuntu-latest",
"session": "tests",
"experimental": True,
},
{"python": "3.10", "os": "windows-latest", "session": "tests"},
{"python": "3.10", "os": "macos-latest", "session": "tests"},
{"python": "3.10", "os": "ubuntu-latest", "session": "typeguard"},
{"python": "3.10", "os": "ubuntu-latest", "session": "xdoctest"},
]
docs_build = [
{"python": "3.13", "os": "ubuntu-latest", "session": "docs-build"},
]
matrix = checks
if "${{ steps.filter.outputs.code }}" == "true":
matrix += test_sessions
matrix += docs_build
with open(os.environ["GITHUB_OUTPUT"], mode="a") as output:
print(f"include={json.dumps(matrix)}", file=output)
tests:
name: ${{ matrix.session }} ${{ matrix.python }} / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: changes
# Allow the experimental (pre-release) Python entries to fail without
# failing the workflow as a whole. This job-level flag keeps a failing
# 3.15 row from failing the run, but GitHub still reports the individual
# matrix job as red; the step-level flag on "Run Nox" below is what turns
# the reported check green.
continue-on-error: ${{ matrix.experimental || false }}
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.changes.outputs.test_matrix) }}
env:
NOXSESSION: ${{ matrix.session }}
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
steps:
- name: Check out the repository
uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python }}
# Needed for the 3.15 experimental entry (pre-release); harmless for stable.
allow-prereleases: true
- name: Upgrade pip
# constraints.txt pins pip==26.x, which relies on
# `typing.no_type_check_decorator` that Python 3.15 removed.
# Skip the explicit upgrade on the 3.15 row and rely on the pip
# shipped by setup-python.
if: matrix.python != '3.15'
run: |
pip install --constraint="${PWD}/.github/workflows/constraints.txt" pip
pip --version
- name: Upgrade pip in virtual environments
shell: python
run: |
import os
import pip
with open(os.environ["GITHUB_ENV"], mode="a") as io:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Nox
run: |
pipx install --pip-args=--constraint="${PWD}/.github/workflows/constraints.txt" nox
nox --version
- name: Install ghostscript
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
# libjpeg-dev + zlib1g-dev are needed when uv builds Pillow from
# source on the Python 3.15 row (no Pillow wheel ships for 3.15
# pre-releases yet). They're harmless / idempotent on the other
# Python rows where Pillow installs from a wheel directly.
sudo apt install -y ghostscript libjpeg-dev zlib1g-dev
- name: Install ghostscript (macos-latest)
if: matrix.os == 'macos-latest'
run: |
brew install ghostscript
mkdir -p ~/lib
ln -s "$(brew --prefix gs)/lib/libgs.dylib" ~/lib
- name: Install ghostscript (windows-latest)
if: matrix.os == 'windows-latest'
run: |
choco install --yes --no-progress --ignore-checksums ghostscript --version 9.56.1
- name: Compute pre-commit cache key
if: matrix.session == 'pre-commit'
id: pre-commit-cache
shell: python
run: |
import hashlib
import os
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
with open(os.environ["GITHUB_OUTPUT"], mode="a") as output:
print("result={}".format(result), file=output)
- name: Restore pre-commit cache
uses: actions/cache@v6
if: matrix.session == 'pre-commit'
with:
path: ~/.cache/pre-commit
key: ${{ steps.pre-commit-cache.outputs.result }}-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.pre-commit-cache.outputs.result }}-
- name: Run Nox
# Tolerate failures on the pre-release (experimental) Python rows at
# the *step* level so the job's check reports green. A core dependency
# such as pandas frequently has no wheel for a new pre-release yet and
# cannot be built from source (e.g. pandas' meson build errors with
# "Unknown compiler(s): cython" on 3.15), which would otherwise mark
# every PR's "tests 3.15" check red. The row still runs to give early
# signal and will pass on its own once upstream wheels land.
continue-on-error: ${{ matrix.experimental || false }}
run: |
nox --python=${{ matrix.python }}
- name: Upload coverage data
if: always() && matrix.session == 'tests'
uses: "actions/upload-artifact@v7"
with:
name: coverage-data-${{ matrix.session }}-${{ matrix.python }}-${{ matrix.os }}
path: ".coverage.*"
if-no-files-found: ignore
include-hidden-files: true
- name: Upload documentation
if: matrix.session == 'docs-build'
uses: actions/upload-artifact@v7
with:
name: docs
path: docs/_build
coverage:
runs-on: ubuntu-latest
needs: [changes, tests]
if: needs.changes.outputs.code == 'true'
steps:
- name: Check out the repository
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.10"
- name: Upgrade pip
run: |
pip install --constraint="${PWD}/.github/workflows/constraints.txt" pip
pip --version
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install Nox
run: |
pipx install --pip-args=--constraint="${PWD}/.github/workflows/constraints.txt" nox
nox --version
- name: Download coverage data
uses: actions/download-artifact@v8
with:
pattern: coverage-data-*
merge-multiple: true
- name: Combine coverage data and display human readable report
run: |
nox --session=coverage
- name: Create coverage report
run: |
nox --session=coverage -- xml -i
- name: Upload coverage report
uses: codecov/codecov-action@v7
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml