Skip to content

Commit

Permalink
Initial GitHub Actions workflow. (#283)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jezdez and hugovk committed Nov 26, 2020
1 parent 50da341 commit 9100895
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 49 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 69 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 }}
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down Expand Up @@ -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.

11 changes: 8 additions & 3 deletions auditlog_tests/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------------------
Expand Down
17 changes: 12 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9100895

Please sign in to comment.