Releases are published to PyPI by the
Publish to PyPI GitHub Actions workflow
whenever a GitHub release is published. The workflow authenticates with
Trusted Publishing, so no PyPI API
token needs to be stored as a repository secret.
-
Log in to PyPI as an owner of the
jsonpatchproject and open https://pypi.org/manage/project/jsonpatch/settings/publishing/ (Your projects → jsonpatch → Manage → Publishing). -
Under Add a new publisher, select the GitHub tab and enter:
Field Value Owner stefankoeglRepository name python-json-patchWorkflow name publish.yamlEnvironment name pypi -
Click Add.
- In the repository, go to Settings → Environments → New environment and
create an environment named
pypi(it must match the environment name entered on PyPI). - Recommended protection rules:
- Required reviewers: add yourself, so every upload waits for a manual approval in the Actions tab.
- Deployment branches and tags: choose Selected branches and tags and
add a tag rule
v*, so only release tags can deploy to PyPI.
To try the full upload without touching the real index:
- Create an account on https://test.pypi.org/ (it is separate from PyPI).
- As
jsonpatchdoes not exist on TestPyPI yet, add a pending publisher at https://test.pypi.org/manage/account/publishing/ with the same values as above, plus PyPI Project Namejsonpatch, and Environment nametestpypi. - Create a GitHub environment named
testpypi(no tag restriction, since manual runs start from a branch).
Once a release has gone out through the workflow, any PyPI API tokens that were
used for manual uploads (e.g. in ~/.pypirc) can be revoked at
https://pypi.org/manage/account/token/.
-
Update
__version__injsonpatch.py, commit, and push tomaster. -
Create a GitHub release whose tag is the version prefixed with
v(e.g.v1.34for__version__ = '1.34'), targetingmaster. Either use Releases → Draft a new release in the web UI, or rungh release create v1.34 --target master --generate-notes -
Publishing the release starts the workflow. It
- fails early if the tag does not match
__version__, - builds the sdist and wheel and checks them with
twine check --strict, - waits for approval if the
pypienvironment requires reviewers, - uploads both files to PyPI.
- fails early if the tag does not match
PyPI never accepts the same version twice, so a failed or wrong upload has to be fixed with a new version number.
Actions → Publish to PyPI → Run workflow builds and checks the distributions from the selected branch without publishing them; the files can be downloaded from the run's Artifacts section. Tick testpypi to also upload them to TestPyPI (requires step 3 of the setup). TestPyPI accepts each version only once, so re-running for an already uploaded version skips the upload.