-
Notifications
You must be signed in to change notification settings - Fork 1
154 lines (135 loc) · 5.54 KB
/
django.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
---
# syntax can be found at https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: Django CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
# the combinations can run in parallel by adjusting this value
max-parallel: 20
# all combinations of the matrix choices below are combined to create jobs. The max combinations is 256
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
database-type: ['postgres', 'mysql']
services:
postgres:
# Docker Hub image
image: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd="pg_isready"
--health-interval=10s
--health-timeout=5s
--health-retries=5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
env:
# Override Django DB settings
POSTGRES_PASSWORD: postgres
POSTGRES_HOST: localhost
mysql:
image: mysql:8.0
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_ROOT_PASSWORD: password
MYSQL_HOST: 127.0.0.1
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
steps:
# for python versions github uses the format "3.10" whereas tox wants "310"
# this converts the github version to the tox version
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs
- name: Set python version variable (short)
id: pyver
run: |
echo "VER=${{ matrix.python-version }}" | sed -E 's/[.]//' >> $GITHUB_OUTPUT
- name: Check out repository code
uses: actions/checkout@v3
# need to install poetry before setting up python:
# see https://github.com/actions/setup-python/issues/374#issuecomment-1088938718
# the whole setup seems like it's full of redundancy (multiple virtualenvs created), but the
# documentation is sparse and testing is very slow (commit+push+wait for actions to run)
#
# This is the reason we don't use the `cache: "poetry"` option for actions/setup-python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# see comment above for why we don't use cache: 'poetry' here
# We don't use actions/cache to cache the virtualenv because poetry --sync is broken with extras
# https://github.com/python-poetry/poetry/issues/7364
# poetry install --no-root --sync --with=dev --extras "extras mysql postgres"
# poetry install --no-root --sync --with=dev --extras ""
# will leave all of the extras installed!
# We run the python environment with the same setup that we use for local dev (venv + tox/poetry)
# An alternative is that suggested by the github actions docs
# https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#caching-packages
# That uses poetry environments which are confusing because they're *not*
# a venv/virtualenv, and you have to prefix everything intended to run with
# the poetry-installed packages with 'poetry run ...'
- name: Create python virtualenv
run: |
pipx install poetry
python${{ matrix.python-version }} -m venv venv
source venv/bin/activate
poetry install --no-root --sync --with=dev --extras "postgres"
# postgres tests
- name: Run PostgreSQL Tests with py${{ matrix.python-version }}
if: matrix.database-type == 'postgres'
run: |
source venv/bin/activate
tox -f test-py${{ steps.pyver.outputs.VER }}-${{ matrix.database-type }}
env:
CI_SERVER: yes
DB_HOST: localhost
DB_PORT: ${{ job.services.postgres.ports[5432] }}
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: postgres
# mysql tests
# - name: Start MySQL service
# if: matrix.database-type == 'mysql'
# run: sudo /etc/init.d/mysql start
- name: Run MySQL Tests with py${{ matrix.python-version }}
if: matrix.database-type == 'mysql'
run: |
source venv/bin/activate
tox -f test-py${{ steps.pyver.outputs.VER }}-${{ matrix.database-type }}
env:
CI_SERVER: yes
DB_HOST: 127.0.0.1
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USER: root
DB_PASSWORD: password
# mypy tests
- name: Run mypy tests (postgres)
if: matrix.python-version == '3.10' && matrix.database-type == 'postgres'
run: |
source venv/bin/activate
tox -f mypy-py${{ steps.pyver.outputs.VER }}-${{ matrix.database-type }}
env:
CI_SERVER: yes
DB_HOST: localhost
DB_PORT: ${{ job.services.postgres.ports[5432] }}
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: postgres
- name: Run mypy tests (mysql)
if: matrix.python-version == '3.10' && matrix.database-type == 'mysql'
run: |
source venv/bin/activate
tox -f mypy-py${{ steps.pyver.outputs.VER }}-${{ matrix.database-type }}
env:
CI_SERVER: yes
DB_HOST: 127.0.0.1
DB_PORT: ${{ job.services.mysql.ports[3306] }}
DB_USER: root
DB_PASSWORD: password