From 516306ccd71af0612a444390b765b96399c9ae21 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 21 Dec 2020 12:08:50 +0100 Subject: [PATCH] Add GitHub Actions test workflow. --- .github/workflows/test.yml | 51 +++++++++++++++++++ README.rst | 8 +-- .../{travis_settings.py => ci_settings.py} | 4 +- exampleapp/settings.py | 2 +- tox.ini | 5 +- 5 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/test.yml rename defender/{travis_settings.py => ci_settings.py} (96%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e71faf5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,51 @@ +name: Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: ['3.6', '3.7', '3.8', '3.9', 'pypy3'] + + steps: + - uses: actions/checkout@v2 + + - name: Start Redis + uses: supercharge/redis-github-action@1.1.0 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Get pip cache dir + id: pip-cache + run: | + echo "::set-output name=dir::$(pip cache dir)" + + - name: Cache + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: + ${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.py') }}-${{ hashFiles('**/tox.ini') }} + restore-keys: | + ${{ matrix.python-version }}-v1- + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox tox-gh-actions + + - name: Tox tests + run: | + tox -v + + - name: Upload coverage + uses: codecov/codecov-action@v1 + with: + name: Python ${{ matrix.python-version }} diff --git a/README.rst b/README.rst index 4187c65..11fcc62 100644 --- a/README.rst +++ b/README.rst @@ -14,15 +14,15 @@ django-defender :target: https://pypi.org/project/django-defender/ :alt: Supported Django versions -.. image:: https://travis-ci.org/jazzband/django-defender.svg - :target: https://travis-ci.org/jazzband/django-defender - :alt: Build Status +.. image:: https://github.com/jazzband/django-defender/workflows/Test/badge.svg + :target: https://github.com/jazzband/django-defender/actions + :alt: GitHub Actions .. image:: https://codecov.io/gh/jazzband/django-defender/branch/master/graph/badge.svg :target: https://codecov.io/gh/jazzband/django-defender :alt: Coverage -.. image:: https://readthedocs.org/projects/python-dockerflow/badge/?version=latest +.. image:: https://readthedocs.org/projects/python-defender/badge/?version=latest :alt: Documentation Status :target: https://django-defender.readthedocs.io/en/latest/?badge=latest diff --git a/defender/travis_settings.py b/defender/ci_settings.py similarity index 96% rename from defender/travis_settings.py rename to defender/ci_settings.py index a4942c4..64e1e50 100644 --- a/defender/travis_settings.py +++ b/defender/ci_settings.py @@ -59,7 +59,7 @@ LOGIN_REDIRECT_URL = "/admin" DEFENDER_LOGIN_FAILURE_LIMIT = 10 DEFENDER_COOLOFF_TIME = 2 DEFENDER_REDIS_URL = "redis://localhost:6379/1" -# don't use mock redis in unit tests, we will use real redis on travis. +# don't use mock redis in unit tests, we will use real redis on CI. DEFENDER_MOCK_REDIS = False # Celery settings: @@ -68,7 +68,7 @@ BROKER_BACKEND = "memory" BROKER_URL = "memory://" # set the default Django settings module for the 'celery' program. -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "defender.travis_settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "defender.ci_settings") app = Celery("defender") diff --git a/exampleapp/settings.py b/exampleapp/settings.py index 88b2849..840f2c1 100644 --- a/exampleapp/settings.py +++ b/exampleapp/settings.py @@ -57,7 +57,7 @@ LOGIN_REDIRECT_URL = "/admin" DEFENDER_LOGIN_FAILURE_LIMIT = 1 DEFENDER_COOLOFF_TIME = 60 DEFENDER_REDIS_URL = "redis://localhost:6379/1" -# don't use mock redis in unit tests, we will use real redis on travis. +# don't use mock redis in unit tests, we will use real redis on CI. DEFENDER_MOCK_REDIS = False # Let's use custom function and strip username string from request. DEFENDER_GET_USERNAME_FROM_REQUEST_PATH = ( diff --git a/tox.ini b/tox.ini index 919835b..3dc8c49 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py{36,37,38,39,py3}-django{22,30,31,master} py38-{lint,docs} -[travis] +[gh-actions] python = 3.6: py36 3.7: py37 @@ -21,8 +21,9 @@ deps = djangomaster: https://github.com/django/django/archive/master.tar.gz usedevelop = True commands = - {envbindir}/coverage run --source=defender {envbindir}/django-admin test defender --settings=defender.travis_settings + {envbindir}/coverage run --source=defender {envbindir}/django-admin test defender --settings=defender.ci_settings {envbindir}/coverage report -m + {envbindir}/coverage xml [testenv:py38-docs] basepython = python3.8