-
-
Notifications
You must be signed in to change notification settings - Fork 188
481 lines (468 loc) · 18.3 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
name: CI
on:
push:
branches:
- dev
- master
pull_request: ~
env:
CACHE_VERSION: 1
DEFAULT_PYTHON: "3.10"
PRE_COMMIT_CACHE: ~/.cache/pre-commit
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
BUILDKIT_PROGRESS: plain
jobs:
prepare-python-venv:
name: Prepare Python venv
runs-on: ubuntu-22.04
outputs:
python-venv-cache-key: ${{ steps.python-venv-cache-key.outputs.key }}
steps:
# Create Python virtual env used for linters
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ env.DEFAULT_PYTHON }}
# Create a virtual environment and cache it
- name: Generate Python virtual environment restore key
id: python-venv-cache-key
env:
cache-name: cache-python-venv
run: >-
echo "key=${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ env.CACHE_VERSION }}-${{ hashFiles('.pre-commit-config.yaml') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements_test.txt') }}-${{ hashFiles('requirements_ci.txt') }}" >> $GITHUB_OUTPUT
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ steps.python-venv-cache-key.outputs.key }}
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
# Install pycoral from Google Coral repo since it is not on PyPI
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libgirepository1.0-dev
python3 -m venv --system-site-packages venv
- name: Install requirements into Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
uses: ./.github/templates/run_in_venv
with:
command: |
pip3 install --extra-index-url https://google-coral.github.io/py-repo/ -r requirements.txt -r requirements_test.txt -r requirements_ci.txt && \
pre-commit install
prepare-pre-commit:
name: Prepare pre-commit
runs-on: ubuntu-22.04
needs: prepare-python-venv
outputs:
pre-commit-cache-key: ${{ steps.pre-commit-cache-key.outputs.key }}
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Generate pre-commit restore key
id: pre-commit-cache-key
env:
cache-name: cache-pre-commit
run: >-
echo "key=${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ env.CACHE_VERSION }}-${{ hashFiles('.pre-commit-config.yaml') }}-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements_test.txt') }}-${{ hashFiles('requirements_ci.txt') }}" >> $GITHUB_OUTPUT
# Install pre-commit hooks into the cached virtual environment
- name: Restore pre-commit hooks
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ steps.pre-commit-cache-key.outputs.key }}
- name: Create pre-commit hooks
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit install-hooks
run-isort:
name: Run isort
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run isort
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual isort --all-files --show-diff-on-failure
run-black:
name: Run black
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run black
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual black --all-files --show-diff-on-failure
run-codespell:
name: Run codespell
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run codespell
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual codespell --all-files --show-diff-on-failure
run-mypy:
name: Run mypy
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run mypy
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual mypy --all-files --show-diff-on-failure
run-pylint:
name: Run pylint
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run pylint
uses: ./.github/templates/run_in_venv
with:
command: |
pylint --version
pylint viseron
run-flake8:
name: Run flake8
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run flake8
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual flake8 --all-files --show-diff-on-failure
run-pyupgrade:
name: Run pyupgrade
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Run pyupgrade
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual pyupgrade --all-files --show-diff-on-failure
run-pytest:
name: Run pytest
runs-on: ubuntu-22.04
needs: prepare-python-venv
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
with:
fetch-depth: 2
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Pull current Docker dev tag
run: |
docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env pull amd64-viseron
docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env pull amd64-wheels
- name: Re-build wheels
run: |
docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env build --build-arg BUILDKIT_INLINE_CACHE=1 amd64-wheels
docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env build --build-arg BUILDKIT_INLINE_CACHE=1 amd64-viseron
- name: Build pytest Docker image
run: |
docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env build --build-arg BUILDKIT_INLINE_CACHE=1 amd64-viseron-tests
- name: Run pytest
run: |
if docker-compose --file azure-pipelines/docker-compose-build.yaml --env-file azure-pipelines/.env up amd64-viseron-tests; then
exit 0
else
exit 1
fi
- name: Copy .coverage to host
run: |
docker cp amd64-viseron-tests:/src/coverage.xml coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
run-generated-docs:
name: Check generated docs
runs-on: ubuntu-22.04
needs: [prepare-python-venv, prepare-pre-commit]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/[email protected]
id: python
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ needs.prepare-python-venv.outputs.python-venv-cache-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-pre-commit
uses: actions/[email protected]
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ needs.prepare-pre-commit.outputs.pre-commit-cache-key }}
- name: Fail job if pre-commit cache restore failed
if: steps.cache-pre-commit.outputs.cache-hit != 'true'
run: |
echo "Failed to restore pre-commit environment from cache"
exit 1
- name: Install libedgetpu1 for edgetpu docs
run: |
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main"
sudo apt-get update
sudo apt-get install -y --no-install-recommends libedgetpu1-std python3-gi python3-gst-1.0
- name: Run script to check generated docs
uses: ./.github/templates/run_in_venv
with:
command: |
pre-commit run --hook-stage manual generate_docs --all-files --show-diff-on-failure
pre-commit run --hook-stage manual check_config_json --all-files --show-diff-on-failure