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 <hugovk@users.noreply.github.com>

* Update auditlog_tests/tests.py

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>

* Update .github/workflows/test.yml

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>

* Update README.md

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>

* Add Django 3.1 to tox config.

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
Jannis Leidel 2020-11-26 10:45:20 +01:00 committed by GitHub
parent 50da34125c
commit 910089597e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 145 additions and 49 deletions

53
.github/workflows/release.yml vendored Normal file
View file

@ -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

69
.github/workflows/test.yml vendored Normal file
View file

@ -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 }}

View file

@ -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

View file

@ -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.

View file

@ -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 @@ class AdditionalDataModelTest(TestCase):
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,

View file

@ -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
------------------------------------------

17
tox.ini
View file

@ -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