Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
7937352
ci: run tests on pull requests to main only, via shared ci-workflows
CtrlAltDevelop Nov 25, 2026
624e563
📄 document(license): relicense from MIT to AGPL-3.0-only
CtrlAltDevelop Nov 26, 2026
3b83ee0
📄 document(readme): add badges and contributing/security section
CtrlAltDevelop Nov 26, 2026
206cf76
⚙️ ci(release): publish from this workflow, not the shared one
CtrlAltDevelop Nov 26, 2026
7b8c7f3
🚀 release: 2.2.0
CtrlAltDevelop Nov 26, 2026
c86f086
⚙️ ci(release): publish on a published GitHub Release
CtrlAltDevelop Nov 26, 2026
5b06210
📦 add(webhooks): signed outgoing webhooks with retries and SSRF guard
CtrlAltDevelop Nov 26, 2026
3e3c1a4
📦 add(files): owned file uploads over REST, GraphQL and gRPC
CtrlAltDevelop Nov 26, 2026
1b87e7c
📦 add(audit): append-only audit log app over REST, GraphQL and gRPC
CtrlAltDevelop Nov 26, 2026
214b01a
🔧 update(audit): record shop order and wallet back-office changes
CtrlAltDevelop Nov 26, 2026
7809a77
📦 add(flags): feature flags app with overrides and percentage rollout
CtrlAltDevelop Nov 26, 2026
29566e4
📄 document(examples): tour the feature flags endpoints in the walkthr…
CtrlAltDevelop Nov 26, 2026
7436a38
💫 style(tests): wrap the feature app list after adding flags
CtrlAltDevelop Nov 29, 2026
2816119
📄 document(changelog): list the four new apps under 2.2.0
CtrlAltDevelop Nov 29, 2026
1ac14eb
🛠️ fix(grpc): pin grpcio-tools so protos --check matches in CI
CtrlAltDevelop Nov 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ DJANGO_SUPPORT_UPLOAD_EXTENSIONS=
# Zero keeps everything. Set a window and schedule `manage.py support_prune`;
# nothing deletes a customer's support history until you run it.
DJANGO_SUPPORT_RETENTION_DAYS=0
DJANGO_FILES_ENABLED=true
# DJANGO_FILES_TRANSPORTS=rest,graph,grpc
# A prefix inside STORAGES["default"], not a filesystem path.
DJANGO_FILES_UPLOAD_PATH=files
# The largest file anybody may upload. Zero means no limit.
DJANGO_FILES_MAX_UPLOAD_MB=10
# Where uploads are stored: `filesystem` (MEDIA_ROOT) or `s3` (needs
# `pip install '.[s3]'` and the bucket settings below).
DJANGO_STORAGE_BACKEND=filesystem
DJANGO_AWS_STORAGE_BUCKET_NAME=
DJANGO_AWS_S3_REGION_NAME=
DJANGO_AWS_S3_ENDPOINT_URL=
DJANGO_AWS_ACCESS_KEY_ID=
DJANGO_AWS_SECRET_ACCESS_KEY=
DJANGO_SHOP_ENABLED=true
# DJANGO_SHOP_TRANSPORTS=rest,graph,grpc
DJANGO_SHOP_CURRENCY=USD
Expand Down Expand Up @@ -218,6 +232,10 @@ DJANGO_CLUB_ENABLED=true
DJANGO_CLUB_JOIN_ON_SIGNUP=
DJANGO_CLUB_PAGE_SIZE=50
DJANGO_CLUB_MAX_PAGE_SIZE=200
# Feature flags: a global switch, per-account overrides and a percentage
# rollout. `apps.flags.is_enabled(key, user)` answers False while this is off.
DJANGO_FLAGS_ENABLED=true
# DJANGO_FLAGS_TRANSPORTS=rest,graph,grpc
# The two transports beside REST. These decide which doors are open, never what
# is behind them.
DJANGO_GRAPHQL_ENABLED=true
Expand Down Expand Up @@ -268,3 +286,11 @@ DJANGO_WEBSOCKET_ALLOWED_ORIGINS=
DJANGO_SECURE_SSL_REDIRECT=true
DJANGO_SECURE_HSTS_SECONDS=31536000
DJANGO_SECURE_HSTS_PRELOAD=true

# Outgoing webhooks. Deliveries are sent by `manage.py webhooks_deliver`; schedule
# it (every minute, say). See docs/webhooks.md.
DJANGO_WEBHOOKS_ENABLED=true
# DJANGO_WEBHOOKS_TRANSPORTS=rest,graph,grpc
DJANGO_WEBHOOKS_MAX_ATTEMPTS=6
DJANGO_WEBHOOKS_BACKOFF_SECONDS=30
DJANGO_WEBHOOKS_TIMEOUT_SECONDS=10
147 changes: 41 additions & 106 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,116 +1,51 @@
# Runs the tests on a pull request into main — and on nothing else.
# The job lives once in CtrlAltDevelop/ci-workflows (python-test.yml).

name: CI

on:
pull_request:
branches: [main]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
permissions: {}

jobs:
# Every pull request runs the suite, and a pull request into `main` runs this
# and nothing else: the branch has already been through the whole pipeline on
# its way into `develop`, and repeating the packaging, the wheel smoke test
# and the example tour to merge a reviewed branch buys minutes, not safety.
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- run: python -m pip install -e '.[dev]'
- run: make test
name: Test
uses: CtrlAltDevelop/ci-workflows/.github/workflows/python-test.yml@v1.2.0
permissions:
contents: read
with:
python-version: "3.12"
install: uv venv && uv pip install -e '.[dev]'
test-command: uv run --no-sync make test

# The wallet's safety rests on `select_for_update`, and SQLite compiles that
# away -- so on the default backend the race tests skip and the whole "no
# double withdrawal" claim is untested. This job is the one place it is
# actually exercised: a real Postgres, and the wallet suite run against it.
# Scoped to the wallet rather than the whole suite because row locking is the
# only thing this proves that the job above does not.
# The wallet's row-lock tests need a real PostgreSQL; on SQLite they skip.
locks:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: wallet
POSTGRES_PASSWORD: wallet
POSTGRES_DB: wallet
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DJANGO_DB_ENGINE: django.db.backends.postgresql
DJANGO_DB_NAME: wallet
DJANGO_DB_USER: wallet
DJANGO_DB_PASSWORD: wallet
DJANGO_DB_HOST: localhost
DJANGO_DB_PORT: "5432"
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- run: python -m pip install -e '.[dev]' 'psycopg[binary]'
# `-p no:randomly` because the race tests run real threads against real
# rows: an ordering that leaves a wallet behind from another test is a
# flake nobody can reproduce.
- run: pytest src/apps/wallet -p no:randomly --no-cov
# Fails the job if the race tests were skipped after all -- a silent skip
# here would put this workflow back exactly where it started.
- name: The row-lock tests must actually have run
run: |
# pipefail, or `tee` succeeding would hide pytest failing.
set -o pipefail
pytest src/apps/wallet/tests/test_concurrency.py -p no:randomly --no-cov -q \
| tee /tmp/locks.txt
if grep -qi "skipped" /tmp/locks.txt; then
echo "::error::the row-lock tests skipped, so nothing proved the locks work"
exit 1
fi

# Everything else a merge could break: the linters and the type checker, the
# wheel, and the published generator building and touring a real project.
# Skipped for a pull request into `main`.
verify:
if: github.base_ref != 'main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- run: python -m pip install -e '.[dev]'
- run: make check
- run: make package
- name: Smoke-test the built wheel
run: |
python -m venv /tmp/django-ninja-starter-wheel
/tmp/django-ninja-starter-wheel/bin/pip install dist/*.whl
cd /tmp
/tmp/django-ninja-starter-wheel/bin/django-ninja-starter example-api
/tmp/django-ninja-starter-wheel/bin/pip install -e 'example-api[dev]'
cd example-api
/tmp/django-ninja-starter-wheel/bin/python manage.py startapi example --api-version v2
# `startapi` scaffolds a gRPC service and says so; its stubs do not
# exist until this runs, and `make check` type-checks the import of
# them. Doing it here is the workflow the command itself prints.
/tmp/django-ninja-starter-wheel/bin/python manage.py protos
PATH="/tmp/django-ninja-starter-wheel/bin:$PATH" make check
PATH="/tmp/django-ninja-starter-wheel/bin:$PATH" make test
- name: Build and tour the example project from that wheel
# The wheel's own django-ninja-starter is first on the path here, so
# this is the published generator building the example, not the
# checkout's copy of it.
run: |
/tmp/django-ninja-starter-wheel/bin/python examples/build.py \
--into /tmp/example-tour --rebuild
/tmp/django-ninja-starter-wheel/bin/python examples/walkthrough.py \
--project /tmp/example-tour
name: Row locks (PostgreSQL)
uses: CtrlAltDevelop/ci-workflows/.github/workflows/python-test.yml@v1.2.0
permissions:
contents: read
with:
python-version: "3.12"
postgres: true
install: uv venv && uv pip install -e '.[dev]' 'psycopg[binary]'
env: |
DJANGO_DB_ENGINE=django.db.backends.postgresql
DJANGO_DB_NAME=test_db
DJANGO_DB_USER=test_user
DJANGO_DB_PASSWORD=test_pass
DJANGO_DB_HOST=localhost
DJANGO_DB_PORT=5432
test-command: |
set -o pipefail
uv run --no-sync pytest src/apps/wallet -p no:randomly --no-cov
uv run --no-sync pytest src/apps/wallet/tests/test_concurrency.py -p no:randomly --no-cov -q | tee /tmp/locks.txt
if grep -qi "skipped" /tmp/locks.txt; then
echo "::error::the row-lock tests skipped, so nothing proved the locks work"
exit 1
fi
69 changes: 54 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
name: Publish to PyPI
# =============================================================================
# Release: build once, publish to PyPI with trusted publishing.
# =============================================================================
# Runs when a GitHub Release is published; its tag must be v<__version__>.
# No API token exists anywhere: PyPI trusts this
# workflow's OIDC identity, configured once under the project's "Publishing"
# settings (owner CtrlAltDevelop, repo django-ninja-starter, workflow
# release.yml, environment pypi).
#
# The publish job lives in this file on purpose: PyPI's trusted publishing
# does not accept the same job run from the shared reusable workflow
# (CtrlAltDevelop/ci-workflows python-publish.yml); it fails with
# `invalid-publisher`, as it did for mdp-outbox v0.2.0.

name: Release

on:
release:
types: [published]

permissions:
contents: read
permissions: {}

jobs:
publish:
build:
name: Build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/django-ninja-starter
timeout-minutes: 10
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v6
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-python@v6
- uses: astral-sh/setup-uv@v7
with:
python-version: "3.12"
- name: Build distributions
- name: Tag matches the package version
run: |
python -m pip install build
python -m build
- name: Publish distributions
uses: pypa/gh-action-pypi-publish@release/v1
version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/django_ninja_starter/__init__.py)
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match __version__ $version"
exit 1
fi
- run: uv build
- uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
if-no-files-found: error

publish:
name: Publish to PyPI
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
environment:
name: pypi
url: https://pypi.org/project/django-ninja-starter/
permissions:
id-token: write # the OIDC token PyPI exchanges for a short-lived upload credential
steps:
- uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
# Don't fail on a re-run: files PyPI already has are skipped.
skip-existing: true
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ All notable changes to this project are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project
follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.0] - 2026-11-26

### Added

- **`apps.audit`: an append-only audit log.** Who changed what and when (actor,
action, target, JSON diff, request IP), readable by staff over REST, GraphQL and
gRPC and never editable on any transport. Shop orders and wallet back-office
changes write entries. Always installed.
- **`apps.files`: owned file uploads** (`DJANGO_FILES_ENABLED`). Django's storage
API, local or S3; sniffed content types, random storage names, owner-or-staff
access. Shares its validation with support attachments.
- **`apps.webhooks`: signed outgoing webhooks** (`DJANGO_WEBHOOKS_ENABLED`).
Per-endpoint secrets, HMAC-SHA256 signatures, retries with exponential backoff
through `manage.py webhooks_deliver`, every attempt recorded, and private,
loopback and link-local targets refused at send time.
- **`apps.flags`: feature flags** (`DJANGO_FLAGS_ENABLED`). A global switch,
per-account overrides and a stable percentage rollout; `is_enabled(key, user)`
is cached and invalidated on save.

### Changed

- **Relicensed from MIT to AGPL-3.0-only.** Releases from 2.2.0 on are under the
GNU Affero General Public License v3; earlier releases keep their MIT license.
- **Releases publish from this repository's own workflow.** PyPI's
trusted publishing rejects the shared reusable publish workflow with
`invalid-publisher`, so the build and publish jobs live in `release.yml`, still run by
publishing a GitHub Release.

## [2.1.1] - 2026-10-15

### Changed
Expand Down
Loading
Loading