-
Notifications
You must be signed in to change notification settings - Fork 50
332 lines (270 loc) · 10.4 KB
/
ci.yml
File metadata and controls
332 lines (270 loc) · 10.4 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
name: CI tests
on:
pull_request:
push:
branches:
- main
- 'push-action/**'
env:
PYTEST_ADDOPTS: "--color=yes"
LINTING_PY_VERSION: "3.10" # The version of Python to use for linting (typically the minimum supported)
# Cancel running workflows when additional changes are pushed
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Set up Python ${{ env.LINTING_PY_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.LINTING_PY_VERSION }}
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --locked --extra server --extra dev --extra elastic
- name: Run pre-commit
run: uv run pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
openapi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --locked --extra server --extra dev
- name: Pass generated OpenAPI schemas through validator.swagger.io
run: |
uv run invoke swagger-validator openapi/openapi.json
uv run invoke swagger-validator openapi/index_openapi.json
- name: Check OpenAPI Schemas have not changed
run: uv run invoke check-openapi-diff
docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- name: Build the container image
run: docker build -f Dockerfile --build-arg CONFIG_FILE=.docker/docker_config.json --tag optimade .
- name: Start Docker image - server
run: |
docker run --rm -d -p 3213:5000 --name optimade optimade
.github/utils/wait_for_it.sh localhost:3213 -t 120
sleep 15
- name: Test server, including OPTIONAL base URLs
# Pin validator action until merge of Materials-Consortia/optimade-validator-action#175
uses: Materials-Consortia/optimade-validator-action@dc4a7b6a83da42e5341a1a401e36d83375550fb7
with:
port: 3213
path: /
all versioned paths: yes
validator version: ${{ github.sha }} # This ensures the head of a PR or latest push commit is tested
- name: Start Docker image - index server
run: |
docker run --rm -d -p 3214:5000 --name optimade-index -e MAIN=main_index optimade
.github/utils/wait_for_it.sh localhost:3214 -t 120
sleep 15
- name: Test index server, including OPTIONAL base URLs
# Pin validator action until merge of Materials-Consortia/optimade-validator-action#175
uses: Materials-Consortia/optimade-validator-action@dc4a7b6a83da42e5341a1a401e36d83375550fb7
with:
port: 3214
path: /
all versioned paths: yes
index: yes
validator version: ${{ github.sha }} # This ensures the head of a PR or latest push commit is tested
pytest:
runs-on: ubuntu-latest
env:
OPTIMADE_CONFIG_FILE: ${{ github.workspace }}/optimade_config.json
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
services:
mongo:
image: mongo:7
ports:
- 27017:27017
postgres:
image: postgres:10
env:
POSTGRES_DB: test_aiida
POSTGRES_PASSWORD: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
elasticsearch:
image: elasticsearch:7.17.7
ports:
- 9200:9200
- 9300:9300
env:
discovery.type: single-node
xpack.security.enabled: 'false'
steps:
- uses: actions/checkout@v5
with:
submodules: true
fetch-depth: 2
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --locked --extra http-client --extra dev
- name: Run non-server tests
run: uv run pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml tests/ --ignore tests/server
- name: Install latest server dependencies
run: uv sync --locked --extra http-client --extra dev --extra server --extra elastic
- name: Run server tests (using `mongomock`)
run: uv run pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
- name: Run server tests with no API validation (using `mongomock`)
run:
uv run pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
OPTIMADE_VALIDATE_API_RESPONSE: false
- name: Run server tests (using a real MongoDB)
run: uv run pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongodb'
- name: Run server tests (using Elasticsearch)
run: |
.github/utils/wait_for_it.sh localhost:9200 -t 120
.github/utils/wait_for_it.sh localhost:9300 -t 120
uv run pytest -rs -vvv --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'elastic'
- name: Install adapter conversion dependencies
run: uv sync --locked --extra http-client --extra dev --extra server --extra client --extra elastic
- name: Setup environment for AiiDA
env:
AIIDA_TEST_BACKEND: core.psql_dos
run: |
.github/aiida/setup_aiida.sh
- name: Run previously skipped tests for adapter conversion
run: uv run pytest -rs -vvv --cov=./optimade/ --cov-report=xml --cov-append tests/adapters/
- name: Run tests for validator only to assess coverage (mongomock)
if: matrix.python-version == '3.11'
run: uv run pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
- name: Run tests for validator only to assess coverage (Elasticsearch)
if: matrix.python-version == '3.11'
run: uv run pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'elastic'
OPTIMADE_INSERT_TEST_DATA: false # Must be specified as previous steps will have already inserted the test data
OPTIMADE_INSERT_FROM_JSONL: '' # Must be specified as previous steps will have already inserted the test data
- name: Run tests for validator only to assess coverage (MongoDB)
if: matrix.python-version == '3.11'
run: uv run pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'mongodb'
OPTIMADE_INSERT_TEST_DATA: false # Must be specified as previous steps will have already inserted the test data
OPTIMADE_INSERT_FROM_JSONL: '' # Must be specified as previous steps will have already inserted the test data
- name: Run the OPTIMADE Client CLI
if: matrix.python-version == '3.11'
run: |
uv run coverage run --append --source optimade optimade/client/cli.py \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--output-file test_get_async.json \
https://optimade.fly.dev
test test_get_async.json
uv run coverage run --append --source optimade optimade/client/cli.py \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--count \
--output-file test_count.json \
https://optimade.fly.dev
test test_count.json
uv run coverage run --append --source optimade optimade/client/cli.py \
--no-async \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--count \
--output-file test_count_no_async.json \
https://optimade.fly.dev
test test_count_no_async.json
diff test_count_no_async.json test_count.json
uv run coverage xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11' && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: project
file: ./coverage.xml
flags: project
- name: Upload validator coverage to Codecov
if: matrix.python-version == '3.11' && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: validator
file: ./validator_cov.xml
flags: validator
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: true
- uses: actions/setup-python@v6
with:
python-version: ${{ env.LINTING_PY_VERSION }}
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --locked --all-extras
# NOTE: While we're now using `mike`, this is still useful
# to test the integrity of the documentation build.
- name: Build
run: |
uv run invoke create-api-reference-docs --pre-clean
uv run mkdocs build --strict
test_build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Python ${{ env.LINTING_PY_VERSION }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.LINTING_PY_VERSION }}
- name: Setup uv
uses: astral-sh/setup-uv@v6
with:
version: "latest"
- name: Install dependencies
run: |
uv sync --locked --all-extras
- name: Build source distribution
run: uv run python -m build