forked from nilearn/nilearn
-
Notifications
You must be signed in to change notification settings - Fork 0
306 lines (256 loc) · 10.2 KB
/
Copy pathtest_with_tox.yml
File metadata and controls
306 lines (256 loc) · 10.2 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
---
# Runs pytest in several environments including several Python and dependencies versions as well as on different systems.
# All environments are defined in `tox.ini <https://github.com/nilearn/nilearn/blob/main/tox.ini>`_.
#
# .. admonition:: Control via commit message
# :class: tip
#
# This workflow can be controlled if your commit message contains:
#
# - ``[skip test]`` skip this workflow.
#
# Uploads as artifacts:
#
# - ``report.html`` that gives a browsable overview of the tests results
#
# - ``pytest_output`` that contains a .csv of the tests results and figures showing the run time of all the tests
# See ``maint_tools/plot_test_timing.py``.
#
# - ``htmlcov`` containing the html version of the code coverage.
#
# .. admonition:: Not all python version run on pull requests.
# :class: warning
#
# When this workflow is triggered by a pull-request,
# it will run using only the oldest and latest python version we support.
# When running on main all combinations of operating system
# and python versions are run.
###
name: test
on:
push:
branches:
- main
paths:
- nilearn/**/*
- tox.ini
- pyproject.toml
- .github/workflows/test_with_tox.yml
pull_request:
branches:
- '*'
paths:
- nilearn/**/*
- tox.ini
- pyproject.toml
- .github/workflows/test_with_tox.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Force to use color
env:
FORCE_COLOR: true
jobs:
check_skip_flags:
uses: ./.github/workflows/check_skip_flags.yml
with:
skip_type: test
define-matrix:
runs-on: ubuntu-latest
needs: check_skip_flags
outputs:
py: ${{ steps.py.outputs.py }}
steps:
- name: Define python version to test
# only run latest and oldest python versions on PR
id: py
run: |
versions='py=["3.14", "3.13", "3.12", "3.11", "3.10"]'
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
versions='py=["3.14", "3.10"]'
fi
echo "Will run on the following python: ${versions}"
echo ${versions} >> "$GITHUB_OUTPUT"
test_and_coverage:
needs: [check_skip_flags, define-matrix]
if: github.repository == 'nilearn/nilearn'
name: 'Test with ${{ matrix.py }} on ${{ matrix.os }}: ${{ matrix.description }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
description: [latest dependencies]
py: ${{ fromJSON(needs.define-matrix.outputs.py) }}
os: [windows-latest, macos-latest, ubuntu-latest]
env: [plotting]
include:
# Using macos on the following as tests run faster on macos.
# As 'no plotting' run fewer tests, this allows to fail event faster if using macos.
- description: oldest dependencies - no plotting
py: '3.10'
os: macos-latest
env: min
- description: oldest dependencies - with plotting
py: '3.10'
os: macos-latest
env: plot_min
# plotly images saved on different OS can generate slightly
# different baseline images. As baseline images are generated
# on a linux machine, ubuntu-latest is used
- description: check generated figures
py: '3.10'
os: ubuntu-latest
env: pytest_mpl
steps:
- uses: actions/checkout@v6
with:
# If pull request, checkout HEAD commit with all commit history
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.py }}
allow-prereleases: true
- name: Install tox
run: uv tool install tox --with=tox-uv --with=tox-gh-actions
- name: Show tox config
run: tox c
- name: Merge with upstream
# We do this so that when on a PR,
# we only get the files involved in a PR
# to avoid running more tests than needed.
shell: bash -el {0}
run: ./build_tools/github/merge_upstream.sh
- name: Run test suite
shell: bash -el {0}
run: |
python build_tools/github/restrict_tests_to_run.py
tests_to_run=$(cat tests_to_run.txt)
tox run --list-dependencies -e ${{ matrix.env }} -- ${tests_to_run}
tox run -e plot_test_timing
- name: Upload test report
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.description }}_report
path: |
report.html
report_slow.html
report_doc.html
- name: Upload test timings
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.description }}_pytest_output
path: results/pytest_output
- name: Upload html coverage
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.description }}_htmlcov
path: htmlcov
- name: Upload coverage to CodeCov
if: success()
uses: codecov/codecov-action@v5
with:
flags: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.env }}
token: ${{ secrets.CODECOV_TOKEN }}
test_pre_release:
# Test with eventual pre-release version of the dependencies
# Run separately to avoid blocking other jobs in case of failure
# (as pre-release dependencies stability is not under our control).
needs: [check_skip_flags]
if: github.repository == 'nilearn/nilearn'
name: 'Test with ${{ matrix.py }} on ${{ matrix.os }}: ${{ matrix.description }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
description: [pre-release dependencies]
py: ['3.14']
os: [ubuntu-latest]
env: [pre]
steps:
- uses: actions/checkout@v6
with:
# If pull request, checkout HEAD commit with all commit history
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.py }}
allow-prereleases: true
- name: Install tox
run: uv tool install tox --with=tox-uv --with=tox-gh-actions
- name: Show tox config
run: tox c
- name: Merge with upstream
# We do this so that when on a PR,
# we only get the files involved in a PR
# to avoid running more tests than needed.
shell: bash -el {0}
run: ./build_tools/github/merge_upstream.sh
- name: Run test suite
shell: bash -el {0}
run: |
python build_tools/github/restrict_tests_to_run.py
tests_to_run=$(cat tests_to_run.txt)
tox run --list-dependencies -e ${{ matrix.env }} -- ${tests_to_run}
tox run -e plot_test_timing
- name: Upload test report
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.description }}_report
path: |
report.html
report_slow.html
report_doc.html
- name: Upload test timings
if: success() || failure()
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.os }}_${{ matrix.py }}_${{ matrix.description }}_pytest_output
path: results/pytest_output
test_flaky:
# Some tests are marked as flaky in order to reduce the noise in CI results.
# These tests are run separately here to monitor their status.
# We also run them on a single processor to reduce the chance of intermittent failures.
needs: [check_skip_flags, define-matrix]
if: github.repository == 'nilearn/nilearn'
name: 'Test with ${{ matrix.py }} on ${{ matrix.os }}: ${{ matrix.description }}'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
description: [flaky tests]
py: ${{ fromJSON(needs.define-matrix.outputs.py) }}
os: [ubuntu-latest, macos-latest, windows-latest]
env: [flaky]
steps:
- uses: actions/checkout@v6
with:
# If pull request, checkout HEAD commit with all commit history
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v7
- name: Setup python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.py }}
allow-prereleases: true
- name: Install tox
run: uv tool install tox --with=tox-uv --with=tox-gh-actions
- name: Show tox config
run: tox c
- name: Run test suite
shell: bash -el {0}
run: |
tox run --list-dependencies -e ${{ matrix.env }} -- nilearn