Skip to content

IT-6150: switch PyPI publishing to trusted publishing (OIDC) - #375

Merged
mdickinson merged 3 commits into
mainfrom
it-6150-trusted-publishing
Jul 27, 2026
Merged

IT-6150: switch PyPI publishing to trusted publishing (OIDC)#375
mdickinson merged 3 commits into
mainfrom
it-6150-trusted-publishing

Conversation

@jychuah

@jychuah jychuah commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Part of IT-6150 — move PyPI release uploads to GitHub Actions OIDC trusted publishing, removing the long-lived PYPI_USERNAME / PYPI_PASSWORD token from repo secrets.

What changed (.github/workflows/publish-on-pypi.yml)

  • Added permissions: id-token: write (required for OIDC).
  • Added environment: pypi (must match the Environment field in the PyPI trusted-publisher config).
  • Replaced the twine upload step — which used secrets.PYPI_USERNAME / secrets.PYPI_PASSWORD — with pypa/gh-action-pypi-publish (pinned to v1.14.1).
  • Kept twine check --strict as its own step.

⚠️ DO NOT MERGE YET — ordering matters

This workflow only authenticates after a trusted publisher is configured on the PyPI project. Because this PR removes the token auth, merging it before PyPI is configured will break the next release.

Required order:

  1. IT configures the trusted publisher on PyPI: owner enthought, this repository, workflow filename publish-on-pypi.yml, environment pypi.
  2. Cut a validation release / re-run the workflow and confirm the OIDC upload succeeds.
  3. Then merge this PR.

Kept as a draft until step 1 is done. /cc @mdickinson

Replace token-based twine upload with pypa/gh-action-pypi-publish using
GitHub Actions OIDC. Adds id-token: write permission and the pypi
environment; removes the PYPI_USERNAME/PYPI_PASSWORD secrets usage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jychuah
jychuah requested a review from mdickinson July 24, 2026 16:02
@mdickinson

Copy link
Copy Markdown
Member

Workflow change looks fine to me. Has the trusted publishing already been set up on the PyPI side?

@mdickinson

Copy link
Copy Markdown
Member

I've set up trusted publishing on the PyPI side, and added the appropriate environment here.

Test run: https://github.com/enthought/apptools/actions/runs/30286226427

That test run should fail as a result of the release already existing, but every step up to that should pass.

@mdickinson
mdickinson marked this pull request as ready for review July 27, 2026 16:51
@mdickinson

Copy link
Copy Markdown
Member

That test run should fail as a result of the release already existing, but every step up to that should pass.

Verified: the test run failed with:

400 File already exists ('apptools-5.3.1-py3-none-any.whl',   
         with blake2_256 hash                                                   
         'bcdb3318162c4e74deeaa3c23564104f8c46fcbedf600190fd40bcf1f8b73b7c'

And it's clear from the log that pypa/gh-action-pypi-publish is being used, so I definitely tested with the version of the workflow from this branch, not from main.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the PyPI publishing workflow to use GitHub Actions OIDC “trusted publishing” instead of long-lived PyPI credentials, aligning releases with modern tokenless authentication.

Changes:

  • Add job environment: pypi and request id-token: write for OIDC.
  • Replace twine upload (username/password secrets) with pypa/gh-action-pypi-publish pinned to a commit.
  • Keep twine check --strict as a separate validation step.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/publish-on-pypi.yml
We need "contents: read" for the checkout action to succeed. It works implicitly at the moment because the repo is public, but both Claude and Copilot recommended making it explicit.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mdickinson

Copy link
Copy Markdown
Member

Merging. Thanks, @jychuah!

@mdickinson
mdickinson merged commit 756d18b into main Jul 27, 2026
25 of 26 checks passed
@mdickinson
mdickinson deleted the it-6150-trusted-publishing branch July 27, 2026 17:55
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.

3 participants