-
Notifications
You must be signed in to change notification settings - Fork 95
279 lines (243 loc) · 8.86 KB
/
ci.yml
File metadata and controls
279 lines (243 loc) · 8.86 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
# 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
# ===========================================================================
# TEMPORARILY DISABLED - Re-enable when dependency isolation testing is needed
# 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
# - 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 4: Coverage Report (only on Ubuntu with full dependencies)
# ===========================================================================
coverage:
name: Coverage Report
runs-on: ubuntu-latest
needs: [test-matrix] # Also depends on: test-no-sklearn, test-no-scipy (currently disabled)
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: Coverage Summary Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: coverage.xml
badge: true