|
1 | | -# Creating a PyPI Token |
| 1 | +# Setting up PyPI publishing |
2 | 2 |
|
3 | | -To publish your package on PyPI requires a PyPI account and for GitHub Actions to have a PyPI token authorizing access to that account. |
| 3 | +To publish your package on PyPI requires a PyPI account and for PyPI to be setup for [Trusted Publisher](https://docs.pypi.org/trusted-publishers/). |
4 | 4 |
|
5 | | -The simplest approach is to set up a PyPI token that is scoped to your PyPI account and add it to the secrets for your GitHub Organization (or user). This means that all new projects created in the Organization will automatically gain permission to publish to PyPI. |
| 5 | +## Gather the information |
6 | 6 |
|
7 | | -Alternatively you can create a project scoped token for each project. This is more work but more secure as a bad actor that obtains the key can only affect a single project. |
| 7 | +You will need the following information: |
8 | 8 |
|
9 | | -If you do not already have a PyPI account use this link: [create_account]. |
| 9 | +- Owner: The GitHub org that the repo is contained in, e.g. `DiamondLightSource` |
| 10 | +- Repository name: The GitHub repository name, e.g. `python-copier-template-example` |
| 11 | +- PyPI Project Name: The distribution name on PyPI, e.g. `dls-python-copier-template-example` |
| 12 | +- Workflow name: The workflow that does publishing, `_pypi.yml` for `python-copier-template` projects |
| 13 | +- Environment name: The GitHub environment that publishing is done with, `release` for `python-copier-template` projects |
10 | 14 |
|
11 | | -To learn how to create a token and store it in Github see: [adding_a_token]. You can ignore the other sections of the page regarding Github Actions because these are already provided by skeleton. Note that skeleton uses `PYPI_TOKEN` as the secret name instead of `PYPI_API_TOKEN` described in the link. |
| 15 | +## If publishing to the DiamondLightSource PyPI organisation |
12 | 16 |
|
13 | | -[adding_a_token]: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#saving-credentials-on-github |
14 | | -[create_account]: https://pypi.org/account/register/ |
| 17 | +If you are publishing to the DiamondLightSource PyPI organisation then use the above information and follow the [Developer Portal Guide on PyPI publishing](https://dev-portal.diamond.ac.uk/guide/python/how-tos/pypi/). |
| 18 | + |
| 19 | +## If publishing the PyPI project to another organisation |
| 20 | + |
| 21 | +If you are publishing to a different PyPI organisation then use the above information in one of the following guides: |
| 22 | + |
| 23 | +- [Creating a PyPI project with a trusted publisher](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/) |
| 24 | +- [Adding a trusted publisher to an existing PyPI project](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) |
0 commit comments