fix: issue4 current user middleware cause exceptions in when another … #301
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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 |