|
5 | 5 |
|
6 | 6 |
|
7 | 7 | ## Usage
|
8 |
| -To use the action simply add the following lines in the end of your |
9 |
| -`.github/main.workflow`. |
10 |
| - |
11 |
| -```hcl |
12 |
| -action "Upload Python dist to PyPI" { |
13 |
| - uses = "re-actors/pypi-action@master" |
14 |
| - env = { |
15 |
| - TWINE_USERNAME = "f'{your_project}-bot'" |
16 |
| - } |
17 |
| - secrets = ["TWINE_PASSWORD"] |
18 |
| -} |
| 8 | + |
| 9 | +To use the action add the following step to your workflow file (e.g.: |
| 10 | +`.github/workflows/main.yml`) |
| 11 | + |
| 12 | + |
| 13 | +```yml |
| 14 | +- name: Publish a Python distribution to PyPI |
| 15 | + uses: pypa/gh-action-pypi-publish@master |
| 16 | + with: |
| 17 | + user: __token__ |
| 18 | + password: ${{ secrets.pypi_password }} |
19 | 19 | ```
|
20 | 20 |
|
21 |
| -N.B. Use a valid tag, or branch, or commit SHA instead |
22 |
| -of `master` to pin the action to use a specific version of it. |
| 21 | +A common use case is to upload packages only on a tagged commit, to do so add a |
| 22 | +filter to the step: |
23 | 23 |
|
24 | 24 |
|
25 |
| -### Environment Variables and Secrets |
26 |
| -- **`TWINE_USERNAME`**: set this one to the username used to authenticate |
27 |
| -against PyPI. _It is recommended to have a separate user account like |
28 |
| -`f'{your_project}-bot'` having the lowest privileges possible on your |
29 |
| -target dist page._ |
30 |
| -- **`TWINE_PASSWORD`**: it's a password for the account used in |
31 |
| -`TWINE_USERNAME` env var. **ATTENTION! WARNING! When adding this value |
32 |
| -to the Action node in your workflow, use SECRETS, not normal env vars.** |
| 25 | +```yml |
| 26 | + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') |
| 27 | +``` |
| 28 | +
|
| 29 | +So the full step would look like: |
| 30 | +
|
| 31 | +
|
| 32 | +```yml |
| 33 | +- name: Publish package |
| 34 | + if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') |
| 35 | + uses: pypa/gh-action-pypi-publish@master |
| 36 | + with: |
| 37 | + user: __token__ |
| 38 | + password: ${{ secrets.pypi_password }} |
| 39 | +``` |
| 40 | +
|
| 41 | +The example above uses the new [API token](https://pypi.org/help/#apitoken) |
| 42 | +feature of PyPI, which is recommended to restrict the access the action has. |
| 43 | +
|
| 44 | +The secret used in `${{ secrets.pypi_password }}` needs to be created on the settings |
| 45 | +page of your project on GitHub. See [Creating & using secrets]. |
33 | 46 |
|
34 | 47 |
|
35 | 48 | ## License
|
| 49 | + |
36 | 50 | The Dockerfile and associated scripts and documentation in this project
|
37 | 51 | are released under the [BSD 3-clause license](LICENSE.md).
|
| 52 | + |
| 53 | + |
| 54 | +[Creating & using secrets]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables |
0 commit comments