Skip to content

Publish to PyPI with trusted publishing from GitHub Actions - #254

Open
rr3khan wants to merge 2 commits into
mainfrom
riyad/add-trusted-pypi-publishing-setup
Open

rr3khan wants to merge 2 commits into
mainfrom
riyad/add-trusted-pypi-publishing-setup

Conversation

@rr3khan

@rr3khan rr3khan commented Dec 3, 2026

Copy link
Copy Markdown

What changed

Adds a Publish to PyPI (trusted publishing) workflow (.github/workflows/publish-pypi.yml). It builds the wheels and sdist and publishes them to PyPI over OIDC, so releasing no longer needs a PyPI token on a maintainer's machine. It follows the same pattern as the JS SDK's npm trusted publishing workflow.

  • Trigger: manual (workflow_dispatch), with channel (beta / stable) and dry_run inputs. Dry run is on by default.
  • build job (read-only, no OIDC token):
    • Checks version.py against the channel, and against PyPI so an already-released version can't be republished.
    • Runs make build-wheels.
    • Checks that all 26 expected files exist, with the right platform tags, that each wheel contains its native library, and that twine check --strict passes. This matters because build-wheels.sh doesn't stop when a single build fails.
  • publish job: the only job with id-token: write. It runs in the pypi environment, so it waits for a reviewer's approval, then uploads the files the build job produced with attestations.
  • release job: after a real publish, creates the vX.Y.Z tag and the GitHub release, like the JS workflow.
  • PR check: pull requests that touch the build files run only the build job, as a check. They never reach publish.

Supporting changes:

  • build-wheels.sh: a USE_PYENV=false mode for CI that calls pythonX.Y directly. Local runs still use pyenv by default.
  • Makefile: a print-python-versions target, so CI and local releases build the same Python versions.
  • release.sh: a comment marking it as the fallback path. The local twine upload is kept as a backup until a CI release has gone through.
  • src/release/README.md: documents the new publish flow, the one-time setup, and the fallback.

Why

Python SDK releases are currently uploaded by hand from a laptop with a long-lived PyPI token. Trusted publishing replaces that token with short-lived credentials issued to this workflow, and puts every publish behind a reviewed GitHub environment.

Before the first real publish

These are one-time setup steps outside this PR:

  1. GitHub: create the pypi environment. Allow deployment from main, beta and release/* only. Require review from 1Password/open-source and turn on "Prevent self-review". No secrets are needed.
  2. PyPI: add a trusted publisher on the onepassword-sdk project (Manage → Publishing) with owner 1Password, repository onepassword-sdk-python, workflow publish-pypi.yml and environment pypi.

Merging this before step 2 is safe. Until the trusted publisher exists, a non-dry-run attempt fails at the OIDC exchange and nothing is uploaded.

Notes for reviewers

  • The workflow filename and the environment name are bound to the PyPI trusted publisher. Renaming either later breaks publishing.
  • Tags are now created by github-actions[bot] as lightweight tags pointing at the signed merge commit, the same as the JS SDK. release.sh used to create GPG-signed annotated tags.
  • workflow_dispatch only shows up once this is on main, so the first dry run happens after merge. Before that, this PR's own run of the build job covers the build on all five Python versions.
  • Tested locally: actionlint and shellcheck are clean. A CI-mode build with Python 3.11 and 3.12 produced correctly tagged wheels. The file and version checks also fail as expected on missing wheels, missing native libraries, a channel/version mismatch and an already-published version.

🤖 Generated with Claude Code

rr3khan and others added 2 commits December 3, 2026 16:26
Add a publish-pypi.yml workflow that builds the wheels and sdist and
publishes them to PyPI over OIDC, so releases no longer need a PyPI token
on a maintainer's machine. Publishing runs in the `pypi` environment, which
gates it behind a reviewer approval, and a dry run is the default.

The build job checks that every expected wheel exists with the right
platform tag and native library, since build-wheels.sh doesn't stop when a
single build fails. Pull requests that touch the build run that job as a
check.

build-wheels.sh gains a USE_PYENV=false mode so CI can call pythonX.Y
directly, and the Makefile exposes PYTHON_VERSIONS so CI and local releases
build the same versions. The local `make release` path stays as a fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ubuntu-latest now resolves to Ubuntu 26.04, which actions/setup-python
has no Python 3.9 build for, so the build job failed while installing
Python. Ubuntu 24.04 has builds for every version we ship wheels for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rr3khan
rr3khan requested a review from a team December 4, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant