-
Notifications
You must be signed in to change notification settings - Fork 77
523 lines (475 loc) · 18.7 KB
/
test.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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Test CI
on:
pull_request:
paths-ignore:
- 'docs/**'
push:
branches:
- master
paths-ignore:
- 'docs/**'
release:
types:
- created
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DEBIAN_FRONTEND: noninteractive
POSTGRES_DB: ci_test
POSTGRES_PASSWORD: ci_test
POSTGRES_USER: ci_test
POSTGRES_HOST: 127.0.0.1
SERVER_NAME: geotrek.local
SECRET_KEY: test-test-test
CONVERSION_HOST: localhost
CAPTURE_HOST: localhost
REDIS_HOST: 127.0.0.1
VAR_DIR: /home/runner/work/Geotrek-admin/Geotrek-admin/var
LANG: C.UTF-8
jobs:
test:
name: Python Unittests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04, ubuntu-20.04]
tests-env: ['tests', 'tests_nds']
include:
- os: ubuntu-18.04
python-version: 3.8 # default python version in 18.04
- os: ubuntu-20.04
python-version: 3.8 # default python version in 20.04
env:
ENV: ${{ matrix.tests-env }}
OS: ${{ matrix.os }}
services:
postgres:
image: postgis/postgis:10-2.5
env:
POSTGRES_DB: ci_test
POSTGRES_PASSWORD: ci_test
POSTGRES_USER: ci_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
redis:
image: redis:5.0-alpine
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
with:
path: |
~/.cache/pip
~/.wheel_dir
key: pip-${{ matrix.python-version }}
restore-keys: |
pip-${{ matrix.python-version }}
- name: Install System dependencies
run: |
sudo apt-get update -q
sudo apt-get -qq -y install \
unzip \
gettext \
binutils \
libproj-dev \
gdal-bin \
sudo \
less \
curl \
git \
iproute2 \
software-properties-common \
shared-mime-info \
fonts-liberation \
libssl-dev \
libfreetype6-dev \
libxml2-dev \
libxslt-dev \
libcairo2 \
libpango1.0-0 \
libpangocairo-1.0-0 \
libgdk-pixbuf2.0-dev \
libffi-dev \
libvips
sudo apt-get install -y --no-install-recommends postgis
- name: Install python dependencies
run: |
pip3 wheel --wheel-dir=~/.wheel_dir pip wheel setuptools
pip3 install --find-links=~/.wheel_dir --upgrade pip wheel setuptools
pip3 wheel --wheel-dir=~/.wheel_dir -r requirements.txt
pip3 wheel --wheel-dir=~/.wheel_dir -r dev-requirements.txt
pip3 install --find-links=~/.wheel_dir -r requirements.txt
pip3 install --find-links=~/.wheel_dir -r dev-requirements.txt
- name: Create test required directories
run: |
mkdir -p ./var/log ./var/cache/sessions
- name: Check migrations
run: |
python3 ./manage.py makemigrations --check
- name: Prepare environment
run: |
mkdir -p $VAR_DIR
mkdir -p $VAR_DIR/conf/extra_static
python3 ./manage.py collectstatic --clear --noinput --verbosity=0
python3 ./manage.py compilemessages
- name: Launch Celery
run: |
celery -A geotrek worker -c 1 &
- name: Unit test
run: |
coverage run ./manage.py test -v 3
coverage xml -o coverage.xml
- uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
env_vars: OS,ENV
token: ${{ secrets.CODECOV_TOKEN }} # not usually required for public repos
fail_ci_if_error: true # optional (default = false)
build_docker_image:
name: Build docker image
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
run: |
docker build -t geotrek:latest .
- name: Upload image
uses: ishworkh/docker-image-artifact-upload@v1
with:
image: "geotrek:latest"
build_deb_18_04:
name: Build 18.04 package
runs-on: ubuntu-latest
container: ubuntu:bionic
steps:
- uses: actions/checkout@v3
- name: Prepare debian 18.04 versioning
run: |
grep '^[0-9]\+\.[0-9]\+\.[0-9]\+$' VERSION || sed -i 's/+dev/.ubuntu18.04~dev'$GITHUB_RUN_ID'/' debian/changelog
sed -i 's/geotrek-admin (\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(.*\)) RELEASED;/geotrek-admin (\1.ubuntu18.04\2) bionic;/' debian/changelog
- name: Install build dependencies
run: |
apt-get -q update
apt-get -q -y install dpkg-dev debhelper dh-virtualenv git python3.8 python3.8-venv python3.8-dev libffi-dev libxml2-dev libxslt1-dev libgdal-dev
- name: Building package debian 18.04
run: |
dpkg-buildpackage -uc -us -b
- name: Archive package artifact
uses: actions/upload-artifact@v3
with:
name: debian-18-04
path: |
/home/runner/work/Geotrek-admin/*.deb
build_deb_20_04:
name: Build 20.04 package
runs-on: ubuntu-latest
container: ubuntu:focal
steps:
- uses: actions/checkout@v3
- name: Prepare debian 20.04 versioning
run: |
sed -i 's/+dev/.ubuntu20.04~dev'$GITHUB_RUN_ID'/' debian/changelog
sed -i 's/geotrek-admin (\([0-9]\+\.[0-9]\+\.[0-9]\+\)\(.*\)) RELEASED;/geotrek-admin (\1.ubuntu20.04\2) focal;/' debian/changelog
- name: Install build dependencies
run: |
apt-get -q update
apt-get -q -y install software-properties-common
add-apt-repository ppa:jyrki-pulliainen/dh-virtualenv
apt-get install -q -y dpkg-dev debhelper dh-virtualenv git python3 python3-venv python3-dev libffi-dev libxml2-dev libxslt1-dev libgdal-dev
- name: Building package debian 20.04
run: |
dpkg-buildpackage -uc -us -b
- name: Archive package artifact
uses: actions/upload-artifact@v3
with:
name: debian-20-04
path: |
/home/runner/work/Geotrek-admin/*.deb
e2e_docker_image:
name: Tests E2E docker
runs-on: ubuntu-20.04
needs: [build_docker_image]
services:
postgres:
image: postgis/postgis:10-2.5
env:
POSTGRES_DB: ci_test
POSTGRES_PASSWORD: ci_test
POSTGRES_USER: ci_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
steps:
- uses: actions/checkout@v3
- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
with:
image: "geotrek:latest"
- name: Launch service
run: |
docker tag geotrek:latest geotrekce/admin:latest
cp .env-prod.dist .env; cp docker-compose-prod.yml docker-compose.yml
echo 'LANGUAGES=en fr' >> .env
echo 'LANGUAGE_CODE=en' >> .env
sudo sed -i 's/localhost/geotrek.local/' .env
sudo sed -i 's/127.0.0.1 localhost/127.0.0.1 localhost geotrek.local/' /etc/hosts
mkdir -p var/conf/extra_static
cp cypress/custom.py var/conf/custom.py
echo 'POSTGRES_USER=ci_test' >> .env
echo 'POSTGRES_PASSWORD=ci_test' >> .env
echo 'POSTGRES_DB=ci_test' >> .env
docker-compose run web update.sh
make load_data
make load_test_integration
docker-compose up -d
- name: Prepare nginx
run: |
sudo apt-get install -q -y nginx
sudo mkdir /var/www/geotrek -p
ls -als
pwd
sudo ln -s /home/runner/work/Geotrek-admin/Geotrek-admin/var/media /var/www/geotrek/media
sudo ln -s /home/runner/work/Geotrek-admin/Geotrek-admin/var/static /var/www/geotrek/static
sudo ln -s /home/runner/work/Geotrek-admin/Geotrek-admin/cypress/nginx.conf /etc/nginx/sites-enabled/geotrek.conf
sudo systemctl restart nginx
- name: install Cypress
run: |
cd /home/runner/work/Geotrek-admin/Geotrek-admin/cypress
npm ci
npm list
echo "Waiting for container..."
while ! nc -z "127.0.0.1" "8000"; do
sleep 0.1
done
- name: E2E test
run: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/node_modules/.bin/cypress run -P /home/runner/work/Geotrek-admin/Geotrek-admin/cypress --record --key 64a5a9b3-9869-4a2f-91e4-e3cd27c2f564
continue-on-error: false
- name: Archive results as artifacts
uses: actions/upload-artifact@v3
with:
name: docker-cypress
path: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/videos/*.mp4
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/screenshots/*.png
e2e_deb_18_04:
name: Tests E2E 18.04
runs-on: ubuntu-18.04
needs: [ build_deb_18_04 ]
env:
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache
services:
postgres:
image: postgis/postgis:10-2.5
env:
POSTGRES_DB: ci_test
POSTGRES_PASSWORD: ci_test
POSTGRES_USER: ci_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: debian-18-04
- name: Simulate install.sh procedure
run: |
sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin
sudo apt-get autoremove
echo "deb [arch=amd64] https://packages.geotrek.fr/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/geotrek.list
wget -O- "https://packages.geotrek.fr/geotrek.gpg.key" | sudo apt-key add -
sudo apt-get -q update
echo "geotrek-admin geotrek-admin/LANGUAGES string en fr" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_USER string $POSTGRES_USER" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_DB string $POSTGRES_DB" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_PASSWORD string $POSTGRES_PASSWORD" >> .debian_settings
echo "geotrek-admin geotrek-admin/SERVER_NAME string geotrek.local" >> .debian_settings
mkdir -p /opt/geotrek-admin/var/conf/
cp /home/runner/work/Geotrek-admin/Geotrek-admin/cypress/custom.py /opt/geotrek-admin/var/conf/custom.py
sudo sed -i 's/127.0.0.1 localhost/127.0.0.1 localhost geotrek.local/' /etc/hosts
sudo debconf-set-selections .debian_settings
- name: Install package
run: |
sudo unlink /etc/nginx/sites-enabled/default
sudo apt-get install /home/runner/work/Geotrek-admin/Geotrek-admin/*.deb || exit 0;
sudo systemctl restart nginx
- name: Load Data
run: |
sudo geotrek loaddata minimal
sudo geotrek loaddata cirkwi
sudo geotrek loaddata basic
sudo geotrek loaddata test-integration
for dir in `ls -d /opt/geotrek-admin/lib/python3*/site-packages/geotrek/*/fixtures/upload`; do
cd $dir > /dev/null
sudo cp -r * /opt/geotrek-admin/var/media/upload/
done
- name: Install cypress
run: |
cd /home/runner/work/Geotrek-admin/Geotrek-admin/cypress
npm ci
- name: E2E test
run: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/node_modules/.bin/cypress run -P /home/runner/work/Geotrek-admin/Geotrek-admin/cypress --record --key 64a5a9b3-9869-4a2f-91e4-e3cd27c2f564
continue-on-error: false
- name: Archive results as artifacts
uses: actions/upload-artifact@v3
with:
name: cypress-18.04
path: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/videos/*.mp4
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/screenshots/*.png
e2e_deb_20_04:
name: Tests E2E 20.04
runs-on: ubuntu-20.04
needs: [ build_deb_20_04 ]
env:
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache
services:
postgres:
image: postgis/postgis:10-2.5
env:
POSTGRES_DB: ci_test
POSTGRES_PASSWORD: ci_test
POSTGRES_USER: ci_test
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: debian-20-04
- name: Simulate install.sh procedure
run: |
sudo service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin
sudo apt-get autoremove
echo "deb [arch=amd64] https://packages.geotrek.fr/ubuntu $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/geotrek.list
wget -O- "https://packages.geotrek.fr/geotrek.gpg.key" | sudo apt-key add -
sudo apt-get -q update
echo "geotrek-admin geotrek-admin/LANGUAGES string en fr" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_USER string $POSTGRES_USER" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_DB string $POSTGRES_DB" >> .debian_settings
echo "geotrek-admin geotrek-admin/POSTGRES_PASSWORD string $POSTGRES_PASSWORD" >> .debian_settings
echo "geotrek-admin geotrek-admin/SERVER_NAME string geotrek.local" >> .debian_settings
mkdir -p /opt/geotrek-admin/var/conf/
cp /home/runner/work/Geotrek-admin/Geotrek-admin/cypress/custom.py /opt/geotrek-admin/var/conf/custom.py
sudo sed -i 's/127.0.0.1 localhost/127.0.0.1 localhost geotrek.local/' /etc/hosts
sudo debconf-set-selections .debian_settings
- name: Install package
run: |
sudo unlink /etc/nginx/sites-enabled/default
sudo apt-get install /home/runner/work/Geotrek-admin/Geotrek-admin/*.deb || exit 0;
sudo systemctl restart nginx
- name: Load Data
run: |
sudo geotrek loaddata minimal
sudo geotrek loaddata cirkwi
sudo geotrek loaddata basic
sudo geotrek loaddata test-integration
for dir in `ls -d /opt/geotrek-admin/lib/python3*/site-packages/geotrek/*/fixtures/upload`; do
cd $dir > /dev/null
sudo cp -r * /opt/geotrek-admin/var/media/upload/
done
- name: Install cypress
run: |
cd /home/runner/work/Geotrek-admin/Geotrek-admin/cypress
npm ci
npm list
- name: E2E test
run: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/node_modules/.bin/cypress run -P /home/runner/work/Geotrek-admin/Geotrek-admin/cypress --record --key 64a5a9b3-9869-4a2f-91e4-e3cd27c2f564
continue-on-error: false
- name: Archive results as artifacts
uses: actions/upload-artifact@v3
with:
name: cypress-20.04
path: |
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/videos/*.mp4
/home/runner/work/Geotrek-admin/Geotrek-admin/cypress/screenshots/*.png
deploy:
name: Publish (on release only)
runs-on: ubuntu-18.04
needs: [ test, e2e_docker_image, e2e_deb_18_04, e2e_deb_20_04 ]
if: ${{ github.event_name == 'release' && github.event.action == 'created' }}
steps:
- uses: actions/checkout@v3
- name: Download 18.04 debian artifact
uses: actions/download-artifact@v3
with:
name: debian-18-04
- name: Download 20.04 debian artifact
uses: actions/download-artifact@v3
with:
name: debian-20-04
- name: Download docker image
uses: ishworkh/docker-image-artifact-download@v1
with:
image: "geotrek:latest"
- name: Attach debian packages as release binaries
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: '*.deb'
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_LOGIN }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Publish Docker image (v2 and latest)
run: |
if [[ "${{ github.ref }}" == *"dev"* ]]; then
export DOCKER_TAG=dev
else
docker tag geotrek:latest geotrekce/admin:$(cat VERSION)
docker push geotrekce/admin:$(cat VERSION)
export DOCKER_TAG=latest
fi
docker tag geotrek:latest geotrekce/admin:$DOCKER_TAG
docker push geotrekce/admin:$DOCKER_TAG
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.SSH_PRIVATE_KEY }}
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }}
- name: Publish debian packages
run: |
if [[ "${{ github.ref }}" == *"dev"* ]]; then
export DEB_COMPONENT=dev
else
export DEB_COMPONENT=main
fi
echo "${{ github.ref }} : Publishing as $DEB_COMPONENT package"
scp -P ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no /home/runner/work/Geotrek-admin/Geotrek-admin/geotrek-admin_*_amd64.deb ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/srv/packages/incoming/$DEB_COMPONENT/
if [[ "${{ github.ref }}" == *"dev"* ]]; then
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make bionic_dev -C /srv/packages
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make focal_dev -C /srv/packages
else
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make bionic_main -C /srv/packages
ssh -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} make focal_main -C /srv/packages
fi