Skip to content

Commit a407801

Browse files
authored
fix(publish): unblock 0.21.0 PyPI release; make publishes idempotent (#38)
Two issues kept past releases (and 0.21.0) from auto-publishing PyPI: 1. clients/python/src/tangle_agent_eval/__init__.py carried a hardcoded `__version__` fallback that drifts every release. The verify step in publish.yml compares it against package.json and exits with "Version mismatch: npm=X python_runtime=Y" before either publish runs. 2. publish-pypi declared `needs: [verify, publish-npm]`. After a tag re-fire (manual publish, workflow re-run, or a fresh tag on the same commit), publish-npm trips over "version already on registry" and blocks PyPI. Coupling these stages was the wrong primitive — PyPI is not downstream of npm; they're parallel artifacts of the same release. Fix: - Bump the Python runtime fallback to 0.21.0. Pre-commit, this matched pyproject.toml; releasing requires bumping it too. (A future cleanup is to derive __version__ from pyproject.toml at build time so the drift can't happen — out of scope here.) - publish-npm now skips with a log message when the version is already on the registry, instead of failing. - publish-pypi gates on `verify` only, and pre-checks PyPI for the version before invoking the trusted-publish action — idempotent on re-fires. After this lands, deleting + force-re-pushing v0.21.0 will fire the workflow and publish the PyPI sdist + wheel that 0.21.0 needs to match the already-published @tangle-network/agent-eval@0.21.0 on npm.
1 parent a74b419 commit a407801

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

.github/workflows/publish.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,27 @@ jobs:
100100

101101
- run: pnpm install --frozen-lockfile
102102
- run: pnpm build
103-
- run: pnpm publish --no-git-checks --access public
103+
104+
# Idempotent: re-running a tag whose npm version is already published
105+
# (e.g. after a manual `pnpm publish` plus a workflow rerun) must not
106+
# block the downstream PyPI step.
107+
- name: Publish to npm (skip if already published)
108+
run: |
109+
NAME=$(node -p "require('./package.json').name")
110+
VERSION=$(node -p "require('./package.json').version")
111+
if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
112+
echo "$NAME@$VERSION already on registry; skipping publish"
113+
else
114+
pnpm publish --no-git-checks --access public
115+
fi
104116
env:
105117
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
106118

107119
publish-pypi:
108-
needs: [verify, publish-npm]
120+
# PyPI publish is independent of npm — both gate on `verify` so a version
121+
# mismatch blocks both, but a re-run after a successful npm publish must
122+
# still be able to push the matching PyPI artifact.
123+
needs: verify
109124
if: startsWith(github.ref, 'refs/tags/v')
110125
runs-on: ubuntu-latest
111126
permissions:
@@ -125,7 +140,19 @@ jobs:
125140
working-directory: clients/python
126141
run: python -m build
127142

143+
- name: Check whether this version is already on PyPI
144+
id: pypi-check
145+
run: |
146+
VERSION=$(grep -E '^version' clients/python/pyproject.toml | head -1 | sed -E 's/.*"([^"]+)".*/\1/')
147+
if curl -sf "https://pypi.org/pypi/tangle-agent-eval/$VERSION/json" >/dev/null; then
148+
echo "tangle-agent-eval==$VERSION already on PyPI; skipping publish"
149+
echo "skip=true" >> "$GITHUB_OUTPUT"
150+
else
151+
echo "skip=false" >> "$GITHUB_OUTPUT"
152+
fi
153+
128154
- name: Publish to PyPI (trusted publishing)
155+
if: steps.pypi-check.outputs.skip != 'true'
129156
uses: pypa/gh-action-pypi-publish@release/v1
130157
with:
131158
packages-dir: clients/python/dist

clients/python/src/tangle_agent_eval/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
try:
4545
__version__ = version("tangle-agent-eval")
4646
except PackageNotFoundError:
47-
__version__ = "0.20.10"
47+
__version__ = "0.21.0"
4848

4949
__all__ = [
5050
"Client",

0 commit comments

Comments
 (0)