Use PyPI action and trusted publishing to publish packages

Open
#186 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
github-actions, python

Research direction

Start with the release job in .github/workflows/main.yml and compare it with the documented pypa/gh-action-pypi-publish trusted-publishing setup. Review the listed PyPI and GitHub environment configuration, then verify the release tox environment is no longer used in CI. Done means the workflow builds and publishes through the action with attestations and creates the GitHub release.

Written by the indexing model from the issue text.

Description

Switch to pypa/gh-action-pypi-publish for the publish to PyPI job in the CI workflow, instead of invocation of twine upload (via tox), using trusted publishing.

This adds build artefact attestations in the upload to PyPI. Trusted publishing (with attestations) means I can know for certain that what I download from PyPI is the same artefact which was generated in GitHub CI, meaning that what I see in GitHub is the same as what is installed - handy for auditing (rather than having to manually review all of the installed files on each release).

See the Python packaging documentation, the PyPI documentation, and the official pypi-publish GitHub action documentation on trusted publishing.

In the release job of the CI workflow, you would add the environment and permissions (id-token: write), and replace the Install tox and Run steps with four steps (assuming you don't want to split the build into a separate step, with less permissions):

  • install dependencies: run: pip install build 'jaraco.develop >= 7.1
  • build the package: run: python -m build
  • the PyPI publish action: uses: pypa/gh-action-pypi-publish@release/v1 (no TWINE_PASSWORD env needed)
  • create the GitHub release: run: python -m jaraco.develop.create-github-release and env: { GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} }

You'll need to configure an environment in PyPI and GitHub. You will be able to remove the PYPI_USERNAME project secret.

The release tox environment would not be used in CI anymore.

Dominant language
No language data
Stars
152
Forks
38
Avg merge
6h 27m
Merged PRs (30d)
4

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jaraco/skeleton

All issues in jaraco/skeleton

Similar issues

More DevOps issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.