Skip to content

Commit

Permalink
establish GitHub actions testing with TOX
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed May 23, 2024
1 parent c2302df commit 244b008
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[run]
omit =
*/virtualenvs/*,
*/migrations/*,
*/site-packages/*
include = import_export_celery/*
plugins =
django_coverage_plugin
branch = True
83 changes: 82 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Flake8
name: CI

on: [push, pull_request]

Expand All @@ -7,6 +7,87 @@ concurrency:
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_DB: pguser
POSTGRES_USER: pguser
POSTGRES_PASSWORD: foobar
options: >-
--health-cmd "pg_isready -U pguser"
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:latest
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
django-version: ["3.2", "4.0", "4.1", "4.2", "5.0", "5.1"]
exclude:
- python-version: "3.8"
django-version: "5.0"
- python-version: "3.8"
django-version: "5.1"

- python-version: "3.9"
django-version: "5.0"
- python-version: "3.9"
django-version: "5.1"

- python-version: "3.11"
django-version: "3.2"

- python-version: "3.12"
django-version: "3.2"
- python-version: "3.12"
django-version: "4.0"

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Run Tox
env:
DJANGO_VERSION: ${{ matrix.django-version }}
run: |
PYTHON_VERSION=`echo ${{ matrix.python-version }} | sed 's/\.//'`
DJANGO_VERSION=`echo $DJANGO_VERSION | sed 's/\.//'`
tox -e py${PYTHON_VERSION}-django${DJANGO_VERSION}
# TODO: activate when organization token will be available
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: coverage.xml
# fail_ci_if_error: true
flake8:
name: flake8
runs-on: ubuntu-latest
Expand Down
29 changes: 19 additions & 10 deletions example/project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
"debug": DEBUG,
},
},
]
Expand All @@ -78,16 +79,24 @@
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("DATABASE_NAME", "pguser"),
"USER": os.environ.get("DATABASE_USER", "pguser"),
"PASSWORD": os.environ.get("DATABASE_PASSWORD", "foobar"),
"HOST": os.environ.get("DATABASE_HOST", "postgres"),
"PORT": os.environ.get("DATABASE_PORT", ""),
},
}
if os.environ.get("DATABASE_TYPE") == "sqlite":
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.environ.get("DATABASE_NAME", os.path.join(BASE_DIR, "db.sqlite3")),
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": os.environ.get("DATABASE_NAME", "pguser"),
"USER": os.environ.get("DATABASE_USER", "pguser"),
"PASSWORD": os.environ.get("DATABASE_PASSWORD", "foobar"),
"HOST": os.environ.get("DATABASE_HOST", "postgres"),
"PORT": os.environ.get("DATABASE_PORT", ""),
},
}

STORAGES = {
"IMPORT_EXPORT_CELERY_STORAGE": {
Expand Down
7 changes: 7 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Django
django-import-export
django-author
html2text
celery
psycopg2-binary
django-admin-smoke-tests
38 changes: 38 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[tox]
envlist =
py{36,37,38,39,310}-django32
py{38,39,310}-django40
py{38,39,310,311}-django41
py{38,39,310,311,312}-django42
py{310,311,312}-django50
py{310,311,312}-django51

[testenv]
deps =
-rrequirements_test.txt
coverage
django-coverage-plugin
django32: django>=3.2,<3.3
django40: django>=4.0,<4.1
django41: django>=4.1,<4.2
django42: django>=4.2,<4.3
django50: django>=5.0,<5.1
django51: django>=5.1a1,<5.2

setenv =
DATABASE_TYPE=sqlite
REDIS_URL=redis://127.0.0.1:6379/0

allowlist_externals = coverage

test-executable =
python --version
python -c "import django; print(django.get_version())"
pip install -r requirements_test.txt
{envbindir}/python -Wall {envbindir}/coverage run --append

commands =
python example/manage.py migrate
{[testenv]test-executable} example/manage.py test winners
coverage report
coverage xml -o coverage.xml

0 comments on commit 244b008

Please sign in to comment.