Repository navigation
ci(publish): refuse a release tag whose version does not match the package - #15
Conversation
…ckage The publish workflow now runs a read-only verify-version job before the publish job. It fails the tag run unless vX.Y.Z matches the pyproject.toml [project] version, src/shieldcortex/_version.py __version__ and a "## X.Y.Z" CHANGELOG.md heading. The publish job needs it, so a mismatched tag builds and publishes nothing. The check is a stdlib-only script (scripts/check_release_version.py) with tests, including one that asserts the checked-out package is self-consistent, so a release PR that bumps only some of the version files fails ordinary CI before any tag is pushed. Refs #1
Review round 1 (independent) found three false acceptances: - a version line inside a TOML multi-line string stood in for [project] version: now tomllib on 3.11+ (workflow runs 3.12); the line reader on older Pythons refuses any triple-quoted string or duplicate key. - a docstring stood in for __version__: now ast, exactly one binding, a top-level string assignment; any other binding is refused. - "##\n0.5.0" passed as a heading: the version must sit on the heading line (horizontal whitespace only); a stray closing bracket no longer matches. Regression tests for each (red on the previous script, green here).
Review round 2 found two more false acceptances, both in reading code that tried to interpret more than it needed to: - the no-tomllib line reader split on Unicode line separators inside a TOML literal string. Removed: without tomllib (Python < 3.11) the guard now reads no version and refuses every tag. The publish workflow runs 3.12. - the AST binding count missed bindings held in string fields (match capture, except-as). Replaced with an allowlist: a version module may hold only a docstring and NAME = <constant> assignments, with __version__ assigned once to a string; anything else is refused. Regression tests for both (red on the previous script).
|
Relaying Veronica's independent static review at exact head Verdict: APPROVE. Static CI-correctness review only, NOT runtime release acceptance. Source evidence (separate detached checkout, clean status):
Consumers traced: workflow CLI invocation → main → check; both version readers and the CHANGELOG reader; package version re-export; Non-blocking PR-description correction: the body still says Python 3.9+ and quotes an earlier 12-test run. At this head a successful check needs Python 3.11+ (script :9–15, 26–29, 127–128); 3.9/3.10 deliberately refuse all tags and skip positive checks (tests :36–41, 123–133). Publish is pinned to 3.12, so the release path is unaffected. Please update the body rather than presenting the earlier count as her result. NOT RUN: guard script, tests, imports, installs, builds, release/publish steps, or runtime probes. No test count asserted, no live CI/release acceptance claimed. No blocking defect found in the requested static scope. |
Round-3 review found two false acceptances. A module-level annotation is evaluated when the module runs and can rebind __version__ (B6), so annotated assignments are no longer accepted at all. The module was decoded as UTF-8 text while Python honours a coding declaration (B7), so it is now parsed from its bytes with Python's own source decoding. Tests pin both on module_version() and check(); 10 of them fail on the previous script.
|
Independent review, round 4, at head Two lanes from different model families, both read-only:
GitHub checks pass on this head (Python 3.9 to 3.13). Merging through the loop gate with the head pinned. |
What
Residual from #1: tags
v0.1.1/v0.3.0were never pushed while their versions shipped, and nothing stops a futurev*tag from disagreeing with the package it publishes.verify-versionjob inpublish.yml, ahead ofpublish(needs: verify-version). It haspermissions: contents: read, checks out withpersist-credentials: false, uses no secrets and runspython scripts/check_release_version.py "$RELEASE_TAG"(tag passed throughenv, not interpolated into the script).vX.Y.Zequals thepyproject.toml[project]version,shieldcortex._version.__version__and a## X.Y.Z(or## [X.Y.Z]) heading inCHANGELOG.md. Standard library only, Python 3.9+.tests/test_release_version_check.py: match, each single mismatch, aversionkey in another TOML table ignored, malformed tags, bracketed heading, and the checked-out repository being self-consistent (so a partial bump fails ordinary CI before a tag exists).[Unreleased]entry.The
publishjob itself is unchanged (same environment,id-token: write, build and trusted-publishing steps). No tag is pushed by this PR.Verification
python3 scripts/check_release_version.py v0.5.0→ exit 0;v0.5.1→ exit 1 with three named mismatches.pytest -q tests/test_release_version_check.py→ 12 passed.test_pyproject_mismatch_failsfail (1 failed, 11 passed); restored → 12 passed.Testsworkflow on this PR.Refs #1