Added possibility to run tests through Github Actions.

This commit is contained in:
Benedikt Willi 2021-07-20 15:38:06 +02:00 committed by Guillaume Baffoin
parent e252df9660
commit f547a69e9f
2 changed files with 100 additions and 0 deletions

96
.github/workflows/django.yml vendored Normal file
View File

@ -0,0 +1,96 @@
name: Django CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: test_project
ports:
- 3306:3306
postgres:
image: postgres:13
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_project
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
django-version: [1.11, 2.0, 2.1, 2.2, 3.0, 3.1, 3.2]
exclude:
# Python 2.7 is compatible with Django 1.11
- python-version: "2.7"
django-version: "2.0"
- python-version: "2.7"
django-version: "2.1"
- python-version: "2.7"
django-version: "2.2"
- python-version: "2.7"
django-version: "3.0"
- python-version: "2.7"
django-version: "3.1"
- python-version: "2.7"
django-version: "3.2"
# Python 3.8 is compatible with Django 2.2+
- python-version: "3.8"
django-version: "1.11"
- python-version: "3.8"
django-version: "2.0"
- python-version: "3.8"
django-version: "2.1"
# Python 3.9 is compatible with Django 3.1+
- python-version: "3.9"
django-version: "1.11"
- python-version: "3.9"
django-version: "2.0"
- python-version: "3.9"
django-version: "2.1"
- python-version: "3.9"
django-version: "2.2"
- python-version: "3.9"
django-version: "3.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: psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 coverage "Django~=${{ matrix.django-version }}.0" "psycopg2==2.8.6" mysqlclient -e .
- name: Run Flake8
run: |
flake8
- name: Run Tests
run: |
coverage run -a tests/runtests.py
- name: Run Tests psql
run: |
coverage run -a tests/runtests.py -d psql
env:
DB_USER: postgres
DB_PASSWORD: postgres
- name: Run Tests mysql
run: |
coverage run -a tests/runtests.py -d mysql
env:
DB_USER: root
DB_PASSWORD: mysql

View File

@ -58,17 +58,20 @@ def main():
# database settings
if options.database:
database_setting = AVAILABLE_DATABASES[options.database]
database_default_host = "127.0.0.1"
if options.database == "sqlite":
database_default_name = os.path.join(os.path.dirname(__file__), "db.sqlite3")
else:
database_default_name = "test_project"
database_setting.update(dict(
NAME=os.environ.get("DB_NAME", database_default_name),
HOST=os.environ.get("DB_HOST", database_default_host),
USER=os.environ.get("DB_USER", ""),
PASSWORD=os.environ.get("DB_PASSWORD", "")))
else:
database_setting = dict(
ENGINE=os.environ.get("DB_ENGINE", 'django.db.backends.sqlite3'),
HOST=os.environ.get("DB_HOST", database_default_host),
NAME=os.environ.get("DB_NAME", os.path.join(os.path.dirname(__file__), "db.sqlite3")),
USER=os.environ.get("DB_USER", ""),
PASSWORD=os.environ.get("DB_PASSWORD", ""))
@ -114,6 +117,7 @@ def main():
]},
'APP_DIRS': True,
}],
SECRET_KEY="fake-key"
)
# Run Django setup (1.7+).