Skip to content

Commit 00c8370

Browse files
weiji14seisman
andauthored
Publish to TestPyPI and PyPI via OpenID Connect token (#2453)
Using a short-lived API token generated by OpenID Connect (OIDC) instead of a long-lived secret to publish packages to TestPyPI and PyPI. Refer to https://github.com/pypa/gh-action-pypi-publish/tree/v1.8.3#ipublishing-with-openid-connect * Add note that workflow must be named publish-to-pypi * Add note about OIDC publishing to doc/maintenance.md Mention that authentication to TestPyPI/PyPI happens via OpenID Connect. --------- Co-authored-by: Dongdong Tian <[email protected]>
1 parent 818dfa5 commit 00c8370

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.github/workflows/publish-to-pypi.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Publish archives to PyPI and TestPyPI using GitHub Actions
2+
# Important: this workflow filename must be publish-to-pypi.yml to match the
3+
# settings in PyPI and TestPyPI so that OIDC publishing works
24

35
name: Publish to PyPI
46

@@ -19,6 +21,9 @@ jobs:
1921
publish-pypi:
2022
name: Publish to PyPI
2123
runs-on: ubuntu-latest
24+
permissions:
25+
# This permission is mandatory for OIDC publishing
26+
id-token: write
2227
if: github.repository == 'GenericMappingTools/pygmt'
2328

2429
steps:
@@ -53,13 +58,10 @@ jobs:
5358
ls -lh dist/
5459
5560
- name: Publish to Test PyPI
56-
uses: pypa/[email protected].1
61+
uses: pypa/[email protected].3
5762
with:
58-
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
5963
repository-url: https://test.pypi.org/legacy/
6064

6165
- name: Publish to PyPI
6266
if: startsWith(github.ref, 'refs/tags')
63-
uses: pypa/[email protected]
64-
with:
65-
password: ${{ secrets.PYPI_API_TOKEN }}
67+
uses: pypa/[email protected]

doc/maintenance.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ There are 11 configuration files located in `.github/workflows`:
118118
If new remote files are needed urgently, maintainers can manually uncomment
119119
the 'pull_request:' line in that `cache_data.yaml` file to refresh the cache.
120120

121-
6. `publish-to-pypi.yml` (Publish wheels to PyPI and TestPyPI)
121+
6. `publish-to-pypi.yml` (Publish wheels to TestPyPI and PyPI)
122122

123-
This workflow is run to publish wheels to PyPI and TestPyPI (for testing only).
124-
Archives will be pushed to TestPyPI on every commit to the *main* branch
125-
and tagged releases, and to PyPI for tagged releases only.
123+
This workflow is ran to publish wheels to TestPyPI (for testing only) and
124+
PyPI. Archives will be pushed to TestPyPI on every commit to the *main*
125+
branch and tagged releases, and to PyPI for tagged releases only. Note that
126+
authentication to TestPyPI/PyPI is done via OpenID Connect, see also
127+
https://github.com/pypa/gh-action-pypi-publish/tree/release/v1#publishing-with-openid-connect
126128

127129
7. `release-drafter.yml` (Drafts the next release notes)
128130

0 commit comments

Comments
 (0)