Repository navigation
277 lines (277 loc) · 13.9 KB
/
Copy pathci.yml
File metadata and controls
277 lines (277 loc) · 13.9 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
# A GitHub Actions workflow file to run on pull request and on main.
# A pull request runs the code-quality checks and the tests on Ubuntu with stable Python. The full
# matrix (Windows, macOS, newer Pythons) runs on main, for manual runs, for pull requests that
# change the build, the dependencies, the C++ extensions or this workflow, and for pull requests
# with the label "full ci" (adding the label starts a run, see ci_full.yml). A pull request that
# only changes the documentation, the examples or Markdown files runs the code-quality checks only.
# Require the job "CI result" in branch protection: it fails if any job failed.
name: CI Tests
on:
pull_request:
push:
branches: [main]
workflow_dispatch:
workflow_call:
# a new push cancels a pull request's run, but every commit on main gets its own full run
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# ----------------------------------------------------------------------------------------------
# Decide which jobs a pull request needs
# ----------------------------------------------------------------------------------------------
changes:
name: Detect changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
code: ${{ steps.filter.outputs.code }}
full: ${{ steps.filter.outputs.full }}
steps:
# a pull request checks out its merge commit: HEAD^1 is the base branch
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Check the changed files
id: filter
env:
EVENT_NAME: ${{ github.event_name }}
FULL_CI_LABEL: ${{ contains(github.event.pull_request.labels.*.name, 'full ci') || github.event.label.name == 'full ci' }}
# changes that cannot affect the tests
DOCS_ONLY: '^(docs/|examples/|\.claude/|\.github/ISSUE_TEMPLATE/|\.github/workflows/docs\.yml$|\.readthedocs\.yaml$|CITATION\.cff$|LICENSE$)|\.md$'
# changes that can break other platforms or Python versions
NEEDS_FULL: '^(setup\.py|pyproject\.toml|uv\.lock|MANIFEST\.in|build_tools/|\.github/workflows/ci)|/cext/'
run: |
if [ "$EVENT_NAME" != "pull_request" ] || [ "$FULL_CI_LABEL" = "true" ]; then
echo "code=true" >> "$GITHUB_OUTPUT"
echo "full=true" >> "$GITHUB_OUTPUT"
exit 0
fi
# without renames: a file moved out of src/ also lists its old path
files=$(git diff --name-only --no-renames HEAD^1 HEAD)
echo "Changed files:"
echo "$files"
if grep -qvE "$DOCS_ONLY" <<< "$files"; then code=true; else code=false; fi
if grep -qE "$NEEDS_FULL" <<< "$files"; then full=true; else full=false; fi
echo "code=$code" >> "$GITHUB_OUTPUT"
echo "full=$full" >> "$GITHUB_OUTPUT"
echo "Run the tests: $code, run the full matrix: $full"
# ----------------------------------------------------------------------------------------------
# Code Quality Checks and Linting
# ----------------------------------------------------------------------------------------------
check_code_quality:
name: Code Quality Checks
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
- name: Install pre-commit
run: |
uv sync --group lint --all-extras
uv run pre-commit install
- name: Run code-quality checks
run: uv run pre-commit run --all-files --show-diff-on-failure
# ----------------------------------------------------------------------------------------------
# Install and Import Check `shapiq`
# ----------------------------------------------------------------------------------------------
# a non-editable install on Ubuntu: the test matrix installs shapiq on the other platforms
install_and_import_shapiq:
name: Install and import check shapiq
needs:
- changes
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
- name: Create uv virtual environment
run: uv venv
- name: Install shapiq package
run: uv run --no-sync uv pip install .
- name: Test import
run: uv run --no-sync python -c "import shapiq; print('shapiq imported successfully')"
# ----------------------------------------------------------------------------------------------
# Install, Import, and Test `shapiq_games` with the `games` extra only
# ----------------------------------------------------------------------------------------------
install_and_import_shapiq_games:
name: Install and import check shapiq-games
runs-on: ubuntu-latest
timeout-minutes: 20
needs:
- install_and_import_shapiq
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
# only the games extra: proves it holds everything the games import
- name: Install shapiq package with the games extra
run: uv sync --no-dev --extra games --group test
- name: Test import of shapiq_games
run: uv run --no-sync python -c "import shapiq_games; print('shapiq_games imported successfully')"
# the tests skip a game whose dependency is missing: check that the extra installs them all
- name: Test import of the games' optional dependencies
run: uv run --no-sync python -c "import google.protobuf, sentencepiece, skimage, tabpfn, torch, torch_geometric, torchvision, transformers, xgboost"
# serial on purpose: under pytest-xdist the multi-threaded model libraries
# oversubscribe the runner's cores (seconds serially, minutes in parallel)
- name: Run shapiq_games unit tests
run: uv run --no-sync pytest "tests/shapiq_games"
# ----------------------------------------------------------------------------------------------
# Install, Import, and Test `shapiq_benchmark`
# ----------------------------------------------------------------------------------------------
test_shapiq_benchmark:
name: Install and test shapiq-benchmark
runs-on: ubuntu-latest
timeout-minutes: 20
needs:
- install_and_import_shapiq
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
- name: Install shapiq package and dependencies for shapiq-benchmark
run: uv sync --all-extras
- name: Test import of shapiq_benchmark
run: uv run --no-sync python -c "import shapiq_benchmark; print('shapiq_benchmark imported successfully')"
- name: Run shapiq_benchmark unit tests (serially, see above)
run: uv run --no-sync pytest "tests/shapiq_benchmark"
# ----------------------------------------------------------------------------------------------
# Heavy Tests of `shapiq_games` and `shapiq_benchmark` (manual runs only)
# ----------------------------------------------------------------------------------------------
test_shapiq_benchmark_heavy:
name: Heavy tests of shapiq-benchmark (downloads)
# pretrained models and OpenML/UCI/Imagenette downloads: run from the Actions tab
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 60
needs:
- install_and_import_shapiq
env:
SHAPIQ_RUN_HEAVY_TESTS: "1"
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
- name: Install shapiq package and dependencies for shapiq-benchmark
run: uv sync --all-extras
- name: Run the heavy tests
run: uv run --no-sync pytest "tests/shapiq_benchmark/test_heavy.py" -rs
# ----------------------------------------------------------------------------------------------
# Unit Tests and Coverage for shapiq (Stable Python and Matrix)
# ----------------------------------------------------------------------------------------------
test_shapiq_stable:
name: Run Unit Tests and Coverage (Stable Python)
runs-on: ubuntu-latest
timeout-minutes: 30
needs:
- install_and_import_shapiq
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
enable-cache: true
# California housing of the core fixtures: fetched once, not on every run
- name: Cache scikit-learn datasets
uses: actions/cache@v6
with:
path: ~/scikit_learn_data
key: scikit-learn-data-${{ runner.os }}
- name: Install test dependencies
run: uv sync --all-extras
- name: Run unit tests and measure coverage
run: uv run pytest "tests/shapiq" --cov=shapiq --cov-report=xml -n logical
- name: Upload coverage to codecov
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
test_shapiq_matrix:
name: Run Unit Tests (Matrix)
needs:
- changes
- test_shapiq_stable
if: needs.changes.outputs.full == 'true'
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: "3.15" # Test latest Python on Ubuntu
- os: ubuntu-latest
python-version: "3.14" # Test latest Python with all optional dependencies (torch, catboost, ...)
- os: windows-latest
python-version: "3.12" # Test stable Python on Windows
- os: macos-latest
python-version: "3.12" # Test stable Python on macOS
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- name: Set up Python and uv
uses: astral-sh/setup-uv@v7
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
- if: matrix.os == 'macos-latest'
name: Install libomp on macOS
run: brew install libomp
# California housing of the core fixtures: fetched once, not on every run
- name: Cache scikit-learn datasets
uses: actions/cache@v6
with:
path: ~/scikit_learn_data
key: scikit-learn-data-${{ runner.os }}
- name: Install test dependencies
run: uv sync --all-extras
# some Windows runners crash the tests with an illegal instruction (0xc000001d) in
# TabPFN: log the CPU and the instruction sets numpy and torch detect on each runner
- if: matrix.os == 'windows-latest'
name: Show the CPU and its instruction sets
continue-on-error: true
run: |
Get-CimInstance Win32_Processor | Select-Object Name, Manufacturer, NumberOfCores
uv run --no-sync python -c "import numpy; numpy.show_runtime()"
uv run --no-sync python -c "import torch; print('torch', torch.__version__, 'CPU capability:', torch.backends.cpu.get_cpu_capability())"
- name: Run unit tests
run: uv run pytest "tests/shapiq"
# ----------------------------------------------------------------------------------------------
# One Result for Branch Protection (a skipped job counts as passed)
# ----------------------------------------------------------------------------------------------
ci_result:
name: CI result
if: always()
needs:
- changes
- check_code_quality
- install_and_import_shapiq
- install_and_import_shapiq_games
- test_shapiq_benchmark
- test_shapiq_benchmark_heavy
- test_shapiq_stable
- test_shapiq_matrix
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Fail if a job failed or was cancelled
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1