Skip to content

feat(action): support PyPI Trusted Publishing via OIDC#116

Merged
brendanjryan merged 2 commits intotempoxyz:masterfrom
brendanjryan:brendan/pypi-oidc-trusted-publishing
May 2, 2026
Merged

feat(action): support PyPI Trusted Publishing via OIDC#116
brendanjryan merged 2 commits intotempoxyz:masterfrom
brendanjryan:brendan/pypi-oidc-trusted-publishing

Conversation

@brendanjryan
Copy link
Copy Markdown
Contributor

@brendanjryan brendanjryan commented May 2, 2026

What

Adds support for PyPI Trusted Publishing (OIDC) to the action's Python publish flow.

When pypi-token is empty and the workflow has permissions: id-token: write, the action mints a short-lived PyPI API token by exchanging the GitHub OIDC ID token at PyPI's _/oidc/mint-token endpoint, and uses it as TWINE_PASSWORD for the existing publish step.

When publishing a Python package, mint a short-lived PyPI API token by
exchanging the GitHub Actions OIDC ID token at PyPI's
`_/oidc/mint-token` endpoint, when:

- `pypi-token` input is empty
- the workflow has `permissions: id-token: write`

This lets users publish to PyPI without storing a long-lived static API
token, by registering a Trusted Publisher on the PyPI project that
matches their workflow.

Behavior is fully backwards-compatible: if `pypi-token` is provided,
it is used as before; if neither is configured, the publish falls
through to its existing 'no token' handling.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 092485cba8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread action.yml Outdated
Comment on lines +222 to +224
if: |
steps.check.outputs.hasChangelogs == 'false' &&
(inputs.ecosystem == 'python' || inputs.pypi-token != '')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enable OIDC auth when ecosystem is auto-detected

The new Configure PyPI auth guard only runs when inputs.ecosystem == 'python' or inputs.pypi-token is non-empty, so a Python repo that relies on auto-detection (documented default) and uses Trusted Publishing (pypi-token unset, id-token: write) will skip this step entirely. In that common path TWINE_PASSWORD is never set, so publish falls back to the existing “no token” behavior instead of minting a PyPI token, which breaks the new feature unless users explicitly set ecosystem: python.

Useful? React with 👍 / 👎.

The `Configure PyPI auth` and Python setup steps were guarded on
`inputs.ecosystem == 'python' || inputs.pypi-token != ''`. A Python
repo relying on the documented auto-detection (no explicit
`ecosystem`) and using Trusted Publishing (no `pypi-token`,
`id-token: write` granted) skipped these steps entirely, so
`TWINE_PASSWORD` was never minted and twine was never installed.

- Drop the gate on `Configure PyPI auth` entirely. It runs on the
  publish path; setting `TWINE_PASSWORD` is a no-op for non-Python
  publishes.
- Extend the Python setup/build-tools steps to also run when
  `env.ACTIONS_ID_TOKEN_REQUEST_TOKEN` is present (OIDC available).
@brendanjryan brendanjryan merged commit de02501 into tempoxyz:master May 2, 2026
6 checks passed
brendanjryan added a commit to tempoxyz/pympp that referenced this pull request May 2, 2026
wevm/changelogs now natively supports PyPI Trusted Publishing (OIDC)
as of tempoxyz/changelogs#116. When pypi-token is empty and the
workflow has id-token: write, it mints a short-lived PyPI API token
by exchanging the GitHub OIDC ID token at PyPI's _/oidc/mint-token
endpoint, removing the need for a long-lived static API token.

Pin to the merge commit (de02501) until a new changelogs release is
cut, and grant id-token: write + environment: release to the release
job so the OIDC mint flow runs and matches the registered Trusted
Publisher (tempoxyz/pympp + publish.yml + release).
@github-actions github-actions Bot mentioned this pull request May 2, 2026
brendanjryan added a commit to tempoxyz/pympp that referenced this pull request May 2, 2026
wevm/changelogs now natively supports PyPI Trusted Publishing (OIDC)
as of tempoxyz/changelogs#116. When pypi-token is empty and the
workflow has id-token: write, it mints a short-lived PyPI API token
by exchanging the GitHub OIDC ID token at PyPI's _/oidc/mint-token
endpoint, removing the need for a long-lived static API token.

Pin to the merge commit (de02501) until a new changelogs release is
cut, and grant id-token: write + environment: release to the release
job so the OIDC mint flow runs and matches the registered Trusted
Publisher (tempoxyz/pympp + publish.yml + release).
brendanjryan added a commit to tempoxyz/pytempo that referenced this pull request May 2, 2026
Releases since v0.5.0 have failed with 403 Forbidden because
wevm/changelogs ran twine upload with no token (no pypi-token input
was provided), and the separate publish job using
pypa/gh-action-pypi-publish never ran since the release job errored
first.

wevm/changelogs now natively supports PyPI Trusted Publishing (OIDC)
as of tempoxyz/changelogs#116. When pypi-token is empty and the
workflow has id-token: write, it mints a short-lived PyPI API token
by exchanging the GitHub OIDC ID token at PyPI's _/oidc/mint-token
endpoint.

Collapse the two-job workflow into a single release job that:
- pins to the changelogs commit with OIDC support (de02501)
- grants id-token: write + environment: pypi so the OIDC mint flow
  matches the registered Trusted Publisher entry on PyPI.
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