Skip to content

Publish to PyPI with trusted publishing - #559

Merged
anth-volk merged 1 commit into
masterfrom
trusted-publishing
Oct 12, 2026
Merged

anth-volk merged 1 commit into
masterfrom
trusted-publishing

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor
  • make format && make documentation has been run. (Not applicable: this PR changes only workflow YAML and changelog files.)

What's changed

Moves PyPI publishing from the shared org-wide secrets.PYPI token to PyPI trusted publishing (OIDC).

In .github/workflows/push.yaml, the Publish job (the one that runs pypa/gh-action-pypi-publish) now:

  • runs in the pypi environment (environment: pypi)
  • has job-level permissions: contents: write (kept because publish-git-tag.sh pushes a tag; the repo default token is already write) + id-token: write
  • no longer passes user: __token__ / password: ${{ secrets.PYPI }}. The action ignores OIDC while a password is given, so these had to go. skip_existing is kept.

The pypi environment already exists in this repo and is limited to master. This PR does not change any repo settings, environments or secrets. secrets.PYPI is not used anywhere else under .github/.

Merging cuts a patch release via changelog.d/trusted-publishing.changed.md. .github/bump_version.py returns major only for breaking, minor for added/removed, and patch otherwise, so changed gives a patch bump. Running bump_version.py and towncrier build locally on this branch gives 0.99.0 -> 0.99.1.

Fix for the broken release pipeline

The Update versioning job has failed on every push to master since #550 (2026-03-18), including the 2026-04-28 run. The reason: #550 and #551 put their fragments under changelog.d/fixed/. bump_version.py only looks at files at the top of changelog.d/, so it saw none and exited with No changelog fragments found. I reproduced this locally on master. This PR moves the two fragments to changelog.d/<name>.fixed.md, the layout towncrier and the PR check suggest. With that, they also go into the 0.99.1 changelog, so the #550 enum fix and the #551 workflow change finally get released. Without the move, the bump would still pass but towncrier would quietly skip those two entries.

Not fixed here (it does not block the PyPI upload): publish-git-tag.sh calls python setup.py --version, but there is no setup.py, so no tag gets pushed (the || true hides the error).

Before merging

Add a trusted publisher on PyPI (project settings, Publishing) with these values:

Field Value
PyPI project policyengine-canada
Owner PolicyEngine
Repository policyengine-canada
Workflow filename push.yaml
Environment pypi

If this PR is merged before the publisher is added, the publish step fails with invalid-publisher and that release does not reach PyPI.

Test plan

  • actionlint on .github/workflows/push.yaml: no new findings compared with master.
  • Ran the release step locally on this branch; it computes a patch bump (see above).
  • PR checks pass.
  • After the PyPI publisher is added and this is merged, the Publish job's deployment to pypi uploads the new patch version to https://pypi.org/project/policyengine-canada/ with no token.

🤖 Generated with Claude Code

Add environment: pypi and id-token: write to the job that runs
pypa/gh-action-pypi-publish, and drop the user/password inputs that
passed the org-wide secrets.PYPI token, so the upload uses OIDC.

Add a changed fragment so merging cuts a patch release. Move the two
fragments under changelog.d/fixed/ to changelog.d/<name>.fixed.md:
bump_version.py only reads files at the top of changelog.d, so it
exited with "No changelog fragments found" and has failed the
Update versioning job on every push since #550.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review October 12, 2026 15:46
@anth-volk
anth-volk merged commit 7a56fe0 into master Oct 12, 2026
4 checks passed
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