-
Notifications
You must be signed in to change notification settings - Fork 16
293 lines (256 loc) · 7.88 KB
/
ci.yaml
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
name: CI
on:
push:
paths-ignore:
- "docs/**"
- "*.md"
- "*.rst"
pull_request:
paths-ignore:
- "docs/**"
- "*.md"
- "*.rst"
jobs:
pre-commit:
name: Run pre-commit
# This is the VM in which github run
# We can use a custom container that will
# be run in this VM
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Cache python environment
uses: actions/cache@v3
# https://tobiasmcnulty.com/posts/caching-pre-commit/
# This restore and/or save in the same action
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-3.11-venv-${{ hashFiles('pyproject.toml') }}
- name: Install dependencies
# Activate or create env from cache and install package
# https://stackoverflow.com/questions/74668349/how-to-activate-a-virtualenv-in-a-github-action
# Note that you have to activate the virtualenv in every step
# because GitHub actions doesn't preserve the environment
run: |
pip install -U '.[dev]'
- name: Cache pre-commits
id: cache-pre-commits
# https://tobiasmcnulty.com/posts/caching-pre-commit/
# This restore and/or save in the same action
uses: actions/cache@v3
with:
path: ~/.cache/pre-commit/
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commits
# https://github.com/actions/cache#restoring-and-saving-cache-using-a-single-action
if: steps.cache-pre-commits.outputs.cache-hit != 'true'
run: pre-commit install
- name: Compute pre-commit cache key
run: |
pre-commit run --all-files
multi-os-tests:
name: Test for Python ${{ matrix.python }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
# Only test all OS on default branch
if: ( github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) || startsWith(github.ref, 'refs/tags')
needs: pre-commit
strategy:
fail-fast: false
# https://github.com/actions/cache/blob/main/examples.md#multiple-oss-in-a-workflow-with-a-matrix
matrix:
include:
- {
python: "3.10",
os: "windows-latest",
session: "tests",
cache-path: ~\AppData\Local\pip\Cache,
}
- {
python: "3.10",
os: "macos-latest",
session: "tests",
cache-path: ~/Library/Caches/pip,
}
- {
python: "3.9",
os: "ubuntu-latest",
session: "tests",
cache-path: ~/.cache/pip,
}
- {
python: "3.10",
os: "ubuntu-latest",
session: "tests",
cache-path: ~/.cache/pip,
}
env:
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Cache python environment
uses: actions/cache@v3
with:
path: ${{ matrix.cache-path }}
key: ${{ runner.os }}-python-${{ matrix.python }}-pip-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
# Activate or create env from cache and install package
run: |
pip install -U '.[dev]'
- name: Run tests
run: |
python -m pytest
linux-tests:
name: Tests for Python 3.11 on ubuntu-latest
runs-on: ubuntu-latest
needs: pre-commit
# If not default branch
# It allows us to not use too much walltime of github
env:
FORCE_COLOR: "1"
PRE_COMMIT_COLOR: "always"
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
lfs: true
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Cache python environment
uses: actions/cache@v3
# https://tobiasmcnulty.com/posts/caching-pre-commit/
# This restore and/or save in the same action
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-3.11-pip-${{ hashFiles('pyproject.toml') }}
- name: Install dependencies
# Activate or create env from cache and install package
run: |
pip install -U '.[dev]'
- name: Run tests
run: |
python -m pytest
- name: Upload artifacts generated by tests
uses: actions/upload-artifact@v3
with:
name: tests-artifacts
path: tests/data/outputs/
- name: Upload coverage data
uses: "actions/upload-artifact@v3"
with:
name: coverage-data
path: "./coverage/"
coverage:
name: Coverage deployment
runs-on: ubuntu-latest
needs: linux-tests
# Only deploy coverage on default branch
if: ( github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ) || startsWith(github.ref, 'refs/tags')
steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
lfs: true
- name: Download coverage data
uses: actions/download-artifact@v3
with:
name: coverage-data
path: ./coverage/
- name: Display structure of downloaded files
run: ls -lh --color=auto -R
- name: Upload coverage report
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage/
fail_ci_if_error: true
files: coverage.xml
verbose: true
test-pypi:
name: Deploy Package to Test PyPI
runs-on: ubuntu-latest
needs: [pre-commit]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
--upgrade
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
pypi:
name: Deploy Package to PyPI
# Deploy only tagged commit and if tests have succeeded
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
needs: [linux-tests, multi-os-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
lfs: true
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pypa/build
run: >-
python -m
pip install
--upgrade
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}