Skip to content

Commit b8bead8

Browse files
ci: pin the README to the release being published
README.md is the long description PyPI shows, so its pre-commit `rev:` is fixed when the wheel is built. Until now that depended on a hand bump merging to main after the version was known and before the release was published; 11 of the 24 releases since #546 missed that window. The publish job now writes the release's tag into every `rev:` in the README before it builds, and gives setuptools-scm the tag's version so the edited tree does not build as X.Y.Z.post1.dev0. The step fails if the README has no pin to update. The workflow_dispatch dry run has no tag and skips it. AGENTS.md drops the exception for pinning ahead of the tag and the check after publishing: the README on main is bumped once the release exists, so it never names a tag pre-commit cannot resolve. Closes #722
1 parent 029bf06 commit b8bead8

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ jobs:
2929
with:
3030
python-version: '3.x'
3131

32+
# README.md is the long description PyPI shows, so its pre-commit `rev:`
33+
# is fixed at build time. Write this release's tag into it here, rather
34+
# than relying on a README bump landing on main before the release is
35+
# published. The workflow_dispatch dry run has no tag and skips this.
36+
- name: Pin the README to this release
37+
if: github.event_name == 'release'
38+
env:
39+
TAG: ${{ github.event.release.tag_name }}
40+
run: |
41+
python - <<'PY'
42+
import os, pathlib, re, sys
43+
p = pathlib.Path("README.md")
44+
text, n = re.subn(r"(rev:\s*)v\d+\.\d+\.\d+", rf"\g<1>{os.environ['TAG']}", p.read_text())
45+
if n == 0:
46+
sys.exit("README.md has no `rev: vX.Y.Z` pin to update")
47+
p.write_text(text)
48+
PY
49+
grep -n "rev: v" README.md
50+
# The edit makes the tree dirty, and setuptools-scm would then build
51+
# X.Y.Z.post1.dev0 instead of X.Y.Z. Give it the tag's version.
52+
echo "SETUPTOOLS_SCM_PRETEND_VERSION_FOR_COMMIT_CHECK=${TAG#v}" >> "$GITHUB_ENV"
53+
3254
- name: Build wheel
3355
run: |
3456
# Install dependencies

‎AGENTS.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ and a stale pin is invisible: the snippet keeps working, it just installs an old
3434

3535
3. **Say so in the pull request description** when you moved them, so the bump is not a silent diff in an unrelated change.
3636

37-
The one exception is a pull request that prepares an unpublished release: there the pins are written **ahead** of the tag, on purpose,
38-
and the pull request merges **before** the release is published. `pyproject.toml` sets `readme = "README.md"`, so this file is the long description PyPI shows,
39-
and the publish workflow builds from whatever `main` holds at that moment. A README bumped after the release ships the old pin to PyPI, where it cannot be corrected
40-
without another release. Check it afterwards: `rev:` on the release's PyPI page must name that release.
37+
Do not pin **ahead** of a release. Until the tag exists, pre-commit cannot resolve the pin, so a README that names an unpublished version
38+
gives anyone who copies the snippet an error. Bump it once the release is published.
4139

42-
`.pre-commit-config.yaml` is a different case and is **not** covered by this rule. That pin is this repository running its own hooks,
40+
What PyPI shows does not depend on that bump. `pyproject.toml` sets `readme = "README.md"`, so this file is the long description on PyPI,
41+
and the publish workflow (`.github/workflows/publish.yml`) writes the release's tag into every `rev:` before it builds. A late bump only leaves
42+
the README on GitHub one release behind until it lands.
43+
44+
`.pre-commit-config.yaml` is **not** covered by this rule. That pin is this repository running its own hooks,
4345
and pre-commit resolves it against real tags when CI runs — so pointing it at a version that is not published yet breaks the build. Bump it only after the release exists.
4446

4547
## Git Rules

0 commit comments

Comments
 (0)