2019-03-27 15:58:36 -04:00
|
|
|
# PyPI publish GitHub Action
|
|
|
|
This action allows you to upload your [Python distribution package](
|
|
|
|
https://packaging.python.org/glossary/#term-distribution-package) to
|
2019-05-26 11:53:57 -04:00
|
|
|
PyPI.
|
2019-03-27 15:58:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
## Usage
|
2019-08-20 16:48:52 -04:00
|
|
|
|
|
|
|
To use the action add the following step to your workflow file (e.g.:
|
|
|
|
`.github/workflows/main.yml`)
|
|
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
- name: Publish a Python distribution to PyPI
|
2019-08-23 07:20:45 -04:00
|
|
|
uses: pypa/gh-action-pypi-publish@master
|
2019-08-20 16:48:52 -04:00
|
|
|
with:
|
|
|
|
user: __token__
|
|
|
|
password: ${{ secrets.pypi_password }}
|
2019-03-27 15:58:36 -04:00
|
|
|
```
|
|
|
|
|
2019-08-20 16:48:52 -04:00
|
|
|
A common use case is to upload packages only on a tagged commit, to do so add a
|
|
|
|
filter to the step:
|
2019-03-27 15:58:36 -04:00
|
|
|
|
|
|
|
|
2019-08-20 16:48:52 -04:00
|
|
|
```yml
|
|
|
|
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
|
|
|
|
```
|
|
|
|
|
|
|
|
So the full step would look like:
|
|
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
- name: Publish package
|
|
|
|
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
|
2019-08-23 07:20:45 -04:00
|
|
|
uses: pypa/gh-action-pypi-publish@master
|
2019-08-20 16:48:52 -04:00
|
|
|
with:
|
|
|
|
user: __token__
|
2019-08-23 07:19:24 -04:00
|
|
|
password: ${{ secrets.pypi_password }}
|
2019-08-20 16:48:52 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
The example above uses the new [API token](https://pypi.org/help/#apitoken)
|
|
|
|
feature of PyPI, which is recommended to restrict the access the action has.
|
|
|
|
|
|
|
|
The secret used in `${{ secrets.pypi_password }}` needs to be created on the settings
|
|
|
|
page of your project on GitHub. See [Creating & using secrets].
|
2019-03-27 15:58:36 -04:00
|
|
|
|
|
|
|
|
2019-09-12 08:06:55 -04:00
|
|
|
## Non-goals
|
|
|
|
|
|
|
|
This GitHub Action [has nothing to do with _building package
|
|
|
|
distributions_]. Users are responsible for preparing dists for upload
|
|
|
|
by putting them into the `dist/` folder prior to running this Action.
|
|
|
|
|
|
|
|
|
2019-03-27 15:58:36 -04:00
|
|
|
## License
|
2019-08-20 16:48:52 -04:00
|
|
|
|
2019-03-27 15:58:36 -04:00
|
|
|
The Dockerfile and associated scripts and documentation in this project
|
2019-03-29 18:48:49 -04:00
|
|
|
are released under the [BSD 3-clause license](LICENSE.md).
|
2019-08-20 16:48:52 -04:00
|
|
|
|
|
|
|
|
|
|
|
[Creating & using secrets]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
|
2019-09-12 08:06:55 -04:00
|
|
|
[has nothing to do with _building package distributions_]:
|
|
|
|
https://github.com/pypa/gh-action-pypi-publish/issues/11#issuecomment-530480449
|