Skip to content

Commit f3f9853

Browse files
leliaclaude
andcommitted
ci: floor the version check at the published release, not main
Ports the socket-python-cli fix. Three changes to the same job: Floor on PyPI, not main. The check required the PR version to exceed both main and PyPI. The main term forbids the legitimate case where several PRs ship under one unreleased version: the first bumps main and the rest ride it without bumping again, which is what keeps them under a single changelog header. Main is still a floor in the direction that matters -- a PR may leave the version alone or move it forwards, never back. Forgetting to bump, reusing a published version, and branching from a stale base all still fail. Stop checking out main to read its version. `git checkout origin/main` left the working tree detached on main, so the "Require uv.lock update when pyproject changes" step below it diffed main against itself and never fired. Reading the version out of the ref with `git show` removes the side effect and revives that guard. Only enforce a bump when the PR changes shipped content. This workflow is now in its own paths filter so an edit to the check is exercised by the PR making it, but a CI-only change ships nothing and must not be told to cut a release. The comparison still runs and reports either way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 57d1bc5 commit f3f9853

1 file changed

Lines changed: 57 additions & 13 deletions

File tree

.github/workflows/version-check.yml

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- 'socketdev/**'
77
- 'pyproject.toml'
88
- 'uv.lock'
9+
# Included so a change to the check itself is exercised by its own PR.
10+
- '.github/workflows/version-check.yml'
911

1012
permissions:
1113
contents: read
@@ -32,15 +34,29 @@ jobs:
3234
PR_VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | tr -d '"' | tr -d "'")
3335
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV
3436
35-
# Get version from main branch
36-
git checkout origin/main
37-
MAIN_VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | tr -d '"' | tr -d "'")
37+
# Get version from main branch. Read it straight out of the ref:
38+
# `git checkout origin/main` leaves the working tree detached on main,
39+
# so the uv.lock guard below ends up diffing main against itself and
40+
# never fires.
41+
MAIN_VERSION=$(git show origin/main:socketdev/version.py | grep -o "__version__.*" | awk '{print $3}' | tr -d '"' | tr -d "'")
3842
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
3943
4044
export PR_VERSION
4145
export MAIN_VERSION
4246
43-
# Compare against both main and latest published PyPI release.
47+
# Only enforce a bump when the PR actually changes shipped content.
48+
# This workflow sits in its own paths filter so edits to it are
49+
# exercised, but a CI-only change ships nothing and must not be told
50+
# to cut a release. The comparison still runs and reports either way.
51+
if git diff --name-only origin/main...HEAD \
52+
| grep -qE '^(socketdev/|pyproject\.toml$|uv\.lock$)'; then
53+
PACKAGE_CHANGED=true
54+
else
55+
PACKAGE_CHANGED=false
56+
fi
57+
export PACKAGE_CHANGED
58+
59+
# Compare against the latest published PyPI release.
4460
python3 <<'PY'
4561
import json
4662
import os
@@ -60,19 +76,47 @@ jobs:
6076
published_versions.append(parsed)
6177
6278
pypi_ver = max(published_versions) if published_versions else version.parse("0.0.0")
63-
required_floor = max(main_ver, pypi_ver)
6479
65-
if pr_ver <= required_floor:
80+
enforced = os.environ["PACKAGE_CHANGED"] == "true"
81+
82+
def reject(message):
83+
print(message)
84+
if enforced:
85+
raise SystemExit(1)
6686
print(
67-
f"❌ Version must be greater than main and PyPI! "
68-
f"Main: {main_ver}, PyPI: {pypi_ver}, PR: {pr_ver}"
87+
"ℹ️ Not enforced: this PR changes no packaged files, "
88+
"so it ships nothing that needs a new version."
89+
)
90+
raise SystemExit(0)
91+
92+
# The only hard requirement is that the version is ahead of what is
93+
# actually released. Treating main's version as a second floor breaks
94+
# the legitimate case where several PRs share one unreleased release:
95+
# the first bumps main to the new version and the rest ride it without
96+
# bumping again, which is what keeps them under a single changelog
97+
# header. Main is therefore only a floor when this PR moves the
98+
# version -- a change to it must go forwards, never backwards.
99+
if pr_ver <= pypi_ver:
100+
reject(
101+
f"❌ Version {pr_ver} is already published on PyPI "
102+
f"(latest release: {pypi_ver}). Bump it."
103+
)
104+
105+
if pr_ver < main_ver:
106+
reject(
107+
f"❌ Version moves backwards: main is {main_ver}, PR is {pr_ver}."
69108
)
70-
raise SystemExit(1)
71109
72-
print(
73-
f"✅ Version properly incremented. "
74-
f"Main: {main_ver}, PyPI: {pypi_ver}, PR: {pr_ver}"
75-
)
110+
if pr_ver == main_ver:
111+
print(
112+
f"✅ Riding main's unreleased {pr_ver} "
113+
f"(latest PyPI release: {pypi_ver})."
114+
)
115+
else:
116+
print(
117+
f"✅ Version properly incremented. "
118+
f"Main: {main_ver}, PyPI: {pypi_ver}, PR: {pr_ver}"
119+
)
76120
PY
77121
78122
- name: Require uv.lock update when pyproject changes

0 commit comments

Comments
 (0)