Repository navigation
ci: publish to PyPI with Trusted Publishing from master - #249
Merged
Merged
Conversation
The release job exchanges its OIDC token for a short-lived PyPI token instead of uploading with the long-lived PYPI_TOKEN secret.
mogita
commented
Nov 17, 2026
Building runs in its own job, so only the publish job can mint a PyPI token. Releasing on push to master lets the pypi environment allow master only, which a branch run cannot reach.
A release whose GitHub release step failed can then be finished by rerunning the workflow, instead of failing on the duplicate upload until the tag is created by hand.
The tag marks the version as released, so a later push to master skips it instead of rebuilding different code under the same version. A failed upload is finished by rerunning the publish job, which reuses the built files.
Checking PyPI instead of the tag lets a full rerun or a later push finish a release whose upload failed. Once the version is tagged, the tagged commit is rebuilt and the existing GitHub release is kept, so the uploaded files always match the tag.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b5e9354. Configure here.
A release counts as done only when PyPI has the sdist and the wheel, so a partial upload is finished by the next run. Serializing the runs keeps overlapping pushes from building the same version from different commits.
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Submit a pull request
CLA
Description of the pull request
The release job uploads to PyPI with the long-lived
PYPI_TOKENsecret, which may have been exposed in the GitHub Actions secret incident. This switches the upload to PyPI Trusted Publishing: the publish job exchanges its OIDC token for a short-lived PyPI token, so the repo no longer needs a PyPI secret.masterinstead of on the closed release PR. Acheckjob releases while PyPI lacks the sdist or the wheel of__version__fromstream_chat/__pkg__.py, which is the case right after a release PR is squash-merged. Any other push to master skips the release. Once the version is tagged, the tagged commit is rebuilt, so a rerun or a later push finishes a failed upload with the same code. Release runs are serialized, so overlapping pushes cannot build the same version twice.buildruns checkout, the changelog script andsetup.pywithcontents: readand uploadsdist/.releasecreates the tag and GitHub release on the released commit withcontents: write, before the upload, and keeps them on a rerun.publishis the only job withid-token: write. It downloadsdist/and runspypa/gh-action-pypi-publishv1.14.3, both pinned to a commit, in thepypienvironment. That environment allowsmasteronly, and the PyPI trusted publisher forstream-chatrequires it, so a branch with an editedrelease.ymlcannot publish.How to verify: the merge of this PR runs
checkwithrelease=false(4.34.1 is on PyPI) and skips the rest. The next release PR merge publishes to PyPI withoutPYPI_TOKEN, and its publish step logs a successful token exchange. After that, thePYPI_TOKENsecret and its PyPI token are removed.Note
Medium Risk
It is the sole release path to PyPI and GitHub; new version detection and job gating could skip or delay a release if misconfigured, but runtime app code is unchanged.
Overview
Replaces the release-on-merged-
release-*PR flow with apushtomasterpipeline that only ships whenstream_chat/__pkg__.py’s__version__is missing sdist or wheel on PyPI.The workflow is split into
check→build→release→publish, with per-job permissions, a release concurrency group, and artifact handoff instead of building and uploading in one job. Version/ref come from the package file (and an existing tag when re-running), not the PR branch name.PyPI upload drops
PYPI_TOKEN/ twine in favor of Trusted Publishing (pypienvironment, OIDC inpublishonly). GitHub releases are created before upload, withskipIfReleaseExistsandskip-existingon publish for safe reruns.Reviewed by Cursor Bugbot for commit 1b13dff. Bugbot is set up for automated code reviews on this repo. Configure here.