-
Notifications
You must be signed in to change notification settings - Fork 58
276 lines (255 loc) · 8.1 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
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
# (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:
- uses: actions/checkout@v3
- run: pip install black flake8 isort
- run: black --version
- run: isort --version
- run: flake8 --version
- run: isort --check .
- run: black --check .
- run: flake8 .
test_build_doc:
name: Test building documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install packages needed to build the documentation
run: |
pip install sphinx
pip install -r docs/requirements.txt
sudo apt-get install pandoc
pip freeze
- name: Documentation
run: |
make clean
make html
# make linkcheck (don't run yet)
working-directory: docs
download-test-data:
name: Download test data
runs-on: ubuntu-latest
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'):
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'):
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'):
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:
# if: (github.event_name == 'release' && github.event.action == 'created') || github.ref == 'refs/heads/main'
# if: github.event_name == 'release' && github.event.action == 'created'
# if: github.ref == 'refs/heads/main'
needs: [download-test-data]
strategy:
matrix:
platform: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.8", "3.9", "3.10"]
# platform: ["ubuntu-latest"]
# python-version: ["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'):
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: 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
# - name: Install climetlab full
# run: |
# pip install .[interactive,tensorflow,zarr]
# pip freeze
# - name: Tests with dependencies
# run: |
# pytest --durations=10 -vv -E short
check-version-tag:
if: github.event_name == 'release' && github.event.action == 'created'
name: Check versions and tags
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Check that tag version matches package version
run: |
tag=${GITHUB_REF#refs/tags/}
version=$(python setup.py --version)
echo 'tag='$tag
echo "version file="$version
test "$tag" == "$version"
deploy:
name: Upload to Pypi and release
needs: [check-version-tag, short-tests, quality, test_build_doc, tests-with-external-download, tests-notebooks]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build pip package
run: python setup.py sdist
- name: Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --verbose dist/*