-
Notifications
You must be signed in to change notification settings - Fork 99
523 lines (493 loc) · 17.4 KB
/
ci.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
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
name: CI
on:
push:
branches:
- develop
- pytest-docker
release:
types: [published]
env:
postgres-version: '13'
postgis-version: '3.2'
jobs:
#build-backend:
# name: Build backend images
# runs-on: ubuntu-latest
# outputs:
# image_name: ${{ fromJSON(steps.build-prod.outputs.metadata)['image.name'] }}
# image_digest: ${{ steps.build-prod.outputs.digest }}
# steps:
# -
# name: Checkout
# uses: actions/checkout@v3
# with:
# submodules: True
# -
# name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# -
# name: Login to GHCR
# uses: docker/login-action@v2
# if: github.event_name != 'pull_request'
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# #-
# # name: Generate metadata for wheels image
# # id: meta-wheels
# # uses: docker/metadata-action@v4
# # with:
# # images: ghcr.io/${{ github.repository_owner }}/geonature-backend
# # flavor: |
# # suffix=-wheels
# # tags: |
# # type=ref,event=branch
# # type=ref,event=tag
# #-
# # name: Build and export wheels image
# # id: build-wheels
# # uses: docker/build-push-action@v4
# # with:
# # context: .
# # file: ./backend/Dockerfile
# # target: wheels
# # push: ${{ github.event_name != 'pull_request' }}
# # tags: ${{ steps.meta-wheels.outputs.tags }}
# # labels: ${{ steps.meta-wheels.outputs.labels }}
# -
# name: Generate metadata for prod image
# id: meta-prod
# uses: docker/metadata-action@v4
# with:
# images: ghcr.io/${{ github.repository_owner }}/geonature-backend
# tags: |
# type=ref,event=branch
# type=ref,event=pr
# type=ref,event=tag
# -
# name: Build and export prod image
# id: build-prod
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ./backend/Dockerfile
# target: prod
# push: true # ${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta-prod.outputs.tags }}
# labels: ${{ steps.meta-prod.outputs.labels }}
#build-frontend:
# name: Build frontend images
# runs-on: ubuntu-latest
# outputs:
# source_image_name: ${{ fromJSON(steps.build-source.outputs.metadata)['image.name'] }}
# source_image_digest: ${{ steps.build-source.outputs.digest }}
# steps:
# -
# name: Checkout
# uses: actions/checkout@v3
# with:
# submodules: True
# -
# name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
# -
# name: Login to GHCR
# uses: docker/login-action@v2
# if: github.event_name != 'pull_request'
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
# -
# name: Generate metadata for source image
# id: meta-source
# uses: docker/metadata-action@v4
# with:
# images: ghcr.io/${{ github.repository_owner }}/geonature-frontend
# flavor: |
# suffix=-source
# tags: |
# type=ref,event=branch
# type=ref,event=tag
# -
# name: Build and export source image
# id: build-source
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ./frontend/Dockerfile
# target: source
# push: true #${{ github.event_name != 'pull_request' }}
# tags: ${{ steps.meta-source.outputs.tags }}
# labels: ${{ steps.meta-source.outputs.labels }}
# #-
# # name: Generate metadata for nginx image
# # id: meta-nginx
# # uses: docker/metadata-action@v4
# # with:
# # images: ghcr.io/${{ github.repository_owner }}/geonature-frontend
# # flavor: |
# # suffix=-nginx
# # tags: |
# # type=ref,event=branch
# # type=ref,event=tag
# #-
# # name: Build and export nginx image
# # uses: docker/build-push-action@v4
# # with:
# # context: .
# # file: ./frontend/Dockerfile
# # target: prod-base
# # push: ${{ github.event_name != 'pull_request' }}
# # tags: ${{ steps.meta-nginx.outputs.tags }}
# # labels: ${{ steps.meta-nginx.outputs.labels }}
# #-
# # name: Generate metadata for prod image
# # id: meta-prod
# # uses: docker/metadata-action@v4
# # with:
# # images: ghcr.io/${{ github.repository_owner }}/geonature-frontend
# # tags: |
# # type=ref,event=branch
# # type=ref,event=tag
# #-
# # id: build-prod
# # name: Build and export prod image
# # uses: docker/build-push-action@v4
# # with:
# # context: .
# # file: ./frontend/Dockerfile
# # target: prod
# # push: true #${{ github.event_name != 'pull_request' }}
# # tags: ${{ steps.meta-prod.outputs.tags }}
# # labels: ${{ steps.meta-prod.outputs.labels }}
#install-database:
# runs-on: ubuntu-latest
# #needs: build-backend
# name: Install database
# outputs:
# postgres-version: 13
# postgis-version: 3.2
# services:
# postgres:
# #image: postgis/postgis:${{ matrix.postgres-version }}-${{ matrix.postgis-version }}
# image: postgis/postgis:13-3.2
# env:
# POSTGRES_DB: geonature2db
# POSTGRES_PASSWORD: geonatpasswd
# POSTGRES_USER: geonatadmin
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# container:
# #image: ${{ needs.build-backend.outputs.image_name }}@${{ needs.build-backend.outputs.image_digest }}
# image: ghcr.io/pnx-si/geonature-backend@sha256:9a4aa99e05d05602351f6b0a7e8ef6df0edf3441b0d7b234f1b2f576d42ae9df
# volumes:
# - postgres:/geonature-db
# steps:
# -
# name: Install packages
# run: |
# apt update
# apt install -y libgdal-dev postgresql-client
# #-
# # name: Add postgis_raster database extension
# # if: ${{ matrix.postgis-version >= 3 }}
# # run: |
# # psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";'
# # env:
# # PGPASSWORD: geonatpasswd
# - name: Add database extensions
# run: |
# psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "hstore";'
# psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "uuid-ossp";'
# psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "pg_trgm";'
# psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "unaccent";'
# psql -h postgres -U geonatadmin -d geonature2db -tc 'CREATE EXTENSION "postgis_raster";'
# env:
# PGPASSWORD: geonatpasswd
# - uses: actions/checkout@v3
# with:
# submodules: true
# - name: Show database branches and dependencies
# run: |
# geonature db status --dependencies
# env:
# GEONATURE_CONFIG_FILE: config/test_config.toml
# - name: Install database
# run: |
# geonature db upgrade geonature@head -x local-srid=2154
# geonature db autoupgrade -x local-srid=2154
# geonature db upgrade ref_geo_fr_departments@head
# geonature taxref import-v16
# geonature db upgrade geonature-samples@head
# geonature db upgrade nomenclatures_taxonomie_data@head
# geonature db upgrade ref_geo_fr_municipalities@head
# geonature db upgrade ref_geo_inpn_grids_5@head
# geonature sensitivity add-referential \
# --source-name "Référentiel sensibilité TAXREF v16 20230203" \
# --url https://geonature.fr/data/inpn/sensitivity/RefSensibiliteV16_20230203.zip \
# --zipfile RefSensibiliteV16_20230203.zip \
# --csvfile RefSensibiliteV16_20230203/RefSensibilite_16.csv \
# --encoding=iso-8859-15
# geonature upgrade-modules-db
# env:
# GEONATURE_CONFIG_FILE: config/test_config.toml
# - name: Show database status
# run: |
# geonature db status
# env:
# GEONATURE_CONFIG_FILE: config/test_config.toml
# -
# name: Dump database
# run: |
# pg_dump --format=custom --file=geonature-db.dump
# env:
# PGDATABASE: geonature2db
# PGHOST: postgres
# PGUSER: geonatadmin
# PGPASSWORD: geonatpasswd
# -
# name: Upload database
# uses: actions/upload-artifact@v3
# with:
# name: geonature-db-${{ github.sha }}
# path: geonature-db.dump
# #- name: Install core modules backend
# # run: |
# # pip install -e contrib/occtax
# # pip install -e contrib/gn_module_occhab
# # pip install -e contrib/gn_module_validation
# #- name: Install core modules database
# # run: |
# # geonature upgrade-modules-db
# # env:
# # GEONATURE_CONFIG_FILE: config/test_config.toml
# #- name: Show database status
# # run: |
# # geonature db status --dependencies
# # env:
# # GEONATURE_CONFIG_FILE: config/test_config.toml
pytest:
runs-on: ubuntu-latest
#needs: [install-database, build-backend]
#needs: install-database
#env:
# postgres-version: '13'
# postgis-version: '3.2'
strategy:
fail-fast: false
matrix:
python-version: [ '3.7', '3.9' ]
#debian-version: [ '10', '11' ]
#include:
# - debian-version: '10'
# python-version: '3.7'
# postgres-version: '11'
# postgis-version: '2.5'
# - debian-version: '11'
# python-version: '3.9'
# postgres-version: '13'
# postgis-version: '3.2'
name: Run pytest with Python ${{ matrix.python-version }}
services:
postgres:
#image: postgis/postgis:${{ env.postgres-version }}-${{ env.postgis-version }}
#image: postgis/postgis:${{ needs.install-database.outputs.postgres-version }}-${{ needs.install-database.outputs.postgis-version }}
image: postgis/postgis:13-3.2
env:
POSTGRES_DB: geonature2db
POSTGRES_PASSWORD: geonatpasswd
POSTGRES_USER: geonatadmin
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
container:
#image: ${{ needs.build-backend.outputs.image_name }}@${{ needs.build-backend.outputs.image_digest }}
#image: ghcr.io/pnx-si/geonature-backend@sha256:9a4aa99e05d05602351f6b0a7e8ef6df0edf3441b0d7b234f1b2f576d42ae9df
image: ghcr.io/pnx-si/geonature-backend:pytest-docker@sha256:3b0eab8d13fac46803d1ffd464470a6fbe6e1be35d0570a186c479c0bec650f6
steps:
#-
# name: Install packages
# run: |
# apt update
# apt install -y postgresql-client
#-
# name: Add database extensions
# uses: addnab/docker-run-action@v3
# with:
# image: postgis/postgis:13-3.2
# run: |
# psql -tc 'CREATE EXTENSION "hstore";'
# psql -tc 'CREATE EXTENSION "uuid-ossp";'
# psql -tc 'CREATE EXTENSION "pg_trgm";'
# psql -tc 'CREATE EXTENSION "unaccent";'
# psql -tc 'CREATE EXTENSION "postgis_raster";'
# env:
# PGDATABASE: geonature2db
# PGHOST: postgres
# PGUSER: geonatadmin
# PGPASSWORD: geonatpasswd
#-
# name: Install database
# run: |
# geonature db upgrade geonature@head -x local-srid=2154
# geonature db autoupgrade -x local-srid=2154
# geonature db upgrade ref_geo_fr_departments@head
# geonature taxref import-v16
# geonature db upgrade geonature-samples@head
# geonature db upgrade nomenclatures_taxonomie_data@head
# geonature db upgrade ref_geo_fr_municipalities@head
# geonature db upgrade ref_geo_inpn_grids_5@head
# geonature sensitivity add-referential \
# --source-name "Référentiel sensibilité TAXREF v16 20230203" \
# --url https://geonature.fr/data/inpn/sensitivity/RefSensibiliteV16_20230203.zip \
# --zipfile RefSensibiliteV16_20230203.zip \
# --csvfile RefSensibiliteV16_20230203/RefSensibilite_16.csv \
# --encoding=iso-8859-15
# geonature upgrade-modules-db
#-
# name: Download database
# uses: actions/download-artifact@v3
# with:
# name: geonature-db-${{ github.sha }}
# #name: geonature-db-b12ba0c7e564694e6b036e939eb22efc543c0579
#-
# name: List files
# run: |
# ls -la
#-
# name: Load database
# run: |
# pg_restore --dbname=geonature2db geonature-db.dump
# env:
# PGHOST: postgres
# PGUSER: geonatadmin
# PGPASSWORD: geonatpasswd
-
name: Populate database
run: |
/dist/populate-db.sh
env:
GEONATURE_SQLALCHEMY_DATABASE_URI: "postgresql://geonatadmin:geonatpasswd@postgres:5432/geonature2db"
GEONATURE_SECRET_KEY: "5fdc2c8fb46f44033144d07396ba082a95b8b3cc827b611a7aaaefbef414f13b"
GEONATURE_URL_APPLICATION: "http://127.0.0.1:4200"
GEONATURE_API_ENDPOINT: "http://127.0.0.1:8000"
GEONATURE_API_TAXHUB: "http://127.0.0.1:5000/api"
#GEONATURE_SYNTHESE__AREA_AGGREGATION_TYPE: "M5"
srid_local: 2154
install_bdc_statuts: true
#install_grid_layer: true
add_sample_data: true
install_ref_sensitivity: true
-
name: Install test dependencies
run: |
pip install pytest pytest-flask pytest-cov jsonschema
-
name: Test with pytest
run: |
pytest -v --cov --cov-report xml
env:
GEONATURE_CONFIG_FILE: config/test_config.toml
-
name: Upload coverage to Codecov
#if: ${{ matrix.debian-version == '11' }}
uses: codecov/codecov-action@v3
with:
flags: pytest
#cypress:
# runs-on: ubuntu-latest
# #needs: [install-database, build-frontend]
# needs: install-database
# name: Run cypress
# services:
# postgres:
# image: postgis/postgis:13-3.2
# volumes:
# - postgres:/var/lib/postgresql/data
# env:
# POSTGRES_DB: geonature2db
# POSTGRES_PASSWORD: geonatpasswd
# POSTGRES_USER: geonatadmin
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
# taxhub-api:
# image: ghcr.io/pnx-si/taxhub:develop
# env:
# TAXHUB_SQLALCHEMY_DATABASE_URI: postgresql://geonatadmin:geonatpasswd@postgres:5432/geonature2db
# geonature-api:
# image: ghcr.io/pnx-si/geonature-backend@sha256:9a4aa99e05d05602351f6b0a7e8ef6df0edf3441b0d7b234f1b2f576d42ae9df
# env:
# GEONATURE_SQLALCHEMY_DATABASE_URI: postgresql://geonatadmin:geonatpasswd@postgres:5432/geonature2db
# GEONATURE_URL_APPLICATION: http://127.0.0.1:4200/
# GEONATURE_API_ENDPOINT: http://geonature-api/api
# GEONATURE_API_TAXHUB: http://taxhub-api/api
# #container:
# # image: ${{ needs.build-frontend.outputs.source_image_name }}@${{ needs.build-frontend.outputs.source_image_digest }}
# # #image: ghcr.io/pnx-si/geonature-backend@sha256:9a4aa99e05d05602351f6b0a7e8ef6df0edf3441b0d7b234f1b2f576d42ae9df
# #container:
# # image: ghcr.io/pnx-si/geonature-frontend:pytest-docker-source@sha256:3677b26ea39dbdb082548bb943693db61bdc04143738c5deafd4e3fd8c284e3b
# steps:
# -
# name: Install packages
# run: |
# apt update
# apt install -y postgresql-client
# -
# name: Download database
# uses: actions/download-artifact@v3
# with:
# name: geonature-db-${{ github.sha }}
# path: .
# -
# name: Load database
# run: |
# pg_restore --file=geonature-db.dump
# env:
# PGDATABASE: geonature2db
# PGHOST: postgres
# PGUSER: geonatadmin
# PGPASSWORD: geonatpasswd
# -
# name: Clone source code
# uses: actions/checkout@v3
# -
# name: Cache node modules
# uses: actions/cache@v3
# with:
# path: ~/.npm
# key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# ${{ runner.os }}-node-
# -
# name: Node ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}
# -
# name: Install dev dependencies
# run: |
# npm ci
# working-directory: ./frontend
# -
# name: Run cypress
# uses: cypress-io/github-action@v5
# with:
# working-directory: ./frontend
# start: npm run start
# wait-on: http://127.0.0.1:4200