Skip to content

🐛 fix(release): detect pre-commit environment inconsistencies#1001

Merged
gaborbernat merged 2 commits intopypa:mainfrom
gaborbernat:fix-release-precommit-check
Mar 24, 2026
Merged

🐛 fix(release): detect pre-commit environment inconsistencies#1001
gaborbernat merged 2 commits intopypa:mainfrom
gaborbernat:fix-release-precommit-check

Conversation

@gaborbernat
Copy link
Copy Markdown
Collaborator

@gaborbernat gaborbernat commented Mar 24, 2026

The release commit bd88956 passed local pre-commit checks but failed pre-commit.ci because docstrfmt formatted CHANGELOG.rst differently in the tox release environment versus the CI environment. 🔧 This happened because towncrier generated RST with one header style (asterisks for versions, equals for sections) but docstrfmt expects a different style (hash symbols for versions, asterisks with overlines for sections).

The fix has three parts:

  1. Detect environment inconsistencies: Added --show-diff-on-failure to the final pre-commit run and check for unstaged changes afterward. If pre-commit modifies files after the final run, the script fails with a clear error instead of creating a commit that will fail CI.

  2. Fix existing CHANGELOG formatting: Applied docstrfmt formatting to the existing CHANGELOG.rst to match expected output.

  3. Fix towncrier template: Configure towncrier to generate CHANGELOG entries matching docstrfmt expectations by setting top_underline = "#" and updating the template to add overlines above section headers.

This ensures the release script will fail early if environment mismatches occur, and fixes the root cause by aligning towncrier output with docstrfmt requirements.

@gaborbernat gaborbernat added the bug Something isn't working label Mar 24, 2026
@gaborbernat gaborbernat requested a review from henryiii as a code owner March 24, 2026 23:17
The release commit bd88956 passed local pre-commit checks but failed
pre-commit.ci because docstrfmt formatted CHANGELOG.rst differently in
the tox release environment versus the CI environment. This happens when
pre-commit hooks make changes after the final check_call run but before
the commit, leaving unstaged changes that get caught by pre-commit.ci.

Added --show-diff-on-failure to the final pre-commit run to display what
changed if hooks fail. After the final run, verify the repository has no
unstaged changes. If it does, fail with a clear error about environment
inconsistency rather than creating a release commit that will fail CI.
Pre-commit.ci detected that CHANGELOG.rst was not formatted according to
the docstrfmt hook configuration. The section headers use a different
underline style than what docstrfmt expects.

Reformatted the changelog to match the expected docstrfmt output to
ensure pre-commit.ci checks pass on this PR.
@gaborbernat gaborbernat force-pushed the fix-release-precommit-check branch from 43ff4f7 to 6ad6ae8 Compare March 24, 2026 23:20
@gaborbernat gaborbernat enabled auto-merge (squash) March 24, 2026 23:21
@gaborbernat gaborbernat merged commit 3786929 into pypa:main Mar 24, 2026
10 checks passed
@gaborbernat gaborbernat deleted the fix-release-precommit-check branch March 24, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants