From 910089597eebce9b23b7fca9085fa08e4cffd55d Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 26 Nov 2020 10:45:20 +0100 Subject: [PATCH] Initial GitHub Actions workflow. (#283) * Initial GitHub Actions workflow. * Use correct Postgres port. * Fix duplicate. * Use POSTGRES_HOST? * Fixing postgres config? * Pass test env vars with Tox. * Work around issue with Django 3.1. * Write coverage file. * Add release workflow. * Remove Travis config file. * Update .github/workflows/test.yml Co-authored-by: Hugo van Kemenade * Update auditlog_tests/tests.py Co-authored-by: Hugo van Kemenade * Update .github/workflows/test.yml Co-authored-by: Hugo van Kemenade * Update README.md Co-authored-by: Hugo van Kemenade * Add Django 3.1 to tox config. Co-authored-by: Hugo van Kemenade --- .github/workflows/release.yml | 53 +++++++++++++++++++++++++++ .github/workflows/test.yml | 69 +++++++++++++++++++++++++++++++++++ .travis.yml | 38 ------------------- README.md | 4 +- auditlog_tests/tests.py | 11 ++++-- docs/source/installation.rst | 2 +- tox.ini | 17 ++++++--- 7 files changed, 145 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..55a6b6b3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + build: + if: github.repository == 'jazzband/django-auditlog' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - 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: release-${{ hashFiles('**/setup.py') }} + restore-keys: | + release- + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U setuptools twine wheel + + - name: Build package + run: | + python setup.py --version + python setup.py sdist --format=gztar bdist_wheel + twine check dist/* + + - name: Upload packages to Jazzband + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@master + with: + user: jazzband + password: ${{ secrets.JAZZBAND_RELEASE_KEY }} + repository_url: https://jazzband.co/projects/django-auditlog/upload diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..255c02e5 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,69 @@ +name: Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: ['3.5', '3.6', '3.7', '3.8'] + + services: + postgres: + image: postgres:10 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + ports: + - 5432/tcp + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - uses: actions/checkout@v2 + + - 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') }} + restore-keys: | + -${{ matrix.python-version }}-v1- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade tox tox-gh-actions + + - name: Tox tests + run: | + tox -v + env: + TEST_DB_HOST: localhost + TEST_DB_USER: postgres + TEST_DB_PASS: postgres + TEST_DB_NAME: postgres + TEST_DB_PORT: ${{ job.services.postgres.ports[5432] }} + + - name: Upload coverage + uses: codecov/codecov-action@v1 + with: + name: Python ${{ matrix.python-version }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d5d29d87..00000000 --- a/.travis.yml +++ /dev/null @@ -1,38 +0,0 @@ -dist: xenial -sudo: required -language: python -services: -- postgresql -addons: - postgresql: '10' -cache: - pip: true -python: - - 3.5 - - 3.6 - - 3.7 - - 3.8 -jobs: - include: - - stage: deploy - if: tag IS present - python: 3.8 - script: skip - deploy: - provider: pypi - user: jazzband - server: https://jazzband.co/projects/django-auditlog/upload - distributions: sdist bdist_wheel - password: - secure: AD22a73v//OXpP8WgFscTQHQxpNE5Rup9+NhoxNRNYXszc+g9Z9yNO5cokPHD0HUL7pma/V31xK1tavFO7jHfvidcnx8mNwezoW7lQctNErxhtuAUN59654IaTPmTOU6vvdslmtNT1W/M/LDsp5hWyzaCbTNbl5Ag4+spUpSCq8= - skip_existing: true - on: - tags: true - repo: jazzband/django-auditlog - fast_finish: true -install: - - travis_retry pip install -U pip - - travis_retry pip install tox-travis codecov -script: tox -v -after_success: -- codecov diff --git a/README.md b/README.md index d499699f..306dbce4 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,9 @@ django-auditlog =============== [![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/) -[![Build Status](https://travis-ci.org/jazzband/django-auditlog.svg?branch=master)](https://travis-ci.org/jazzband/django-auditlog) +[![Build Status](https://github.com/jazzband/django-auditlog/workflows/Test/badge.svg)](https://github.com/jazzband/django-auditlog/actions) [![Docs](https://readthedocs.org/projects/django-auditlog/badge/?version=latest)](http://django-auditlog.readthedocs.org/en/latest/?badge=latest) +[![codecov](https://codecov.io/gh/jazzband/django-auditlog/branch/master/graph/badge.svg)](https://codecov.io/gh/jazzband/django-auditlog) **Please remember that this app is still in development.** **Test this app before deploying it in production environments.** @@ -39,4 +40,3 @@ Releases 5. Pull request `stable` -> `master`. Now everything is back in sync. Opening a pull request from `master` directly to `stable` is discouraged as `master` may be updated while the PR is open, thus changing the contents of the release. - diff --git a/auditlog_tests/tests.py b/auditlog_tests/tests.py index edd06707..4dd68d72 100644 --- a/auditlog_tests/tests.py +++ b/auditlog_tests/tests.py @@ -1,5 +1,6 @@ import datetime import django +import json from django.conf import settings from django.contrib import auth from django.contrib.auth.models import User, AnonymousUser @@ -257,9 +258,13 @@ def test_model_with_additional_data(self): self.assertTrue(obj_with_additional_data.history.count() == 1, msg="There is 1 log entry") log_entry = obj_with_additional_data.history.get() - self.assertIsNotNone(log_entry.additional_data) - extra_data = log_entry.additional_data - print(type(extra_data), extra_data) + # FIXME: Work-around for the fact that additional_data isn't working + # on Django 3.1 correctly (see https://github.com/jazzband/django-auditlog/issues/266) + if django.VERSION >= (3, 1): + extra_data = json.loads(log_entry.additional_data) + else: + extra_data = log_entry.additional_data + self.assertIsNotNone(extra_data) self.assertTrue(extra_data['related_model_text'] == related_model.text, msg="Related model's text is logged") self.assertTrue(extra_data['related_model_id'] == related_model.id, diff --git a/docs/source/installation.rst b/docs/source/installation.rst index fd631259..a879370b 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -15,7 +15,7 @@ The repository can be found at https://github.com/jazzband/django-auditlog/. - Django 2.2 or higher Auditlog is currently tested with Python 3.5 - 3.8 and Django 2.2, 3.0 and 3.1. The latest test report can be found -at https://travis-ci.com/jazzband/django-auditlog. +at https://github.com/jazzband/django-auditlog/actions. Adding Auditlog to your Django application ------------------------------------------ diff --git a/tox.ini b/tox.ini index 7afa09d9..bd3a88cc 100644 --- a/tox.ini +++ b/tox.ini @@ -1,19 +1,27 @@ [tox] envlist = {py35,py36,py37,py38}-django-22 - {py36,py37,py38}-django-30 - {py36,py37,py38}-django-31 + {py36,py37,py38}-django-{30,31} py38-docs [testenv] -commands = coverage run --source auditlog runtests.py +commands = + coverage run --source auditlog runtests.py + coverage xml deps = django-22: Django>=2.2,<2.3 django-30: Django>=3.0,<3.1 + django-31: Django>=3.1,<3.2 # Test requirements coverage codecov psycopg2-binary +passenv= + TEST_DB_HOST + TEST_DB_USER + TEST_DB_PASS + TEST_DB_NAME + TEST_DB_PORT basepython = py38: python3.8 @@ -26,9 +34,8 @@ changedir = docs/source deps = -rdocs/requirements.txt commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html -[travis] +[gh-actions] python = - 2.7: py27 3.5: py35 3.6: py36 3.7: py37