-
Notifications
You must be signed in to change notification settings - Fork 7
226 lines (195 loc) · 6.42 KB
/
test-backend.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
name: "Backend tests"
on:
push:
paths:
- backend/**
branches:
- main
pull_request:
workflow_dispatch:
# Cancel a workflow from the same PR, branch or tag when a new workflow is triggered.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
PYTHON_VERSION: 3.13
jobs:
checks:
name: "Check migrations and translations"
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:13-3.3-alpine
env:
POSTGRES_USER: tvp
POSTGRES_PASSWORD: tvp
POSTGRES_DB: tvp
DEBUG: true
SECRET_KEY: build_secret
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 10
ports:
- 5432:5432
redis:
image: redis:7-alpine
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 10
ports:
- 6379:6379
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Set up python"
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: "Install Poetry and project dependencies"
uses: ./.github/actions/poetry
with:
python-version: ${{ steps.setup-python.outputs.python-version }}
- name: "Test for migration issues"
working-directory: backend
run: poetry run python manage.py makemigrations --check --no-color --no-input --dry-run
env:
DJANGO_SETTINGS_ENVIRONMENT: CI
DATABASE_URL: postgis://tvp:tvp@localhost:5432/tvp
- name: "Test for missing translation"
working-directory: backend
run: poetry run python -m config.hooks.translations_done
env:
DJANGO_SETTINGS_ENVIRONMENT: CI
DATABASE_URL: postgis://tvp:tvp@localhost:5432/tvp
test:
name: "Run tests (${{ matrix.group }}/8)"
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:13-3.3-alpine
env:
POSTGRES_USER: tvp
POSTGRES_PASSWORD: tvp
POSTGRES_DB: tvp
DEBUG: true
SECRET_KEY: build_secret
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 10
ports:
- 5432:5432
redis:
image: redis:7-alpine
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 5s
--health-retries 10
ports:
- 6379:6379
strategy:
matrix:
# Length must match "--splits".
group: [1, 2, 3, 4, 5, 6, 7, 8]
steps:
- name: "Checkout code"
uses: actions/checkout@v4
- name: "Set up python"
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: "Install Poetry and project dependencies"
uses: ./.github/actions/poetry
with:
python-version: ${{ steps.setup-python.outputs.python-version }}
- name: "Download test durations artifact"
uses: dawidd6/action-download-artifact@v8
with:
workflow: update_test_durations.yml
name: test_durations
- name: "Run pytest with coverage"
working-directory: backend
run: |
poetry run coverage run \
--branch \
-m pytest \
--disable-warnings \
--splits 8 \
--splitting-algorithm least_duration \
--group ${{ matrix.group }}
env:
DJANGO_SETTINGS_ENVIRONMENT: AutomatedTests
COVERAGE_FILE: .coverage.${{ matrix.group }}
# Invalid characters in artifact name: " : < > | * ? \r \n \ /
- name: "Create artifact name"
id: artifact
run: >-
echo "artifact=$(
echo ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | sed 's/[":<>|*?\r\n\\/]/-/g'
)" >> $GITHUB_OUTPUT
- name: "Upload coverage artifact"
uses: actions/upload-artifact@v4
with:
name: cov-${{ steps.artifact.outputs.artifact }}-${{ matrix.group }}
path: ./backend/.coverage.${{ matrix.group }}
if-no-files-found: error
retention-days: 1
include-hidden-files: true
overwrite: true
sonarcloud:
needs: test
name: "SonarCloud scan"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
# Disable shallow cloning to improve relevancy of reporting in SonarCloud
fetch-depth: 0
# Invalid characters in artifact name: " : < > | * ? \r \n \ /
- name: "Create artifact name"
id: artifact
run: >-
echo "artifact=$(
echo ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | sed 's/[":<>|*?\r\n\\/]/-/g'
)" >> $GITHUB_OUTPUT
- name: "Download coverage artifacts"
uses: actions/download-artifact@v4
with:
path: ./backend
pattern: cov-${{ steps.artifact.outputs.artifact }}-*
merge-multiple: true
- name: "Set up python"
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: "Install coverage"
working-directory: backend
run: pip install coverage
- name: "Combine coverage reports and generate XML report"
working-directory: backend
run: |
coverage combine
coverage xml
sed -i 's@<source>@<source>backend/@g' coverage.xml
- name: "SonarCloud Scan"
uses: SonarSource/sonarqube-scan-action@v5
with:
projectBaseDir: ./backend
# Skip analysis for all bots
if: ${{ ! contains(fromJSON(vars.BOTS), github.event.pull_request.user.login) }}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}