Docs / PYPI-TRUSTED-PUBLISHING

Publishing the CLI to PyPI with Trusted Publishing

Source: docs/PYPI-TRUSTED-PUBLISHING.md

The Python CLI is kitty-game-composer 0.2.0 (the kitty command). Publishing uses
PyPI Trusted Publishing (OpenID Connect) from GitHub Actions, so no API token,
password or 2FA code is stored in the repository or typed into a terminal.

One-time setup on PyPI

On https://pypi.org/manage/account/publishing/ add a pending publisher
(the project does not exist on PyPI yet, so a pending publisher will create it):

Field Value
PyPI Project Name kitty-game-composer
Owner EnzoVezzaro
Repository name game-composer
Workflow name publish-pypi.yml
Environment name pypi

The repository is private; Trusted Publishing works with private repositories
because the OIDC token is issued by GitHub Actions for the matching workflow.

One-time setup on GitHub

The repository needs an environment named pypi. GitHub creates it when the job
first runs; to restrict who can approve, add it under Settings → Environments.
Optionally add a required reviewer there. No secrets are needed.

Publishing

Push .github/workflows/publish-pypi.yml to the default branch first: PyPI
validates that the workflow file exists on the default branch at publish time.
Then publish GitHub release v0.2.0 (or use the manual workflow_dispatch
trigger). The workflow builds the sdist and wheel, runs twine check --strict,
and publishes with pypa/gh-action-pypi-publish using the OIDC identity.

Verify with:

python -m pip index versions kitty-game-composer
python -m pip install kitty-game-composer
kitty --version

The pending publisher does not reserve the name. If someone else creates
kitty-game-composer on PyPI first, this setup cannot publish to it.

Back to all docs