Skip to content

Commit a2da12a

Browse files
committed
ci: fold PyPI publish into the auto-release job
The previous setup had a separate `deploy` job gated on `github.event_name == 'release'`, relying on the release.published event to fire downstream. That stopped firing between v0.1.7 and v0.1.10 — three GitHub Releases were created (v0.1.8, v0.1.9, v0.1.10) but none triggered the deploy, so PyPI fell three versions behind the git tags. Manual upload was needed to recover. Causes (any of): - GH_PAT expired or scope changed; action-gh-release silently fell back to GITHUB_TOKEN, and releases created via GITHUB_TOKEN never trigger downstream workflows by design. - Repository owners can't grant a Release-creation event from a workflow without specifically attaching a PAT. Fix: build + publish in the same job, right after the version bump and Release creation. No more event indirection. Also adds a workflow_dispatch-only `republish` job (skip-existing=true) for re-running the upload manually if a future release is half-broken.
1 parent 225213d commit a2da12a

1 file changed

Lines changed: 38 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,53 @@ jobs:
9090
env:
9191
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
9292

93+
# ─────────────────────────────────────────────────────────
94+
# Build + publish to PyPI in the same job — relying on the
95+
# release.published event to fire downstream is unreliable
96+
# when the Release is created by an action (a previous setup
97+
# broke quietly between v0.1.7 and v0.1.10, leaving PyPI
98+
# behind the git tags by three versions).
99+
# ─────────────────────────────────────────────────────────
100+
101+
- name: Set up Python (publish)
102+
uses: actions/setup-python@v5.6.0
103+
with: { python-version: '3.x' }
104+
105+
- name: Install build deps
106+
run: |
107+
python -m pip install --upgrade pip
108+
pip install build twine
109+
110+
- name: Build wheel & sdist
111+
run: |
112+
# Make sure we build from the freshly bumped checkout —
113+
# the VERSION write happened earlier in this job.
114+
python -m build
115+
116+
- name: Publish to PyPI
117+
uses: pypa/gh-action-pypi-publish@release/v1
118+
with:
119+
user: __token__
120+
password: ${{ secrets.PYPI_API_TOKEN }}
121+
93122
# ────────────────────────────────────────
94-
# 2. Job B: build & publish when Release fires
123+
# 2. Manual republish-only path (workflow_dispatch)
124+
# Useful when PyPI is behind the git tag and you want to
125+
# reprocess the latest tag without bumping again.
95126
# ────────────────────────────────────────
96-
deploy:
97-
if: github.event_name == 'release'
127+
republish:
128+
if: github.event_name == 'workflow_dispatch'
98129
runs-on: ubuntu-latest
99130
environment: pypi
100-
101131
steps:
102-
- uses: actions/checkout@v4.2.2 # exact tagged commit
132+
- uses: actions/checkout@v4.2.2
103133

104134
- name: Set up Python
105135
uses: actions/setup-python@v5.6.0
106-
with:
107-
python-version: '3.x'
136+
with: { python-version: '3.x' }
108137

109138
- name: Install build deps
110-
run: |
111-
python -m pip install --upgrade pip
112-
pip install build twine
139+
run: pip install build twine
113140

114141
- name: Build wheel & sdist
115142
run: python -m build
@@ -119,3 +146,4 @@ jobs:
119146
with:
120147
user: __token__
121148
password: ${{ secrets.PYPI_API_TOKEN }}
149+
skip-existing: true

0 commit comments

Comments
 (0)