Skip to content

Commit ff5420c

Browse files
committed
Convert to trusted publishing
I based this change on the official PyPI documentation: https://docs.pypi.org/trusted-publishers/ as well as a blog post walking through an example of how to implement trusted publishing for a Python project: https://pgjones.dev/blog/trusted-plublishing-2023/ The diff is fairly minimal. All it does is remove the password used to authenticate to PyPI, which we don't need anymore, and add a permission needed for trusted publishing to operate. This commit will be accompanied by some configuration in the project settings on PyPI to allow this specific workflow to act as a trusted publisher. Effectively, we're telling PyPI that when this particular workflow (`publish.yml`) contacts it with an OIDC token from Github, then PyPI should accept that as valid authentication and return an API token which can be used to actually upload a package.
1 parent e6baa2f commit ff5420c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
runs-on: ubuntu-latest
3232
needs: [build]
3333
environment: test-pypi
34+
permissions:
35+
# this permission is mandatory for trusted publishing
36+
id-token: write
3437
steps:
3538
- uses: actions/download-artifact@v3
3639
with:
@@ -39,14 +42,16 @@ jobs:
3942
- name: Publish packages to Test PyPI
4043
uses: pypa/gh-action-pypi-publish@release/v1
4144
with:
42-
password: '${{ secrets.TEST_PYPI_API_TOKEN }}'
4345
repository_url: https://test.pypi.org/legacy/
4446
print_hash: true
4547
publish-to-pypi:
4648
name: Publish packages to PyPI
4749
runs-on: ubuntu-latest
4850
needs: [build]
4951
environment: pypi
52+
permissions:
53+
# this permission is mandatory for trusted publishing
54+
id-token: write
5055
steps:
5156
- uses: actions/download-artifact@v3
5257
with:
@@ -55,5 +60,4 @@ jobs:
5560
- name: Publish packages to PyPI
5661
uses: pypa/gh-action-pypi-publish@release/v1
5762
with:
58-
password: '${{ secrets.PYPI_API_TOKEN }}'
5963
print_hash: true

0 commit comments

Comments
 (0)