Skip to content

Commit 4ec0ae3

Browse files
authored
Test multiple Python versions in CI (#151)
* Test multiple Python versions in ci Support testing with multiple Python versions using a matrix. Test with 3.12 and 3.13 currently. * Use Python venv for coverage too
1 parent 7b5c406 commit 4ec0ae3

File tree

1 file changed

+64
-49
lines changed

1 file changed

+64
-49
lines changed

.github/workflows/ci.yaml

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

1212
env:
13-
DEFAULT_PYTHON: "3.12"
13+
DEFAULT_PYTHON: "3.13"
1414
PRE_COMMIT_CACHE: ~/.cache/pre-commit
1515

1616
concurrency:
@@ -22,25 +22,28 @@ jobs:
2222
# This prevent upcoming jobs to do the same individually
2323
prepare:
2424
runs-on: ubuntu-latest
25+
strategy:
26+
matrix:
27+
python-version: ["3.12", "3.13"]
2528
outputs:
26-
python-version: ${{ steps.python.outputs.python-version }}
27-
name: Prepare Python dependencies
29+
python-version: ${{ matrix.python-version }}
30+
name: Prepare Python ${{ matrix.python-version }} dependencies
2831
steps:
2932
- name: Check out code from GitHub
3033
uses: actions/[email protected]
3134
- name: Set up Python
3235
id: python
3336
uses: actions/[email protected]
3437
with:
35-
python-version: ${{ env.DEFAULT_PYTHON }}
38+
python-version: ${{ matrix.python-version }}
3639
- name: Restore Python virtual environment
3740
id: cache-venv
3841
uses: actions/[email protected]
3942
with:
4043
path: venv
41-
key: |
42-
${{ runner.os }}-venv-${{ steps.python.outputs.python-version }}-${{
43-
hashFiles('pyproject.toml') }}
44+
key: >
45+
${{ runner.os }}-venv-${{ matrix.python-version }}-
46+
${{ hashFiles('pyproject.toml') }}
4447
- name: Create Python virtual environment
4548
if: steps.cache-venv.outputs.cache-hit != 'true'
4649
run: |
@@ -54,9 +57,9 @@ jobs:
5457
with:
5558
path: ${{ env.PRE_COMMIT_CACHE }}
5659
lookup-only: true
57-
key: |
58-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
59-
}}
60+
key: >
61+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
62+
${{ hashFiles('.pre-commit-config.yaml') }}
6063
restore-keys: |
6164
${{ runner.os }}-pre-commit-
6265
- name: Install pre-commit dependencies
@@ -66,25 +69,28 @@ jobs:
6669
pre-commit install-hooks
6770
6871
lint-ruff-format:
69-
name: Check ruff-format
72+
name: Check ruff-format Python ${{ matrix.python-version }}
7073
runs-on: ubuntu-latest
7174
needs: prepare
75+
strategy:
76+
matrix:
77+
python-version: ["3.12", "3.13"]
7278
steps:
7379
- name: Check out code from GitHub
7480
uses: actions/[email protected]
75-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
81+
- name: Set up Python ${{ matrix.python-version }}
7682
uses: actions/[email protected]
7783
id: python
7884
with:
79-
python-version: ${{ needs.prepare.outputs.python-version }}
85+
python-version: ${{ matrix.python-version }}
8086
- name: Restore Python virtual environment
8187
id: cache-venv
8288
uses: actions/[email protected]
8389
with:
8490
path: venv
85-
key: |
86-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
87-
}}-${{ hashFiles('pyproject.toml') }}
91+
key: >
92+
${{ runner.os }}-venv-${{ matrix.python-version }}-
93+
${{ hashFiles('pyproject.toml') }}
8894
- name: Fail job if Python cache restore failed
8995
if: steps.cache-venv.outputs.cache-hit != 'true'
9096
run: |
@@ -95,9 +101,9 @@ jobs:
95101
uses: actions/[email protected]
96102
with:
97103
path: ${{ env.PRE_COMMIT_CACHE }}
98-
key: |
99-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
100-
}}
104+
key: >
105+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
106+
${{ hashFiles('.pre-commit-config.yaml') }}
101107
- name: Fail job if cache restore failed
102108
if: steps.cache-venv.outputs.cache-hit != 'true'
103109
run: |
@@ -112,25 +118,28 @@ jobs:
112118
RUFF_OUTPUT_FORMAT: github
113119

114120
lint-ruff:
115-
name: Check ruff
121+
name: Check ruff Python ${{ matrix.python-version }}
116122
runs-on: ubuntu-latest
117123
needs: prepare
124+
strategy:
125+
matrix:
126+
python-version: ["3.12", "3.13"]
118127
steps:
119128
- name: Check out code from GitHub
120129
uses: actions/[email protected]
121-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
130+
- name: Set up Python ${{ matrix.python-version }}
122131
uses: actions/[email protected]
123132
id: python
124133
with:
125-
python-version: ${{ needs.prepare.outputs.python-version }}
134+
python-version: ${{ matrix.python-version }}
126135
- name: Restore Python virtual environment
127136
id: cache-venv
128137
uses: actions/[email protected]
129138
with:
130139
path: venv
131-
key: |
132-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
133-
}}-${{ hashFiles('pyproject.toml') }}
140+
key: >
141+
${{ runner.os }}-venv-${{ matrix.python-version }}-
142+
${{ hashFiles('pyproject.toml') }}
134143
- name: Fail job if Python cache restore failed
135144
if: steps.cache-venv.outputs.cache-hit != 'true'
136145
run: |
@@ -141,9 +150,9 @@ jobs:
141150
uses: actions/[email protected]
142151
with:
143152
path: ${{ env.PRE_COMMIT_CACHE }}
144-
key: |
145-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
146-
}}
153+
key: >
154+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
155+
${{ hashFiles('.pre-commit-config.yaml') }}
147156
- name: Fail job if cache restore failed
148157
if: steps.cache-venv.outputs.cache-hit != 'true'
149158
run: |
@@ -158,25 +167,28 @@ jobs:
158167
RUFF_OUTPUT_FORMAT: github
159168

160169
lint-other:
161-
name: Check other linters
170+
name: Check other linters Python ${{ matrix.python-version }}
162171
runs-on: ubuntu-24.04
163172
needs: prepare
173+
strategy:
174+
matrix:
175+
python-version: ["3.12", "3.13"]
164176
steps:
165177
- name: Check out code from GitHub
166178
uses: actions/[email protected]
167-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
179+
- name: Set up Python ${{ matrix.python-version }}
168180
uses: actions/[email protected]
169181
id: python
170182
with:
171-
python-version: ${{ needs.prepare.outputs.python-version }}
183+
python-version: ${{ matrix.python-version }}
172184
- name: Restore Python virtual environment
173185
id: cache-venv
174186
uses: actions/[email protected]
175187
with:
176188
path: venv
177-
key: |
178-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
179-
}}-${{ hashFiles('pyproject.toml') }}
189+
key: >
190+
${{ runner.os }}-venv-${{ matrix.python-version }}-
191+
${{ hashFiles('pyproject.toml') }}
180192
- name: Fail job if Python cache restore failed
181193
if: steps.cache-venv.outputs.cache-hit != 'true'
182194
run: |
@@ -187,9 +199,9 @@ jobs:
187199
uses: actions/[email protected]
188200
with:
189201
path: ${{ env.PRE_COMMIT_CACHE }}
190-
key: |
191-
${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml')
192-
}}
202+
key: >
203+
${{ runner.os }}-pre-commit-${{ matrix.python-version }}-
204+
${{ hashFiles('.pre-commit-config.yaml') }}
193205
- name: Fail job if cache restore failed
194206
if: steps.cache-venv.outputs.cache-hit != 'true'
195207
run: |
@@ -249,23 +261,26 @@ jobs:
249261
pytest:
250262
runs-on: ubuntu-latest
251263
needs: prepare
252-
name: Run tests Python ${{ needs.prepare.outputs.python-version }}
264+
strategy:
265+
matrix:
266+
python-version: ["3.12", "3.13"]
267+
name: Run tests Python ${{ matrix.python-version }}
253268
steps:
254269
- name: Check out code from GitHub
255270
uses: actions/[email protected]
256-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
271+
- name: Set up Python ${{ matrix.python-version }}
257272
uses: actions/[email protected]
258273
id: python
259274
with:
260-
python-version: ${{ needs.prepare.outputs.python-version }}
275+
python-version: ${{ matrix.python-version }}
261276
- name: Restore Python virtual environment
262277
id: cache-venv
263278
uses: actions/[email protected]
264279
with:
265280
path: venv
266-
key: |
267-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
268-
}}-${{ hashFiles('pyproject.toml') }}
281+
key: >
282+
${{ runner.os }}-venv-${{ matrix.python-version }}-
283+
${{ hashFiles('pyproject.toml') }}
269284
- name: Fail job if Python cache restore failed
270285
if: steps.cache-venv.outputs.cache-hit != 'true'
271286
run: |
@@ -304,26 +319,26 @@ jobs:
304319
steps:
305320
- name: Check out code from GitHub
306321
uses: actions/[email protected]
307-
- name: Set up Python ${{ needs.prepare.outputs.python-version }}
322+
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
308323
uses: actions/[email protected]
309324
id: python
310325
with:
311-
python-version: ${{ needs.prepare.outputs.python-version }}
326+
python-version: ${{ env.DEFAULT_PYTHON }}
312327
- name: Restore Python virtual environment
313328
id: cache-venv
314329
uses: actions/[email protected]
315330
with:
316331
path: venv
317-
key: |
318-
${{ runner.os }}-venv-${{ needs.prepare.outputs.python-version
319-
}}-${{ hashFiles('pyproject.toml') }}
332+
key: >
333+
${{ runner.os }}-venv-${{ env.DEFAULT_PYTHON }}-
334+
${{ hashFiles('pyproject.toml') }}
320335
- name: Fail job if Python cache restore failed
321336
if: steps.cache-venv.outputs.cache-hit != 'true'
322337
run: |
323338
echo "Failed to restore Python virtual environment from cache"
324339
exit 1
325340
- name: Download all coverage artifacts
326-
uses: actions/download-artifact@v4.1.8
341+
uses: actions/download-artifact@v5.0.0
327342
- name: Combine coverage results
328343
run: |
329344
. venv/bin/activate

0 commit comments

Comments
 (0)