-
Notifications
You must be signed in to change notification settings - Fork 58
239 lines (212 loc) · 6.58 KB
/
test-and-release.yml
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
# (C) Copyright 2021 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
name: Tests and release
on:
workflow_dispatch: {}
# schedule:
# # Every day at 3:07am
# # on the "default" branch set in github (currently is develop)
# - cron: '07 3 * * *'
release:
types: [created]
push:
branches:
- "*"
repository_dispatch:
types:
- cdsapi-updated
- magics-python-updated
- ecmwf-api-client-updated
jobs:
quality:
name: Code QA
runs-on: ubuntu-latest
steps:
- run: sudo apt-get install -y pandoc # Needed by sphinx for notebooks
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: pre-commit/action@v3.0.1
download-test-data:
name: Download test data
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Tokens
shell: python
env:
ECMWFAPIRC: ${{ secrets.ECMWFAPIRC }}
CDSAPIRC: ${{ secrets.CDSAPIRC }}
run: |
import os
# for n in ('ECMWFAPIRC', 'CDSAPIRC'):
n = 'ECMWFAPIRC'
m = os.path.expanduser("~/." + n.lower())
if os.environ[n]:
with open(m, "w") as f:
print(os.environ[n], file=f)
- run: mkdir test-data
- run: echo "dataA" > test-data/dataA.txt
- run: echo "dataB" > test-data/dataB.txt
- run: cat test-data/dataA.txt
- name: Tar files
run: tar -cvf test-data.tar test-data
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: test-data
path: test-data.tar
tests-with-external-download:
if: github.event_name == 'release' && github.event.action == 'created'
strategy:
fail-fast: true
matrix:
platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.10"]
name: Long tests with external downloads Python ${{ matrix.python-version }} ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Tokens
shell: python
env:
ECMWFAPIRC: ${{ secrets.ECMWFAPIRC }}
CDSAPIRC: ${{ secrets.CDSAPIRC }}
run: |
import os
# for n in ('ECMWFAPIRC', 'CDSAPIRC'):
n = 'ECMWFAPIRC'
m = os.path.expanduser("~/." + n.lower())
if os.environ[n]:
with open(m, "w") as f:
print(os.environ[n], file=f)
- name: Install climetlab
run: pip install -e . # run: pip install .[interactive,tensorflow,zarr]
- run: climetlab versions
- name: Install test tools
run: |
pip install pytest
pip freeze
- name: Long Tests
run: pytest --durations=0 -E release -k 'not test_notebooks'
tests-notebooks:
if: github.event_name == 'release' && github.event.action == 'created'
strategy:
matrix:
platform: ["ubuntu-latest"]
python-version: ["3.9"]
name: Tests notebooks Python ${{ matrix.python-version }} ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Tokens
shell: python
env:
ECMWFAPIRC: ${{ secrets.ECMWFAPIRC }}
CDSAPIRC: ${{ secrets.CDSAPIRC }}
run: |
import os
# for n in ('ECMWFAPIRC', 'CDSAPIRC'):
n = 'ECMWFAPIRC'
m = os.path.expanduser("~/." + n.lower())
if os.environ[n]:
with open(m, "w") as f:
print(os.environ[n], file=f)
- name: Install climetlab
run: pip install -e . # run: pip install .[interactive,tensorflow,zarr]
- run: climetlab versions
- name: Install test tools
run: |
pip install pytest
pip freeze
- name: Tests notebooks
run: pytest tests/documentation/test_notebooks.py
short-tests:
needs: [download-test-data]
strategy:
matrix:
platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.9", "3.10"]
name: Short tests Python ${{ matrix.python-version }} ${{ matrix.platform }}
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Download test-data
uses: actions/download-artifact@v3
with:
name: test-data
- run: tar xvf test-data.tar
- run: cat test-data/dataA.txt
- name: Tokens
# (this should be removed when tests are refactored)
shell: python
env:
ECMWFAPIRC: ${{ secrets.ECMWFAPIRC }}
CDSAPIRC: ${{ secrets.CDSAPIRC }}
run: |
import os
# for n in ('ECMWFAPIRC', 'CDSAPIRC'):
n = 'ECMWFAPIRC'
m = os.path.expanduser("~/." + n.lower())
if os.environ[n]:
with open(m, "w") as f:
print(os.environ[n], file=f)
- run: pip install --upgrade pip
- name: Install climetlab
run: pip install -e .
- run: climetlab versions
- name: Install test tools
run: |
pip install pytest
pip freeze
- name: Check imports
run: |
pytest tests/test_imports.py
env:
SKIP_TEST_IMPORTS: 0
- name: Tests
run: |
# -E flag is defined in conftest.py
# notebooks need more dependencies
# pytest --durations=0 -E release -k 'not test_notebooks'
pytest --durations=10 -vv -E short
deploy:
name: Upload to Pypi and release
needs: [short-tests, quality, tests-with-external-download, tests-notebooks]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m build
twine upload dist/*