-
Notifications
You must be signed in to change notification settings - Fork 94
390 lines (338 loc) · 12.5 KB
/
ci.yml
File metadata and controls
390 lines (338 loc) · 12.5 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# Gradient-Free-Optimizers CI Pipeline
#
# Pipeline Structure:
# 1. Code Quality (gate) - Must pass before anything else runs
# 2. API Smoke Tests (gate) - Fast API freeze tests, must pass before main tests
# 3. Main Tests (parallel):
# - OS Matrix Tests (Ubuntu, macOS, Windows × Python versions)
# - Dependency Isolation Tests (no-sklearn, no-scipy)
# 4. Coverage - Runs after all tests pass
name: CI
on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ===========================================================================
# STAGE 1: Code Quality (gate)
# ===========================================================================
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pre-commit
run: python -m pip install --no-cache-dir pre-commit
- name: Get changed files
id: changed-files
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ')
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD | tr '\n' ' ')
fi
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
- name: Print changed files
run: |
echo "Changed files:" && echo "$CHANGED_FILES" | tr ' ' '\n'
- name: Run pre-commit on changed files
run: |
if [ -n "$CHANGED_FILES" ]; then
pre-commit run --color always --files $CHANGED_FILES --show-diff-on-failure
else
echo "No changed files to check."
fi
# ===========================================================================
# STAGE 2: API Smoke Tests (gate)
# ===========================================================================
api-smoke-tests:
name: API Smoke Tests
runs-on: ubuntu-latest
needs: code-quality
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
make install
make install-test-requirements
- name: Run API smoke tests
run: |
python -m pytest tests/test_api/ -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 3a: Main Tests - OS Matrix
# ===========================================================================
test-matrix:
name: Tests (${{ matrix.os }}, py${{ matrix.python-version }}, np${{ matrix.numpy-version }})
runs-on: ${{ matrix.os }}
needs: api-smoke-tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
numpy-version: ["1", "2"]
exclude:
# numpy 1.x not compatible with Python 3.13+
- python-version: "3.13"
numpy-version: "1"
- python-version: "3.14"
numpy-version: "1"
# pandas 1.x has no pre-built wheel for Python 3.12, source build
# broken since setuptools 81 removed pkg_resources (Feb 2026)
- python-version: "3.12"
numpy-version: "1"
# Reduce macOS/Windows matrix to save CI minutes
- os: macos-latest
numpy-version: "1"
- os: windows-latest
numpy-version: "1"
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
make install
make install-test-requirements
- name: Install specific numpy/pandas versions
shell: bash
run: |
if [ "${{ matrix.numpy-version }}" = "1" ]; then
python -m pip install "numpy>=1.18.1,<2.0.0" "pandas>=1.0,<2.0"
else
python -m pip install "numpy>=2.0,<3.0" "pandas>=2.0,<3.0"
fi
- name: Run main tests
run: |
python -m pytest tests/test_main/ -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 3b: Dependency Isolation Tests - No sklearn
# ===========================================================================
# TEMPORARILY DISABLED - Re-enable when dependency isolation testing is needed
# test-no-sklearn:
# name: Tests (no sklearn)
# runs-on: ubuntu-latest
# needs: api-smoke-tests
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
# - name: Set up Python 3.11
# uses: actions/setup-python@v5
# with:
# python-version: "3.11"
# - name: Install minimal dependencies (no sklearn)
# run: |
# python -m pip install --upgrade pip
# python -m pip install build numpy pandas pytest
# python -m pip install scipy
# - name: Build and install package
# run: |
# python -m pip install build
# python -m build
# pip install dist/*.whl
# - name: Verify sklearn is NOT installed
# run: |
# python -c "
# import sys
# try:
# import sklearn
# print('ERROR: sklearn is installed but should not be!')
# sys.exit(1)
# except ImportError:
# print('OK: sklearn is not installed')
# "
# - name: Run dependency isolation tests
# run: |
# python -m pytest tests/test_dependencies/test_no_sklearn.py -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 3b: Dependency Isolation Tests - No scipy
# ===========================================================================
test-no-scipy:
name: Tests (no scipy)
runs-on: ubuntu-latest
needs: api-smoke-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install minimal dependencies (no scipy)
run: |
python -m pip install --upgrade pip
python -m pip install build numpy pandas pytest tqdm
- name: Build and install package
run: |
python -m pip install build
python -m build
pip install dist/*.whl
- name: Verify scipy is NOT installed
run: |
python -c "
import sys
try:
import scipy
print('ERROR: scipy is installed but should not be!')
sys.exit(1)
except ImportError:
print('OK: scipy is not installed')
"
- name: Run dependency isolation tests
run: |
python -m pytest tests/test_dependencies/test_no_scipy.py -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 3c: Dependency Isolation Tests - No numpy (pure Python)
# ===========================================================================
test-no-numpy:
name: Tests (no numpy, pure Python)
runs-on: ubuntu-latest
needs: api-smoke-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install minimal dependencies (no numpy, no scipy)
run: |
python -m pip install --upgrade pip
python -m pip install build pytest tqdm
- name: Build and install package
run: |
python -m pip install build
python -m build
pip install dist/*.whl
- name: Uninstall numpy and pandas (test pure Python mode)
run: |
pip uninstall numpy pandas -y
- name: Verify numpy and pandas are NOT installed
run: |
python -c "
import sys
errors = []
for mod in ('numpy', 'pandas'):
try:
__import__(mod)
errors.append(f'{mod} is installed but should not be')
except ImportError:
print(f'OK: {mod} is not installed')
if errors:
for e in errors:
print(f'ERROR: {e}')
sys.exit(1)
"
- name: Verify array backend uses pure Python
run: |
python -c "
from gradient_free_optimizers._array_backend import _backend_name, HAS_NUMPY
assert not HAS_NUMPY, 'HAS_NUMPY should be False'
assert _backend_name == 'pure', f'Expected pure backend, got {_backend_name}'
print('OK: using pure Python array backend')
"
- name: Run dependency isolation tests
run: |
python -m pytest tests/test_dependencies/test_no_numpy.py -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 3d: C Extension Tests (no numpy, with compiled C backend)
# ===========================================================================
test-c-extension:
name: Tests (C extension, no numpy)
runs-on: ubuntu-latest
needs: api-smoke-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build pandas pytest tqdm setuptools
- name: Build and install package (with C extension)
run: |
python -m pip install build
python -m build
pip install dist/*.whl
- name: Uninstall numpy (keep C extension)
run: |
pip uninstall numpy -y || true
- name: Verify C extension is active
run: |
python -c "
from gradient_free_optimizers._array_backend import _backend_name, HAS_NUMPY, HAS_C_EXTENSION
assert not HAS_NUMPY, 'numpy should not be installed'
assert HAS_C_EXTENSION, 'C extension should be available'
assert _backend_name == 'c_extension', f'Expected c_extension backend, got {_backend_name}'
print('OK: using C extension array backend')
"
- name: Run C extension unit tests
run: |
python -m pytest tests/test_internal/test_array_backend/test_c_extension.py -v --tb=short -p no:warnings
- name: Run dependency isolation tests
run: |
python -m pytest tests/test_dependencies/test_no_numpy.py -v --tb=short -p no:warnings
# ===========================================================================
# STAGE 4: Coverage Report (only on Ubuntu with full dependencies)
# ===========================================================================
coverage:
name: Coverage Report
runs-on: ubuntu-latest
needs: [test-matrix, test-no-scipy, test-no-numpy, test-c-extension]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
make install
make install-test-requirements
- name: Run tests with coverage
run: |
python -m pytest tests/test_main/ tests/test_api/ \
--cov=gradient_free_optimizers \
--cov-report=term-missing \
--cov-report=xml \
-p no:warnings
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false
verbose: true