Publish verified Python distributions¶
These are the shared publication checks for the PyPI migration. It extends the existing tested-artifact release approach; it does not build, resolve versions, download releases, or replace consumer provenance checks.
Keep the publisher in the package repository¶
PyPI does not support registering reusable workflows as Trusted Publishers.
In a job defined directly in the package repository, use the shared
verify-pypi guard, then call the pinned PyPA publisher as the next top-level
job step. PyPA does not support nesting its publisher in a composite action.
The legacy publish-pypi composite is retained for compatibility
with existing references. Do not use that wrapper for new or repaired
callers: its nested Docker action can resolve the enclosing action's
repository instead of the PyPA image.
Name the caller workflow publish-pypi.yml, matching the pending publisher tuples.
Register that repository's owner, repository name, publish-pypi.yml and pypi
environment with PyPI. Do not register this shared repository as the publisher.
The environment must restrict deployment to protected main. Its name must match
PyPI registration exactly. Owners configure these settings separately; adopting
the guard does not create them or establish that they exist.
Prepare once with read-only permissions¶
Reuse the package's existing release verification job. Before handing off bytes:
- Bind the package/version to its exact verified source commit and successful protected release/build. For an existing release, check immutable, published, non-prerelease status, exact tag commit, authentic asset digests and checksum manifest, and embedded build provenance where the package provides it.
- Run the package's clean installed tests and the shared
check-pypi-metadataaction on the exact staged wheel(s) and source archive. Never rebuild between validation and publication. - Upload only those distributions with the existing pinned artifact action.
Expose the artifact name and a
checksumsjob output in standard SHA256SUMS format: lowercase SHA-256, two spaces, basename, one entry per line. - Derive that output from the authenticated, tested bytes in this read-only job, not a checksum file supplied by an untrusted artifact. Do not accept arbitrary run IDs, fork artifacts, or unverified releases as publication inputs.
The read-only metadata action uses the versions from the pinned PyPA v1.14.3
runtime lock to run twine check --strict, also refusing metadata warnings.
Run it after installing the
repository's pinned uv and staging the original distributions.
Its default input is pypi-dist; an alternate staged directory must be in the
workspace or runner's temporary directory. The action does not download the
release, verify its checksums again, or install or execute the package.
Check the PyPA runtime lock and run the old- and new-format metadata fixtures
before changing the direct uploader pin or the shared constraints.
For publication the only supported directory is pypi-dist/ directly under
GITHUB_WORKSPACE.
The workspace must be a real absolute directory, with no symlink resolution;
the distribution directory and files must not be symlinks. The verifier and
PyPA publisher use this same location. No step or background process may write
these files between verification and upload. Place the direct publisher
immediately after the guard, with no intervening steps or background writers.
The guard requires the complete set of wheel(s) and exactly one .tar.gz source
archive. It refuses missing, extra, duplicate, changed or symlinked files,
preventing the next step from publishing. It reuses the shared release
publisher's SHA-256 helper.
Package-specific compatibility and provenance validation remain in preparation.
Add a thin publication job¶
The following job assumes the existing verify-release job exports artifact
and checksums only after all checks pass. The workflow itself uses only a
protected-main push or manual dispatch; PR checks live in a separate workflow.
Replace RELEASE_TAG with the reviewed immutable Guidelines release tag
containing the guard. Do not use this placeholder as a production dependency.
publish-pypi:
needs: verify-release
if: >-
github.ref == 'refs/heads/main' && github.ref_protected &&
needs.verify-release.result == 'success'
runs-on: ubuntu-24.04
environment: pypi
permissions:
id-token: write
steps:
# actions/download-artifact v4.3.0
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: ${{ needs.verify-release.outputs.artifact }}
path: pypi-dist/
- uses: Living-Proof-Labs/collaboration-guidelines/.github/actions/verify-pypi@RELEASE_TAG
with:
checksums: ${{ needs.verify-release.outputs.checksums }}
# pypa/gh-action-pypi-publish v1.14.3
- uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086
with:
packages-dir: pypi-dist/
Keep contents: read on preparation and id-token: write only on publication.
Do not check out or execute package code in the OIDC job. The transfer is from
the same workflow run; no cross-run artifact lookup or credentials are inputs.
The guard rechecks the event, main ref and protected-ref context. It never
publishes or requests an OIDC token. Use a Linux runner for the pinned PyPA
publisher.
There is no password, alternate registry, skip-existing or overwrite option.
If publication is interrupted, inspect public PyPI before authorizing a retry.
A rerun uses the original workflow revision. If that revision nests the
publisher, fix the caller and use a reviewed recovery path with the same
immutable files. Rerunning the old definition will not pick up the repair.
Review and adoption¶
Before enabling a consumer, independently review its preparation and job gates, confirm the exact pending/existing PyPI publisher tuple and environment policy, and verify the action release pin. A local checksum test does not prove OIDC registration. No public test upload is required or authorized by this component. After authorized publication, independently download wheel and source from PyPI, compare both hashes with the tested inputs, and clean-install the public package. Consumer adoption and future automatic release triggers are separate changes.
Documentation home · Docs: v9.15.0 · Version and source · Help / report an issue · License