-
Notifications
You must be signed in to change notification settings - Fork 0
108 lines (93 loc) · 3.02 KB
/
test.yml
File metadata and controls
108 lines (93 loc) · 3.02 KB
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
name: Test
on:
push:
branches: [develop]
pull_request:
branches: [develop]
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: pytest
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: testpass
MYSQL_DATABASE: speedcam
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 --silent"
--health-interval=10s
--health-timeout=5s
--health-retries=5
--health-start-period=30s
env:
DJANGO_SETTINGS_MODULE: config.settings.dev
DB_HOST: 127.0.0.1
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: testpass
DB_NAME: speedcam
DB_NAME_VEHICLES: speedcam_vehicles
DB_NAME_DETECTIONS: speedcam_detections
DB_NAME_NOTIFICATIONS: speedcam_notifications
CELERY_BROKER_URL: memory://
SECRET_KEY: ci-test-secret-key
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-test-${{ hashFiles('requirements/test.txt') }}
restore-keys: |
${{ runner.os }}-pip-test-
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y default-libmysqlclient-dev pkg-config
- name: Install Python dependencies
run: pip install -r requirements/test.txt
- name: Create MSA databases
run: |
mysql -h 127.0.0.1 -u root -ptestpass -e "
CREATE DATABASE IF NOT EXISTS speedcam_vehicles CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS speedcam_detections CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE DATABASE IF NOT EXISTS speedcam_notifications CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER DATABASE speedcam CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
"
- name: Run migrations
run: |
python manage.py migrate --database=default
python manage.py migrate --database=vehicles_db
python manage.py migrate --database=detections_db
python manage.py migrate --database=notifications_db
- name: Run tests
run: |
pytest \
--cov=apps \
--cov-report=term-missing \
--cov-report=xml:coverage.xml \
--junitxml=test-results.xml \
-v --tb=short
- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: test-results.xml