-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (132 loc) · 4.47 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
name: Tests
on:
- push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.11']
defaults:
run:
working-directory: ./app
env:
DB_ENGINE: django.contrib.gis.db.backends.postgis
DB_NAME: admg
DB_USER: admg
DB_PASSWORD: admg
DB_HOST: 127.0.0.1
DB_PORT: 5432
DJANGO_SETTINGS_MODULE: config.settings.local
DJANGO_SECRET_KEY: "secret key here"
DJANGO_ADMIN_URL: admg/
GH_TOKEN: faketokenhere
GCMD_SYNC_SOURCE_EMAIL: gcmdadmg@localhost
GCMD_SYNC_RECIPIENTS: gcmd@localhost
CELERY_BROKER_URL: amqp://guest:guest@localhost:5672/
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Setup PostgreSQL with Postgis
uses: huaxk/[email protected]
with:
postgresql version: latest
postgresql db: admg
postgresql user: admg
postgresql password: admg
- name: Setup RabbitMQ
uses: nijel/[email protected]
with:
rabbitmq version: latest
- name: Install GDAL
run: |
sudo apt-get update -y
sudo apt-get install -y libgdal-dev
- name: Set user-site-path
id: user-site
run: |
USER_SITE_PATH=$(python -m site --user-site)
echo "USER_SITE_PATH=$USER_SITE_PATH" >> $GITHUB_ENV
# NOTE: The cache does not seem to detect changes in the requirements files reliably
- uses: actions/cache@v2
id: cache-dependencies
with:
path: ${{ env.USER_SITE_PATH }}
key: ${{ env.USER_SITE_PATH }}-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements/local.txt') }}
- name: Install Dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: |
python -m pip install --upgrade pip
pip install \
--user \
--upgrade \
--upgrade-strategy eager \
-r requirements/base.txt \
-r requirements/local.txt
- name: Install Playwright Browsers
run: |
python -m playwright install --with-deps
- name: Check for missing migrations
run: |
python manage.py makemigrations --check --dry-run
- name: Run Tests
run: |
python -m coverage run -m pytest
python -m coverage report -m --skip-covered
python -m coverage json -o coverage.json
- name: Save Test Videos
uses: actions/upload-artifact@v3
if: ${{ failure() }}
with:
name: videos
path: app/videos/
- name: Save Code Coverage
uses: actions/upload-artifact@v3
with:
name: code_coverage
path: app/coverage.json
compare-coverage:
runs-on: ubuntu-latest
needs: test
if: ${{ github.ref_name != 'dev'}}
defaults:
run:
working-directory: ./app
steps:
- uses: actions/checkout@v2
- name: Get Commit Coverage
uses: actions/download-artifact@v3
with:
name: code_coverage
path: new_cov
- name: Get Dev Coverage
uses: dawidd6/action-download-artifact@v2
with:
branch: dev
name: code_coverage
path: dev_cov
if_no_artifact_found: fail
- name: Calculate Coverage
id: calculate_coverage
run: |
new_cov=$(cat ../new_cov/coverage.json)
echo "new_cov=${new_cov//'%'/'%25'}" >> $GITHUB_OUTPUT
dev_cov=$(cat ../dev_cov/coverage.json)
echo "dev_cov=${dev_cov//'%'/'%25'}" >> $GITHUB_OUTPUT
- name: Compare Coverage
id: compare_coverage
run: |
dev_total="${{fromJson(steps.calculate_coverage.outputs.dev_cov).totals.percent_covered}}"
new_total="${{fromJson(steps.calculate_coverage.outputs.new_cov).totals.percent_covered}}"
coverage_diff=$(echo "$dev_total - $new_total" | bc -l)
(( $(echo "$coverage_diff > 1.0" | bc -l) )) && result=failure || result=success
echo "Coverage comparison: $result"
- name: Report result
if: ${{steps.compare_coverage.outputs.result=='failure'}}
uses: actions/github-script@v3
with:
script: |
core.setFailed('Test coverage on source branch is lower than on dev branch')