Skip to content

Commit 1bf93d9

Browse files
authored
Set up Github Actions (#1)
* Fix readme and project links * Set up Github Actions with tox * We don't support py38 * Fix pytest configuration * No need to install package to run tox * Fix tox version mapping for Github Actions * Test Django 4.2 with more Python versions * Fix nightly workflow * Trim down to supported Wagtail versions only * Add support for Python 3.13 * PR feedback
1 parent c227fd8 commit 1bf93d9

File tree

7 files changed

+190
-14
lines changed

7 files changed

+190
-14
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
Called by GH Actions when the nightly build fails.
3+
4+
This reports an error to the #nightly-build-failures Slack channel.
5+
"""
6+
7+
import os
8+
9+
import requests
10+
11+
12+
if "SLACK_WEBHOOK_URL" in os.environ:
13+
print("Reporting to #nightly-build-failures slack channel")
14+
response = requests.post(
15+
os.environ["SLACK_WEBHOOK_URL"],
16+
json={
17+
"text": "A Nightly build failed. See https://github.com/torchbox/django-birdbath/actions/runs/"
18+
+ os.environ["GITHUB_RUN_ID"],
19+
},
20+
timeout=30,
21+
)
22+
23+
print("Slack responded with:", response)
24+
25+
else:
26+
print(
27+
"Unable to report to #nightly-build-failures slack channel because SLACK_WEBHOOK_URL is not set"
28+
)

.github/workflows/nightly.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Nightly Wagtail Test
2+
3+
on:
4+
schedule:
5+
- cron: '0 1 * * *'
6+
# At 01:00, daily
7+
workflow_dispatch:
8+
9+
jobs:
10+
nightly-wagtail-test:
11+
runs-on: ubuntu-latest
12+
env:
13+
WEBHOOK_EXISTS: ${{ secrets.SLACK_WEBHOOK_URL != '' }}
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
21+
- run: git clone https://github.com/wagtail/wagtail.git
22+
23+
- run: python -m pip install flit
24+
- run: flit install --extras dev
25+
- run: python -m pip install ./wagtail
26+
27+
- run: pytest
28+
29+
- name: Report failure
30+
run: |
31+
python -m pip install requests
32+
python ./.github/scripts/report_nightly_build_failure.py
33+
if: ${{ failure() && env.WEBHOOK_EXISTS == 'true' }}
34+
env:
35+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# See https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
2+
# for a detailed guide
3+
name: Publish to PyPI
4+
5+
on:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read # to fetch code (actions/checkout)
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Python 3.11
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: '3.11'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
python -m pip install flit
28+
python -m flit install --symlink
29+
30+
- name: Build
31+
run: python -m flit build
32+
33+
- uses: actions/upload-artifact@v4
34+
with:
35+
path: ./dist
36+
37+
publish:
38+
needs: build
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: none
42+
id-token: write # required for trusted publishing
43+
environment: publish
44+
steps:
45+
- uses: actions/download-artifact@v4
46+
47+
- name: Publish to PyPI
48+
uses: pypa/gh-action-pypi-publish@release/v1
49+
with:
50+
packages-dir: artifact/
51+
print-hash: true

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Django Birdbath CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'stable/**'
8+
9+
pull_request:
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
contents: read # to fetch code (actions/checkout)
17+
18+
jobs:
19+
lint:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Set up Python 3.12
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.12'
29+
- uses: pre-commit/[email protected]
30+
31+
test:
32+
runs-on: ubuntu-latest
33+
needs: lint
34+
strategy:
35+
matrix:
36+
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
37+
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Set up Python ${{ matrix.python }}
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python }}
44+
- name: Install
45+
run: |
46+
python -m pip install --upgrade pip tox tox-gh-actions
47+
- name: Test
48+
run: tox

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Your site will probably have some of your own check/processor needs.
3939

4040
Custom checks can be implemented by subclassing `birdbath.checks.BaseCheck` and implementing the `check` method:
4141

42-
```
42+
```python
4343
from birdbath.checks import BaseCheck
4444

4545

@@ -54,7 +54,7 @@ The `check` method should either return `True` if the checks should continue, or
5454

5555
Custom processors can be implemented by subclassing `birdbath.processors.BaseProcessor` and implementing the `run` method:
5656

57-
```
57+
```python
5858
from birdbath.processors import BaseProcessor
5959

6060

@@ -65,7 +65,7 @@ class DeleteAllMyUsersProcessor(BaseProcessor):
6565

6666
There are also more specialised base classes in `birdbath.processors` that can help you write cleaner custom processors. For example, the above example could be written using the `BaseModelDeleter` class instead:
6767

68-
```
68+
```python
6969
from birdbath.processors import BaseModelDeleter
7070

7171

@@ -75,7 +75,7 @@ class DeleteAllMyUsersProcessor(BaseModelDeleter):
7575

7676
If you only need to delete a subset of users, you can override the `get_queryset()` method, like so:
7777

78-
```
78+
```python
7979
from birdbath.processors import BaseModelDeleter
8080

8181

@@ -88,8 +88,7 @@ class DeleteNonStaffUsersProcessor(BaseModelDeleter):
8888

8989
If you're looking to 'anonymise' rather than delete objects, you will likely find the `BaseModelAnonymiser` class useful. You just need to indicate the fields that should be 'anonymised' or 'cleared', and the class will do the rest. For example:
9090

91-
92-
```
91+
```python
9392
from birdbath.processors import BaseModelAnonymiser
9493

9594

@@ -122,7 +121,7 @@ The class will generate:
122121

123122
If you have fields with custom validation requirements, or would simply like to generate more realistic replacement values, you can add 'generate' methods to your subclass to achieve this. `BaseModelAnonymiser` will automatically look for method matching the format `"generate_{field_name}"` when anoymising field values. For example, the following processor will generate random values for "account_holder" and "account_number" fields:
124123

125-
```
124+
```python
126125
from birdbath.processors import BaseModelAnonymiser
127126

128127

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ classifiers = [
1515
"Programming Language :: Python :: 3.10",
1616
"Programming Language :: Python :: 3.11",
1717
"Programming Language :: Python :: 3.12",
18+
"Programming Language :: Python :: 3.13",
1819
]
1920
keywords = ["django", "anonymization", "data cleaning"]
2021
dependencies = [
21-
"Faker >=8",
22+
"Faker>=8",
23+
"Django>=4.2",
2224
]
2325
requires-python = ">=3.9"
2426

2527
[project.urls]
26-
Home = "https://git.torchbox.com/internal/django-birdbath"
28+
Home = "https://github.com/torchbox/django-birdbath"
2729

2830
[project.optional-dependencies]
2931
dev = [
@@ -60,3 +62,8 @@ lint.select = [
6062
"C4", # flake8-comprehensions
6163
"UP", # pyupgrade
6264
]
65+
66+
[tool.pytest.ini_options]
67+
django_find_project = false
68+
pythonpath = "."
69+
DJANGO_SETTINGS_MODULE = "tests.settings"

tox.ini

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
[tox]
22
envlist =
3-
py39-django42-wagtail62
4-
py{310,311,312}-django{50,51}-wagtail62
5-
py312-django42-wagtail{52,60,61,62}
3+
# Django versions with their respectively supported Python versions and the most recent Wagtail LTS
4+
py{39,310,311,312,313}-django42-wagtail62
5+
py{310,311,312,313}-django{50,51}-wagtail62
6+
# Old Wagtail versions with the oldest Django LTS and Python
7+
py39-django42-wagtail52
68
isolated_build = True
79

10+
[gh-actions]
11+
python =
12+
3.9: py39
13+
3.10: py310
14+
3.11: py311
15+
3.12: py312
16+
3.13: py313
17+
818
[testenv]
919
deps =
1020
django42: Django>=4.2,<5.0
1121
django50: Django>=5.0,<5.1
1222
django51: Django>=5.1,<5.2
1323
wagtail52: wagtail>=5.2,<5.3
14-
wagtail60: wagtail>=6.0,<6.1
15-
wagtail61: wagtail>=6.1,<6.2
1624
wagtail62: wagtail>=6.2,<6.3
1725
pytest
1826
pytest-django

0 commit comments

Comments
 (0)