-
Notifications
You must be signed in to change notification settings - Fork 0
386 lines (323 loc) · 14 KB
/
main.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
name: CI
on:
# push: -- just run on PRs for now
pull_request:
workflow_dispatch:
jobs:
build_feature_branch:
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:13-3.0
env:
POSTGRES_PASSWORD: postgis
POSTGRES_DB: arches_lingo
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Install Java, GDAL, and other system dependencies
run: |
sudo apt update
sudo apt-get install libxml2-dev libpq-dev openjdk-8-jdk libgdal-dev libxslt-dev
echo Postgres and ES dependencies installed
- name: Install Python packages
run: |
python -m pip install --upgrade pip
pip install .
pip install -r arches_lingo/install/requirements.txt
pip install -r arches_lingo/install/requirements_dev.txt
echo Python packages installed
- uses: ankane/setup-elasticsearch@v1
with:
elasticsearch-version: 8
- name: Webpack frontend files
run: |
echo "Checking for package.json..."
if [ -f package.json ]; then
echo "package.json found, building static bundle."
npm install && npm run build_test
else
echo "package.json not found, skipping npm commands."
fi
- name: Run frontend tests
run: |
npm run vitest
mv coverage/frontend/coverage.xml feature_branch_frontend_coverage.xml
- name: Check for missing migrations
run: |
python manage.py makemigrations --check
- name: Ensure previous Python coverage data is erased
run: |
coverage erase
- name: Run Python unit tests
run: |
python -W default::DeprecationWarning -m coverage run manage.py test tests --settings="tests.test_settings"
- name: Generate Python report coverage
run: |
coverage report
coverage json
mv coverage/python/coverage.json feature_branch_python_coverage.json
- name: Upload frontend coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: feature-branch-frontend-coverage-report
path: feature_branch_frontend_coverage.xml
overwrite: true
- name: Upload Python coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: feature-branch-python-coverage-report
path: feature_branch_python_coverage.json
overwrite: true
build_target_branch:
runs-on: ubuntu-latest
services:
postgres:
image: postgis/postgis:13-3.0
env:
POSTGRES_PASSWORD: postgis
POSTGRES_DB: arches_lingo
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
fail-fast: false
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Install Java, GDAL, and other system dependencies
run: |
sudo apt update
sudo apt-get install libxml2-dev libpq-dev openjdk-8-jdk libgdal-dev libxslt-dev
echo Postgres and ES dependencies installed
- name: Install Python packages
run: |
python -m pip install --upgrade pip
pip install .
pip install -r arches_lingo/install/requirements.txt
pip install -r arches_lingo/install/requirements_dev.txt
echo Python packages installed
- uses: ankane/setup-elasticsearch@v1
with:
elasticsearch-version: 8
- name: Webpack frontend files
run: |
echo "Checking for package.json..."
if [ -f package.json ]; then
echo "package.json found, building static bundle."
npm install && npm run build_test
else
echo "package.json not found, skipping npm commands."
fi
- name: Run frontend tests
run: |
if [ -f vitest.config.json ]; then
npm run vitest
mv coverage/frontend/coverage.xml target_branch_frontend_coverage.xml
else
echo "Unable to find vitest config. Skipping frontend tests."
fi
- name: Check for missing migrations
run: |
python manage.py makemigrations --check
- name: Ensure previous Python coverage data is erased
run: |
coverage erase
- name: Run Python unit tests
run: |
python -W default::DeprecationWarning -m coverage run manage.py test tests --settings="tests.test_settings"
- name: Generate Python report coverage
run: |
coverage report
coverage json
# handles older target branch
if [ -f coverage/python/coverage.json ]; then
mv coverage/python/coverage.json target_branch_python_coverage.json
else
mv coverage.json target_branch_python_coverage.json
fi
- name: Upload frontend coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: target-branch-frontend-coverage-report
path: target_branch_frontend_coverage.xml
overwrite: true
- name: Upload Python coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: target-branch-python-coverage-report
path: target_branch_python_coverage.json
overwrite: true
check_frontend_coverage:
runs-on: ubuntu-latest
needs: [build_feature_branch, build_target_branch]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x' # Use the latest available version
check-latest: true
- name: Download feature branch frontend coverage report artifact
uses: actions/download-artifact@v4
with:
name: feature-branch-frontend-coverage-report
path: .
- name: Extract feature branch frontend coverage data
shell: pwsh
run: |
[xml]$xml = Get-Content feature_branch_frontend_coverage.xml
$metrics = $xml.coverage.project.metrics
$statements = [double]$metrics.statements
$coveredstatements = [double]$metrics.coveredstatements
$conditionals = [double]$metrics.conditionals
$coveredconditionals = [double]$metrics.coveredconditionals
$methods = [double]$metrics.methods
$coveredmethods = [double]$metrics.coveredmethods
$elements = [double]$metrics.elements
$coveredelements = [double]$metrics.coveredelements
$statement_coverage = 0.0
$conditional_coverage = 0.0
$method_coverage = 0.0
$element_coverage = 0.0
if ($statements -gt 0) {
$statement_coverage = ($coveredstatements / $statements) * 100
}
if ($conditionals -gt 0) {
$conditional_coverage = ($coveredconditionals / $conditionals) * 100
}
if ($methods -gt 0) {
$method_coverage = ($coveredmethods / $methods) * 100
}
if ($elements -gt 0) {
$element_coverage = ($coveredelements / $elements) * 100
}
$nonZeroCount = 0
$totalCoverage = 0.0
if ($statements -gt 0) { $nonZeroCount++; $totalCoverage += $statement_coverage }
if ($conditionals -gt 0) { $nonZeroCount++; $totalCoverage += $conditional_coverage }
if ($methods -gt 0) { $nonZeroCount++; $totalCoverage += $method_coverage }
if ($elements -gt 0) { $nonZeroCount++; $totalCoverage += $element_coverage }
$feature_branch_frontend_coverage = 0.0
if ($nonZeroCount -gt 0) {
$feature_branch_frontend_coverage = $totalCoverage / $nonZeroCount
}
Write-Output "feature_branch_frontend_coverage=$feature_branch_frontend_coverage" | Out-File -Append $env:GITHUB_ENV
- name: Download target branch frontend coverage report artifact
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: target-branch-frontend-coverage-report
path: .
- name: Check if target branch frontend coverage report artifact exists
run: |
if [ -f target_branch_frontend_coverage.xml ]; then
echo "target_branch_frontend_coverage_artifact_exists=true" >> $GITHUB_ENV
else
echo "Target branch coverage not found. Defaulting to 0% coverage."
echo "target_branch_frontend_coverage_artifact_exists=false" >> $GITHUB_ENV
fi
- name: Extract target branch frontend coverage data
if: ${{ env.target_branch_frontend_coverage_artifact_exists == 'true' }}
shell: pwsh
run: |
[xml]$xml = Get-Content target_branch_frontend_coverage.xml
$metrics = $xml.coverage.project.metrics
$statements = [double]$metrics.statements
$coveredstatements = [double]$metrics.coveredstatements
$conditionals = [double]$metrics.conditionals
$coveredconditionals = [double]$metrics.coveredconditionals
$methods = [double]$metrics.methods
$coveredmethods = [double]$metrics.coveredmethods
$elements = [double]$metrics.elements
$coveredelements = [double]$metrics.coveredelements
$statement_coverage = 0.0
$conditional_coverage = 0.0
$method_coverage = 0.0
$element_coverage = 0.0
if ($statements -gt 0) {
$statement_coverage = ($coveredstatements / $statements) * 100
}
if ($conditionals -gt 0) {
$conditional_coverage = ($coveredconditionals / $conditionals) * 100
}
if ($methods -gt 0) {
$method_coverage = ($coveredmethods / $methods) * 100
}
if ($elements -gt 0) {
$element_coverage = ($coveredelements / $elements) * 100
}
$nonZeroCount = 0
$totalCoverage = 0.0
if ($statements -gt 0) { $nonZeroCount++; $totalCoverage += $statement_coverage }
if ($conditionals -gt 0) { $nonZeroCount++; $totalCoverage += $conditional_coverage }
if ($methods -gt 0) { $nonZeroCount++; $totalCoverage += $method_coverage }
if ($elements -gt 0) { $nonZeroCount++; $totalCoverage += $element_coverage }
$target_branch_frontend_coverage = 0.0
if ($nonZeroCount -gt 0) {
$target_branch_frontend_coverage = $totalCoverage / $nonZeroCount
}
Write-Output "target_branch_frontend_coverage=$target_branch_frontend_coverage" | Out-File -Append $env:GITHUB_ENV
- name: Compare frontend feature coverage with target coverage
if: github.event_name == 'pull_request'
run: |
feature_branch_frontend_coverage=${feature_branch_frontend_coverage}
target_branch_frontend_coverage=${target_branch_frontend_coverage:-0.0}
# Compare feature coverage with target coverage using floating-point comparison
if awk -v feature="$feature_branch_frontend_coverage" -v target="$target_branch_frontend_coverage" 'BEGIN { exit (feature < target) ? 0 : 1 }'; then
echo "Coverage decreased from $target_branch_frontend_coverage% to $feature_branch_frontend_coverage%. Please add or update tests to increase coverage."
exit 1
else
echo "Feature branch coverage ($feature_branch_frontend_coverage%) >= Target branch coverage ($target_branch_frontend_coverage%)."
fi
check_python_coverage:
runs-on: ubuntu-latest
needs: [build_feature_branch, build_target_branch]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x' # Use the latest available version
check-latest: true
- name: Download feature branch Python coverage report artifact
uses: actions/download-artifact@v4
with:
name: feature-branch-python-coverage-report
path: .
- name: Download target branch Python coverage report artifact
uses: actions/download-artifact@v4
with:
name: target-branch-python-coverage-report
path: .
- name: Compare Python feature coverage with target coverage
if: github.event_name == 'pull_request'
run: |
feature_branch_python_coverage=$(cat feature_branch_python_coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}')
target_branch_python_coverage=$(cat target_branch_python_coverage.json | grep -o '"totals": {[^}]*' | grep -o '"percent_covered": [0-9.]*' | awk -F ': ' '{print $2}')
# Compare feature coverage with target coverage using floating-point comparison
if awk -v feature="$feature_branch_python_coverage" -v target="$target_branch_python_coverage" 'BEGIN { exit (feature < target) ? 0 : 1 }'; then
echo "Coverage decreased from $target_branch_python_coverage% to $feature_branch_python_coverage%. Please add or update tests to increase coverage."
exit 1
else
echo "Feature branch coverage ($feature_branch_python_coverage%) >= Target branch coverage ($target_branch_python_coverage%)."
fi