Skip to content

Commit b53ff30

Browse files
committed
fix: version from PyPI query instead of run_number
CI queries PyPI JSON API for latest published version, bumps patch +1. If VERSION base changes (manual bump), starts at .0. No repo writes, no merge conflicts.
1 parent 522b46d commit b53ff30

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

.github/workflows/publish-dev.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,21 @@ jobs:
137137
with:
138138
python-version: '3.12'
139139

140-
- name: Compute version
140+
- name: Compute version from PyPI
141141
id: version
142142
run: |
143143
base=$(cat VERSION | tr -d '[:space:]')
144-
version="${base}.${{ github.run_number }}"
144+
pkg="drp-cli"
145+
latest=$(curl -sf "https://pypi.org/pypi/${pkg}/json" \
146+
| python3 -c "import sys,json; print(json.load(sys.stdin)['info']['version'])" 2>/dev/null || echo "")
147+
if [ -n "$latest" ] && echo "$latest" | grep -q "^${base}\."; then
148+
patch=$(echo "$latest" | cut -d. -f3)
149+
version="${base}.$((patch + 1))"
150+
else
151+
version="${base}.0"
152+
fi
145153
echo "version=$version" >> "$GITHUB_OUTPUT"
146-
echo "Publishing drp-cli $version"
154+
echo "Publishing ${pkg} ${version} (latest on PyPI: ${latest:-none})"
147155
148156
- name: Stamp version into CLI
149157
run: |

.github/workflows/publish.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,21 @@ jobs:
169169
with:
170170
python-version: '3.12'
171171

172-
- name: Compute version
172+
- name: Compute version from PyPI
173173
id: version
174174
run: |
175175
base=$(cat VERSION | tr -d '[:space:]')
176-
version="${base}.${{ github.run_number }}"
176+
pkg="drp"
177+
latest=$(curl -sf "https://pypi.org/pypi/${pkg}/json" \
178+
| python3 -c "import sys,json; print(json.load(sys.stdin)['info']['version'])" 2>/dev/null || echo "")
179+
if [ -n "$latest" ] && echo "$latest" | grep -q "^${base}\."; then
180+
patch=$(echo "$latest" | cut -d. -f3)
181+
version="${base}.$((patch + 1))"
182+
else
183+
version="${base}.0"
184+
fi
177185
echo "version=$version" >> "$GITHUB_OUTPUT"
178-
echo "Publishing drp $version"
186+
echo "Publishing ${pkg} ${version} (latest on PyPI: ${latest:-none})"
179187
180188
- name: Collect commits since last release
181189
run: |

cli/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""drp CLI — command-line tool for drp."""
22

33
# VERSION file holds major.minor (e.g. "0.3") — only bumped manually.
4-
# CI computes full version (major.minor.run_number) and seds this line
5-
# to a literal before building: __version__ = '0.3.42'
6-
# Never auto-committed, so merges between dev↔main stay clean.
4+
# CI queries PyPI for latest published version, bumps patch +1,
5+
# and seds this line to a literal before building: __version__ = '0.3.42'
6+
# Nothing committed back — merges between dev↔main stay clean.
77
# Fallback: importlib.metadata for installed packages.
88

99
def _resolve_version():

tests/unit/test_cli_pure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def test_version_is_semver(self):
550550
from cli import __version__
551551
parts = __version__.split('.')
552552
# Locally: "0.3" (major.minor from VERSION file)
553-
# CI/installed: "0.3.42" (major.minor.run_number)
553+
# CI/installed: "0.3.42" (major.minor.patch from PyPI bump)
554554
assert len(parts) >= 2
555555
for part in parts:
556556
assert part.isdigit()

0 commit comments

Comments
 (0)