| 1 |
name: Tests |
| 2 |
permissions: |
| 3 |
contents: read |
| 4 |
|
| 5 |
on: |
| 6 |
push: |
| 7 |
branches: |
| 8 |
- main |
| 9 |
pull_request: |
| 10 |
|
| 11 |
env: |
| 12 |
# Used in our tox configuration to determine which dependency groups to install |
| 13 |
DEPENDENCY_GROUP: ci |
| 14 |
|
| 15 |
jobs: |
| 16 |
pre-commit: |
| 17 |
runs-on: ubuntu-latest |
| 18 |
steps: |
| 19 |
- name: Checkout code |
| 20 |
uses: actions/[email protected] |
| 21 |
|
| 22 |
- name: Install uv |
| 23 |
uses: astral-sh/[email protected] |
| 24 |
with: |
| 25 |
enable-cache: true |
| 26 |
|
| 27 |
- name: Install Python |
| 28 |
uses: actions/[email protected] |
| 29 |
with: |
| 30 |
python-version: '3.13' |
| 31 |
|
| 32 |
- name: Install pre-commit |
| 33 |
run: uv tool install pre-commit |
| 34 |
|
| 35 |
- name: Run pre-commit hooks |
| 36 |
run: pre-commit run --all-files |
| 37 |
|
| 38 |
tests: |
| 39 |
runs-on: ubuntu-24.04 |
| 40 |
needs: pre-commit |
| 41 |
strategy: |
| 42 |
fail-fast: false |
| 43 |
matrix: |
| 44 |
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14'] |
| 45 |
database-engine: [sqlite, mariadb, postgres] |
| 46 |
|
| 47 |
services: |
| 48 |
mariadb: |
| 49 |
image: mariadb:11.4.2 |
| 50 |
env: |
| 51 |
MYSQL_ROOT_PASSWORD: mariadb |
| 52 |
ports: |
| 53 |
- 3306:3306 |
| 54 |
postgres: |
| 55 |
image: postgres:16-alpine |
| 56 |
env: |
| 57 |
PGUSER: postgres |
| 58 |
POSTGRES_PASSWORD: postgres |
| 59 |
options: >- |
| 60 |
--health-cmd pg_isready |
| 61 |
--health-interval 10s |
| 62 |
--health-timeout 5s |
| 63 |
--health-retries 5 |
| 64 |
ports: |
| 65 |
- 5432:5432 |
| 66 |
|
| 67 |
env: |
| 68 |
DJANGO_SETTINGS_MODULE: tests.server.settings |
| 69 |
DATABASE_ENGINE: ${{ matrix.database-engine }} |
| 70 |
|
| 71 |
steps: |
| 72 |
- name: Checkout code |
| 73 |
uses: actions/[email protected] |
| 74 |
|
| 75 |
- name: Install uv |
| 76 |
uses: astral-sh/[email protected] |
| 77 |
with: |
| 78 |
enable-cache: true |
| 79 |
cache-dependency-glob: pyproject.toml |
| 80 |
|
| 81 |
- name: Install tox |
| 82 |
# See: https://github.com/tox-dev/tox-gh |
| 83 |
run: uv tool install --python-preference only-managed --python 3.13 tox --with . --with tox-uv --with tox-gh |
| 84 |
|
| 85 |
- name: Install Python |
| 86 |
# Skip if the python version is already installed to run tox |
| 87 |
if: matrix.python-version != '3.13' |
| 88 |
run: uv python install --python-preference only-managed ${{ matrix.python-version }} |
| 89 |
|
| 90 |
- name: Setup test suite |
| 91 |
run: tox run -vv --notest --skip-missing-interpreters false |
| 92 |
env: |
| 93 |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} |
| 94 |
|
| 95 |
- name: Create databases |
| 96 |
run: | |
| 97 |
PGPASSWORD="postgres" psql -c 'create database django_guardian;' -h localhost -U postgres; |
| 98 |
PGPASSWORD="postgres" psql -c 'create database test_django_guardian;' -h localhost -U postgres; |
| 99 |
mysql --host=127.0.0.1 --user=root --password=mariadb -e 'CREATE DATABASE django_guardian;'; |
| 100 |
mysql --host=127.0.0.1 --user=root --password=mariadb -e 'CREATE DATABASE test_django_guardian;'; |
| 101 |
|
| 102 |
- name: Test with PostgreSQL |
| 103 |
if: matrix.database-engine == 'postgres' |
| 104 |
env: |
| 105 |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} |
| 106 |
DATABASE_URL: postgres://postgres:postgres@localhost/django_guardian |
| 107 |
PYTEST_ADDOPTS: -vv --durations=20 |
| 108 |
DIFF_AGAINST: HEAD |
| 109 |
UV_PYTHON_PREFERENCE: only-managed |
| 110 |
run: tox run -vv --skip-pkg-install |
| 111 |
|
| 112 |
- name: Test with MariaDB |
| 113 |
if: matrix.database-engine == 'mariadb' |
| 114 |
env: |
| 115 |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} |
| 116 |
DATABASE_URL: mysql://root:[email protected]:3306/django_guardian |
| 117 |
PYTEST_ADDOPTS: -vv --durations=20 |
| 118 |
DIFF_AGAINST: HEAD |
| 119 |
UV_PYTHON_PREFERENCE: only-managed |
| 120 |
run: tox run -vv --skip-pkg-install |
| 121 |
|
| 122 |
- name: Test with SQLite |
| 123 |
if: matrix.database-engine == 'sqlite' |
| 124 |
env: |
| 125 |
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }} |
| 126 |
DATABASE_URL: sqlite:// |
| 127 |
PYTEST_ADDOPTS: -vv --durations=20 |
| 128 |
DIFF_AGAINST: HEAD |
| 129 |
UV_PYTHON_PREFERENCE: only-managed |
| 130 |
run: tox run -vv --skip-pkg-install |