-
Notifications
You must be signed in to change notification settings - Fork 76
470 lines (424 loc) · 16.2 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
# 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
LANGUAGES: en fr
LANGUAGE_CODE: en
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
jobs:
test:
name: Python Unittests
runs-on: ubuntu-latest
container: makinacorpus/geodjango:${{ matrix.os }}
strategy:
matrix:
os: ['bionic-3.8', 'focal-3.8']
python-version: ['3.8']
tests-env: ['tests', 'tests_nds']
env:
ENV: ${{ matrix.tests-env }}
OS: ${{ matrix.os }}
POSTGRES_HOST: postgres
REDIS_HOST: redis
services:
postgres:
image: postgis/postgis:12-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
- uses: actions/cache@v3
with:
path: |
./venv
key: pip-${{ matrix.python-version }}-${{ matrix.os }}-${{ hashFiles('./requirements.txt', './dev-requirements.txt', './docs/requirements.txt') }}
restore-keys: |
pip-${{ matrix.python-version }}-${{ matrix.os }}-${{ hashFiles('./requirements.txt', './dev-requirements.txt', './docs/requirements.txt') }}
pip-${{ matrix.python-version }}-${{ matrix.os }}
- name: Prepare test env
run: |
apt-get update -q
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
apt-get install -y --no-install-recommends postgis
- name: Install python dependencies
run: |
python3.8 -m venv ./venv
./venv/bin/pip3 install --upgrade pip wheel setuptools -c requirements.txt -c dev-requirements.txt
./venv/bin/pip3 install -r requirements.txt -U
./venv/bin/pip3 install -r dev-requirements.txt -U
- name: Create test required directories
run: |
mkdir -p ./var/log ./var/cache/sessions
- name: Prepare environment
run: |
mkdir -p $VAR_DIR/conf/extra_static $VAR_DIR/tmp
./venv/bin/python3 ./manage.py collectstatic --clear --noinput --verbosity=0
./venv/bin/python3 ./manage.py compilemessages
- name: Check missing migrations
run: |
ENV=dev ./venv/bin/python3 ./manage.py makemigrations --check
- name: Check running migrations
run: |
ENV=dev ./venv/bin/python3 ./manage.py migrate
- name: Launch Celery
run: |
./venv/bin/celery -A geotrek worker -c 1 &
- name: Unit test
run: |
./venv/bin/coverage run --parallel-mode --concurrency=multiprocessing ./manage.py test --parallel -v 3
./venv/bin/coverage combine
./venv/bin/coverage xml -o coverage.xml
- name: Save coverage
uses: actions/upload-artifact@v2
with:
name: coverage_${{ matrix.os }}_${{ matrix.tests-env }}
path: coverage.xml
upload_coverage:
name: Upload coverage to codecov
runs-on: ubuntu-latest
needs: [ test ]
strategy:
matrix:
os: ['bionic-3.8', 'focal-3.8']
python-version: ['3.8']
tests-env: ['tests', 'tests_nds']
env:
ENV: ${{ matrix.tests-env }}
OS: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v2
with:
name: coverage_${{ matrix.os }}_${{ matrix.tests-env }}
path: .
- uses: codecov/codecov-action@v4
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@v3
- name: Build Docker image
run: |
docker build -f ./docker/Dockerfile -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
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: Building package debian 18.04
run: |
DISTRO=ubuntu:bionic make build_deb
cp ./dpkg/*.deb /home/runner/work/Geotrek-admin/
- 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
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: Building package debian 18.04
run: |
DISTRO=ubuntu:focal make build_deb
cp ./dpkg/*.deb /home/runner/work/Geotrek-admin/
- 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]
env:
CYPRESS_BASE_URL: http://geotrek.local
CYPRESS_CACHE_FOLDER: ~/cypress/cache
services:
postgres:
image: postgis/postgis:12-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 docker/install/.env.dist .env
cp docker/install/docker-compose.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 service apache2 stop
sudo apt-get purge apache2 apache2-utils apache2.2-bin
sudo apt-get autoremove
sudo apt-get install -q -y nginx
sudo unlink /etc/nginx/sites-enabled/default
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" "8001"; 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: cypress-docker
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:12-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-latest
needs: [ test, e2e_docker_image, build_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@v3
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