-
Notifications
You must be signed in to change notification settings - Fork 12
171 lines (154 loc) · 5.35 KB
/
tests.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
# GeoSight is UNICEF's geospatial web-based business intelligence platform.
#
# Contact : [email protected]
#
# .. note:: This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# __author__ = '[email protected]'
# __date__ = '13/06/2023'
# __copyright__ = ('Copyright 2023, Unicef')
name: Tests
on:
push:
branches: [ main ]
pull_request:
branches: [ main, version-2.0.0 ]
jobs:
flake8_py3:
name: Python Lint
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8.18
architecture: x64
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Display branch
run: git branch --show-current
- name: Install flake8
run: pip install flake8 flake8-docstrings
- name: Run flake8
uses: suo/flake8-github-action@releases/v1
with:
checkName: 'Python Lint'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build_image:
needs: flake8_py3
name: Build Docker Image
runs-on: ubuntu-latest
env:
APP_IMAGE: kartoza/geosight:dev
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Display branch
run: git branch --show-current
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
file: deployment/docker/Dockerfile
push: false
load: true
target: dev
tags: ${{ env.APP_IMAGE }}
cache-from: |
type=gha,scope=test
type=gha,scope=prod
cache-to: type=gha,scope=test
- name: Save Docker Image as Tar File
run: docker save -o /tmp/my-image.tar ${{ env.APP_IMAGE }}
- name: Upload Docker Image Cache
uses: actions/cache@v3
with:
path: /tmp/my-image.tar
key: ${{ runner.os }}-docker-image-${{ hashFiles('deployment/docker/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-image-
django_app_tests:
needs: build_image
name: Django App Tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test_suite: [
{ name: "Backend Tests", script: "make devweb-test" },
{ name: "E2E Tests: Project Creation", path: "tests/project_creation", workers: 2, script_load : "make load-test-data" },
{ name: "E2E Tests: Project View", path: "tests/project_view", workers: 3, script_load : "make load-test-data" },
{ name: "E2E Tests: Admin List", path: "tests/admin_list", workers: 3, script_load : "make load-test-data" },
{ name: "E2E Tests: Admin Edit", path: "tests/admin_edit", workers: 3, script_load : "make load-test-data" },
{ name: "E2E Tests: Admin List Filter", path: "tests/admin_filter", workers: 3, script_load : "make load-test-data-for-filter" }
]
env:
APP_IMAGE: kartoza/geosight
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Display branch
run: git branch --show-current
- name: Restore Docker Image from Cache
uses: actions/cache@v3
with:
path: /tmp/my-image.tar
key: ${{ runner.os }}-docker-image-${{ hashFiles('deployment/docker/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-image-
- name: Load Docker Image
run: docker load -i /tmp/my-image.tar
- name: Run docker-compose services
working-directory: deployment
run: |
echo "Override docker-compose for testing purposes"
cp docker-compose.test.yml docker-compose.override.yml
cp .template.env .env
cd ../
make devweb
make wait-db
docker cp ./django_project geosight_dev:/home/web
make devweb-initialize
- name: Execute Test Backend
if: ${{ matrix.test_suite.script }}
run: ${{ matrix.test_suite.script }}
- name: Prepare container
if: ${{ matrix.test_suite.path }}
run: |
make devweb-entrypoint
make devweb-runserver
${{ matrix.test_suite.script_load }}
make sleep
- name: Test production config ready
if: ${{ matrix.test_suite.path }}
run: make production-check
- name: Test django endpoint
if: ${{ matrix.test_suite.path }}
run: |
curl http://localhost:2000/
if [ $? -ne 0 ]; then
echo "Curl command failed"
exit 1
fi
- name: Test E2E
if: ${{ matrix.test_suite.path }}
working-directory: ./playwright/ci-test
run: |
npm install
npm ci
npx playwright install --with-deps
npx playwright test ${{ matrix.test_suite.path }} --workers ${{ matrix.test_suite.workers }}