Skip to content

Commit 800c449

Browse files
committed
Test multiple Python versions in ci
Support testing with multiple Python versions using a matrix. Test with 3.12 and 3.13 currently.
1 parent 7b5c406 commit 800c449

File tree

1 file changed

+69
-67
lines changed

1 file changed

+69
-67
lines changed

.github/workflows/ci.yaml

Lines changed: 69 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ on:
1010
workflow_dispatch:
1111

1212
env:
13-
DEFAULT_PYTHON: "3.12"
1413
PRE_COMMIT_CACHE: ~/.cache/pre-commit
1514

1615
concurrency:
@@ -22,25 +21,28 @@ jobs:
2221
# This prevent upcoming jobs to do the same individually
2322
prepare:
2423
runs-on: ubuntu-latest
24+
strategy:
25+
matrix:
26+
python-version: ["3.12", "3.13"]
2527
outputs:
26-
python-version: ${{ steps.python.outputs.python-version }}
27-
name: Prepare Python dependencies
28+
python-version: ${{ matrix.python-version }}
29+
name: Prepare Python ${{ matrix.python-version }} dependencies
2830
steps:
2931
- name: Check out code from GitHub
3032
uses: actions/[email protected]
3133
- name: Set up Python
3234
id: python
3335
uses: actions/[email protected]
3436
with:
35-
python-version: ${{ env.DEFAULT_PYTHON }}
37+
python-version: ${{ matrix.python-version }}
3638
- name: Restore Python virtual environment
3739
id: cache-venv
3840
uses: actions/[email protected]
3941
with:
4042
path: venv
41-
key: |
42-
${{ runner.os }}-venv-${{ steps.python.outputs.python-version }}-${{
43-
hashFiles('pyproject.toml') }}
43+
key: >
44+
${{ runner.os }}-venv-${{ matrix.python-version }}-
45+
${{ hashFiles('pyproject.toml') }}
4446
- name: Create Python virtual environment
4547
if: steps.cache-venv.outputs.cache-hit != 'true'
4648
run: |
@@ -54,9 +56,9 @@ jobs:
5456
with:
5557
path: ${{ env.PRE_COMMIT_CACHE }}
5658
lookup-only: true
57-
key: |
58-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
59-
}}
59+
key: >
60+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
61+
${{ hashFiles('.pre-commit-config.yaml') }}
6062
restore-keys: |
6163
${{ runner.os }}-pre-commit-
6264
- name: Install pre-commit dependencies
@@ -66,25 +68,28 @@ jobs:
6668
pre-commit install-hooks
6769
6870
lint-ruff-format:
69-
name: Check ruff-format
71+
name: Check ruff-format Python ${{ matrix.python-version }}
7072
runs-on: ubuntu-latest
7173
needs: prepare
74+
strategy:
75+
matrix:
76+
python-version: ["3.12", "3.13"]
7277
steps:
7378
- name: Check out code from GitHub
7479
uses: actions/[email protected]
75-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
80+
- name: Set up Python ${{ matrix.python-version }}
7681
uses: actions/[email protected]
7782
id: python
7883
with:
79-
python-version: ${{ needs.prepare.outputs.python-version }}
84+
python-version: ${{ matrix.python-version }}
8085
- name: Restore Python virtual environment
8186
id: cache-venv
8287
uses: actions/[email protected]
8388
with:
8489
path: venv
85-
key: |
86-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
87-
}}-${{ hashFiles('pyproject.toml') }}
90+
key: >
91+
${{ runner.os }}-venv-${{ matrix.python-version }}-
92+
${{ hashFiles('pyproject.toml') }}
8893
- name: Fail job if Python cache restore failed
8994
if: steps.cache-venv.outputs.cache-hit != 'true'
9095
run: |
@@ -95,9 +100,9 @@ jobs:
95100
uses: actions/[email protected]
96101
with:
97102
path: ${{ env.PRE_COMMIT_CACHE }}
98-
key: |
99-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
100-
}}
103+
key: >
104+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
105+
${{ hashFiles('.pre-commit-config.yaml') }}
101106
- name: Fail job if cache restore failed
102107
if: steps.cache-venv.outputs.cache-hit != 'true'
103108
run: |
@@ -112,25 +117,28 @@ jobs:
112117
RUFF_OUTPUT_FORMAT: github
113118

114119
lint-ruff:
115-
name: Check ruff
120+
name: Check ruff Python ${{ matrix.python-version }}
116121
runs-on: ubuntu-latest
117122
needs: prepare
123+
strategy:
124+
matrix:
125+
python-version: ["3.12", "3.13"]
118126
steps:
119127
- name: Check out code from GitHub
120128
uses: actions/[email protected]
121-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
129+
- name: Set up Python ${{ matrix.python-version }}
122130
uses: actions/[email protected]
123131
id: python
124132
with:
125-
python-version: ${{ needs.prepare.outputs.python-version }}
133+
python-version: ${{ matrix.python-version }}
126134
- name: Restore Python virtual environment
127135
id: cache-venv
128136
uses: actions/[email protected]
129137
with:
130138
path: venv
131-
key: |
132-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
133-
}}-${{ hashFiles('pyproject.toml') }}
139+
key: >
140+
${{ runner.os }}-venv-${{ matrix.python-version }}-
141+
${{ hashFiles('pyproject.toml') }}
134142
- name: Fail job if Python cache restore failed
135143
if: steps.cache-venv.outputs.cache-hit != 'true'
136144
run: |
@@ -141,9 +149,9 @@ jobs:
141149
uses: actions/[email protected]
142150
with:
143151
path: ${{ env.PRE_COMMIT_CACHE }}
144-
key: |
145-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
146-
}}
152+
key: >
153+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
154+
${{ hashFiles('.pre-commit-config.yaml') }}
147155
- name: Fail job if cache restore failed
148156
if: steps.cache-venv.outputs.cache-hit != 'true'
149157
run: |
@@ -158,25 +166,28 @@ jobs:
158166
RUFF_OUTPUT_FORMAT: github
159167

160168
lint-other:
161-
name: Check other linters
169+
name: Check other linters Python ${{ matrix.python-version }}
162170
runs-on: ubuntu-24.04
163171
needs: prepare
172+
strategy:
173+
matrix:
174+
python-version: ["3.12", "3.13"]
164175
steps:
165176
- name: Check out code from GitHub
166177
uses: actions/[email protected]
167-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
178+
- name: Set up Python ${{ matrix.python-version }}
168179
uses: actions/[email protected]
169180
id: python
170181
with:
171-
python-version: ${{ needs.prepare.outputs.python-version }}
182+
python-version: ${{ matrix.python-version }}
172183
- name: Restore Python virtual environment
173184
id: cache-venv
174185
uses: actions/[email protected]
175186
with:
176187
path: venv
177-
key: |
178-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
179-
}}-${{ hashFiles('pyproject.toml') }}
188+
key: >
189+
${{ runner.os }}-venv-${{ matrix.python-version }}-
190+
${{ hashFiles('pyproject.toml') }}
180191
- name: Fail job if Python cache restore failed
181192
if: steps.cache-venv.outputs.cache-hit != 'true'
182193
run: |
@@ -187,9 +198,9 @@ jobs:
187198
uses: actions/[email protected]
188199
with:
189200
path: ${{ env.PRE_COMMIT_CACHE }}
190-
key: |
191-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
192-
}}
201+
key: >
202+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
203+
${{ hashFiles('.pre-commit-config.yaml') }}
193204
- name: Fail job if cache restore failed
194205
if: steps.cache-venv.outputs.cache-hit != 'true'
195206
run: |
@@ -249,23 +260,26 @@ jobs:
249260
pytest:
250261
runs-on: ubuntu-latest
251262
needs: prepare
252-
name: Run tests Python ${{ needs.prepare.outputs.python-version }}
263+
strategy:
264+
matrix:
265+
python-version: ["3.12", "3.13"]
266+
name: Run tests Python ${{ matrix.python-version }}
253267
steps:
254268
- name: Check out code from GitHub
255269
uses: actions/[email protected]
256-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
270+
- name: Set up Python ${{ matrix.python-version }}
257271
uses: actions/[email protected]
258272
id: python
259273
with:
260-
python-version: ${{ needs.prepare.outputs.python-version }}
274+
python-version: ${{ matrix.python-version }}
261275
- name: Restore Python virtual environment
262276
id: cache-venv
263277
uses: actions/[email protected]
264278
with:
265279
path: venv
266-
key: |
267-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
268-
}}-${{ hashFiles('pyproject.toml') }}
280+
key: >
281+
${{ runner.os }}-venv-${{ matrix.python-version }}-
282+
${{ hashFiles('pyproject.toml') }}
269283
- name: Fail job if Python cache restore failed
270284
if: steps.cache-venv.outputs.cache-hit != 'true'
271285
run: |
@@ -300,35 +314,23 @@ jobs:
300314
coverage:
301315
name: Process test coverage
302316
runs-on: ubuntu-latest
303-
needs: ["pytest", "prepare"]
317+
needs: ["pytest"]
304318
steps:
305319
- name: Check out code from GitHub
306320
uses: actions/[email protected]
307-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
308-
uses: actions/[email protected]
309-
id: python
310321
with:
311-
python-version: ${{ needs.prepare.outputs.python-version }}
312-
- name: Restore Python virtual environment
313-
id: cache-venv
314-
uses: actions/[email protected]
315-
with:
316-
path: venv
317-
key: |
318-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
319-
}}-${{ hashFiles('pyproject.toml') }}
320-
- name: Fail job if Python cache restore failed
321-
if: steps.cache-venv.outputs.cache-hit != 'true'
322-
run: |
323-
echo "Failed to restore Python virtual environment from cache"
324-
exit 1
325-
- name: Download all coverage artifacts
322+
fetch-depth: 0
323+
- name: Download coverage data
326324
uses: actions/[email protected]
327-
- name: Combine coverage results
325+
- name: Set up uv
326+
uses: astral-sh/[email protected]
327+
with:
328+
enable-cache: true
329+
- name: Install dependencies
330+
run: uv sync --frozen --dev
331+
- name: Process coverage results
328332
run: |
329-
. venv/bin/activate
330-
coverage combine coverage*/.coverage*
331-
coverage report
332-
coverage xml
333+
uv run --frozen coverage combine coverage*/.coverage*
334+
uv run --frozen coverage xml -i
333335
- name: Upload coverage to Codecov
334336
uses: codecov/[email protected]

0 commit comments

Comments
 (0)