Skip to content

ci: add PyPI Trusted Publishing workflow#7

Open
MHoroszowski wants to merge 1 commit intomasterfrom
ci/pypi-trusted-publishing
Open

ci: add PyPI Trusted Publishing workflow#7
MHoroszowski wants to merge 1 commit intomasterfrom
ci/pypi-trusted-publishing

Conversation

@MHoroszowski
Copy link
Copy Markdown
Owner

Summary

  • Adds .github/workflows/publish.yml so future releases publish to PyPI automatically when a GitHub Release is published.
  • Uses PyPI Trusted Publishing (OIDC) — no long-lived API token stored as a repo secret. Workflow identity is verified by PyPI against the configured publisher.
  • Two-job pipeline: build (sdist + wheel + twine check, uploaded as a workflow artifact) → publish-pypi (downloads artifact, publishes via pypa/gh-action-pypi-publish with id-token: write and the pypi environment).

One-time setup required on PyPI (cannot be done from this repo)

After this PR merges, configure the Trusted Publisher so the workflow can actually upload:

  1. Open https://pypi.org/manage/project/python-pptx-extended/settings/publishing/
  2. Click Add publisher and fill in:
    • PyPI Project Name: python-pptx-extended
    • Owner: MHoroszowski
    • Repository name: python-pptx
    • Workflow name: publish.yml
    • Environment name: pypi
  3. (Recommended) In this repo's Settings → Environments, create an environment named pypi and add a deployment branch/tag rule restricting deploys to tags matching v*. Second line of defense in case workflow logic is ever changed in a PR.

After setup, the local ~/.pypirc PyPI API token used for the manual 1.1.0 upload can be revoked at https://pypi.org/manage/account/token/ — Trusted Publishing replaces it.

How releases will work after merge

  1. Bump version in src/pptx/init.py and add an entry to HISTORY.rst; merge to master.
  2. Tag the merge commit vX.Y.Z and push the tag.
  3. Create a GitHub Release pointing at that tag (UI or gh release create vX.Y.Z).
  4. The publish workflow runs on release: published, builds, and uploads to PyPI. workflow_dispatch is also wired for manual re-runs.

Test plan

  • PR review of the workflow YAML
  • After merge: configure the PyPI Trusted Publisher per the setup section above
  • After merge: create the pypi environment in repo Settings (optional but recommended)
  • Validate end-to-end on the next release by cutting a GitHub Release and watching the Actions tab

Related

🤖 Generated with Claude Code

Adds .github/workflows/publish.yml so future releases publish to PyPI
automatically when a GitHub Release is published, using PyPI's OIDC
Trusted Publishing instead of a long-lived API token stored as a repo
secret.

Workflow:
  - build job: checkout, build sdist+wheel, twine check, upload as
    workflow artifact.
  - publish-pypi job: downloads the artifact and uploads to PyPI via
    pypa/gh-action-pypi-publish, gated on the `pypi` environment with
    id-token write permission for OIDC.

One-time setup required on PyPI side (cannot be done from this repo):
  1. https://pypi.org/manage/project/python-pptx-extended/settings/publishing/
  2. Add a GitHub publisher with:
       owner: MHoroszowski
       repository: python-pptx
       workflow: publish.yml
       environment: pypi
  3. (Recommended) Create a `pypi` environment in repo Settings →
     Environments with branch protection requiring tag-based deploys.

Triggering a release after setup:
  - Cut a GitHub Release pointing at a vX.Y.Z tag — this fires the
    workflow on `release: published`.
  - workflow_dispatch is also wired for manual re-runs / overrides.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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