towncrier-fragment-check
A pre-commit hook and CLI that fails when a branch does
not add a towncrier changelog fragment. It
wraps towncrier check and fills the gaps around it.
What it adds to towncrier check
- Monorepos. Check several towncrier projects in one run with
--project, passing when any one of them has a fragment (--require any) or only when they all do (--require all). - Subdirectories.
towncrier checkresolves git's repository-relative paths against the working directory, so it never matches when run insidepackages/api/. This tool always runs it from the git toplevel. - Base branch. Resolved from the flag, the environment, or
origin/main, whichever git can find first. GitHub pull requests need no configuration. - Empty fragments. A blank fragment file satisfies
towncrier checkand yields a blank release note. It fails here unless you pass--allow-empty. - New branches.
--skip-new-branchpasses a branch's first push, when the pull request number that fragment names often embed does not exist yet.
Installation
default_install_hook_types: [pre-commit, pre-push]
repos:
- repo: https://github.com/ChartinoLabs/towncrier-fragment-check
rev: v0.1.0
hooks:
- id: towncrier-fragment-check
stages: [pre-push]
Then run pre-commit install.
The check describes a whole branch, not one commit, so pre-push is the
recommended stage: it asks once, when the branch becomes visible to reviewers.
To run at the pre-commit stage instead, set stages: [pre-commit] and pass
args: [--staged] so fragments staged in the current commit count.
Monorepos
Each independently released package in a monorepo usually has its own towncrier
configuration, fragment directory, and changelog. Name each one with
--project DIR, or --project DIR:CONFIG when the configuration is not in
that directory's pyproject.toml or towncrier.toml:
- id: towncrier-fragment-check
stages: [pre-push]
args:
- --project
- packages/api
- --project
- apps/web:apps/web/towncrier.toml
By default a fragment in any one project passes, which suits a pull request that
changes only one package. Add --require all when every project must carry its
own.
Continuous integration
On a GitHub pull request the base branch comes from GITHUB_BASE_REF. Check out
the full history so the diff is available:
jobs:
check-changelog-fragment:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- run: uvx towncrier-fragment-check==0.1.0 --project packages/api --project apps/web
The package is on PyPI, so
pipx run and pip install work too. If pre-commit already runs in CI, reuse
the configured hook with
pre-commit run --hook-stage pre-push towncrier-fragment-check --all-files.
Options
| Option | Description |
|---|---|
--project DIR[:CONFIG] |
Towncrier project to check, relative to the git toplevel. Repeat once per project. Defaults to the repository root. |
--require {any,all} |
Pass rule across projects. Default any. |
--compare-with BRANCH |
Base ref to diff against. |
--staged |
Include staged files, for the pre-commit stage. |
--allow-empty |
Do not fail on empty or whitespace-only fragments. |
--skip-new-branch |
Exit 0 when PRE_COMMIT_FROM_REF is all zeros. |
--verbose, -v |
Always print towncrier's full output. |
--version |
Print the version and exit. |
Base branch resolution
The first candidate git can resolve wins:
--compare-withTOWNCRIER_COMPARE_WITHGITHUB_BASE_REF, prefixed withorigin/when it contains no/origin/mainorigin/master- towncrier's own default
Exit codes
| Code | Meaning |
|---|---|
0 |
Passed. |
1 |
No fragment, an empty fragment, or no resolvable base ref. |
2 |
Usage error. |
Development
uv sync --group dev
uv run pre-commit install
uv run pytest
License
Apache-2.0. See LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file towncrier_fragment_check-0.1.0.tar.gz.
File metadata
- Download URL: towncrier_fragment_check-0.1.0.tar.gz
- Upload date:
- Size: 81.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0f4d88ce1352d942a8d9e08863b9d5f5e9eb144d3a0e81f29ef2869bb759157
|
|
| MD5 |
71d87c54c61e33a86f330220b373efce
|
|
| BLAKE2b-256 |
c60f77644521fd5c702225c31b437e2511c9707192f34443afb29979ba64f031
|
Provenance
The following attestation bundles were made for towncrier_fragment_check-0.1.0.tar.gz:
Publisher:
release.yaml on ChartinoLabs/towncrier-fragment-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
towncrier_fragment_check-0.1.0.tar.gz -
Subject digest:
d0f4d88ce1352d942a8d9e08863b9d5f5e9eb144d3a0e81f29ef2869bb759157 - Sigstore transparency entry: 2682708579
- Sigstore integration time:
-
Permalink:
ChartinoLabs/towncrier-fragment-check@cb6e2b6164c0ba3b1a5d4bcc65fde48f13d7ae4f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChartinoLabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@cb6e2b6164c0ba3b1a5d4bcc65fde48f13d7ae4f -
Trigger Event:
push
-
Statement type:
File details
Details for the file towncrier_fragment_check-0.1.0-py3-none-any.whl.
File metadata
- Download URL: towncrier_fragment_check-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
875660654d7e548d4a42fe4aa276e54376824f6435197df88f073c4b82f8894c
|
|
| MD5 |
166ea502017ab2df40405fca57bcc4f9
|
|
| BLAKE2b-256 |
559fb067fe0092c399a31d42df85cead18fe7863e2cb0670478424913047c48b
|
Provenance
The following attestation bundles were made for towncrier_fragment_check-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on ChartinoLabs/towncrier-fragment-check
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
towncrier_fragment_check-0.1.0-py3-none-any.whl -
Subject digest:
875660654d7e548d4a42fe4aa276e54376824f6435197df88f073c4b82f8894c - Sigstore transparency entry: 2682708736
- Sigstore integration time:
-
Permalink:
ChartinoLabs/towncrier-fragment-check@cb6e2b6164c0ba3b1a5d4bcc65fde48f13d7ae4f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChartinoLabs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@cb6e2b6164c0ba3b1a5d4bcc65fde48f13d7ae4f -
Trigger Event:
push
-
Statement type: