Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to TestPyPI and PyPI via OpenID Connect token #2453

Merged
merged 3 commits into from
Mar 23, 2023
Merged

Conversation

weiji14
Copy link
Member

@weiji14 weiji14 commented Mar 22, 2023

Description of proposed changes

Using a short-lived API token generated by OpenID Connect (OIDC) instead of a long-lived secret to publish packages to TestPyPI and PyPI.

I've set up the OIDC publisher at both TestPyPI and PyPI under the publishing settings like so:

PyPI settings to set up OIDC publishing

To be super sure, I've also tested this on my own project at weiji14/zen3geo#90. See the publish-to-pypi workflow run using OIDC at https://github.com/weiji14/zen3geo/actions/runs/4495219924/jobs/7908620558#step:8:21, and the package that was successfully uploaded at https://test.pypi.org/project/zen3geo/0.5.1.dev19.

References:

Xref #2451 (comment)

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If wrapping a new module, open a 'Wrap new GMT module' issue and submit reasonably-sized PRs.
  • If adding new functionality, add an example to docstrings or tutorials.
  • Use underscores (not hyphens) in names of Python files and directories.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

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.1#ipublishing-with-openid-connect
@weiji14 weiji14 self-assigned this Mar 22, 2023
@weiji14 weiji14 added the maintenance Boring but important stuff for the core devs label Mar 22, 2023
@weiji14 weiji14 added this to the 0.9.0 milestone Mar 22, 2023
@weiji14 weiji14 marked this pull request as ready for review March 22, 2023 23:31
@seisman
Copy link
Member

seisman commented Mar 23, 2023

Looks good to me. Perhaps we should add a note that "the workflow file name must be publish-to-pypi.yml to match the settings in PyPI" at the beginning of the workflow file.

Also need to remove these API tokens from the GitHub secrets.

weiji14 and others added 2 commits March 23, 2023 16:15
Co-Authored-By: Dongdong Tian <seisman.info@gmail.com>
Mention that authentication to TestPyPI/PyPI happens via OpenID Connect.
@weiji14
Copy link
Member Author

weiji14 commented Mar 23, 2023

Looks good to me. Perhaps we should add a note that "the workflow file name must be publish-to-pypi.yml to match the settings in PyPI" at the beginning of the workflow file.

Ok, I've added the note at commit d01ea6b. Also mentioned the OpenID Connect (OIDC) authentication to TestPyPI/PyPI in doc/maintenance.md

Also need to remove these API tokens from the GitHub secrets.

Yes, will do this after this PR is merged and we've checked that uploading to TestPyPI works. Will also need to remove the API tokens from TestPyPI and PyPI.

@weiji14 weiji14 merged commit 00c8370 into main Mar 23, 2023
@weiji14 weiji14 deleted the pypi-oidc branch March 23, 2023 08:26
@weiji14
Copy link
Member Author

weiji14 commented Mar 23, 2023

Also need to remove these API tokens from the GitHub secrets.

Yes, will do this after this PR is merged and we've checked that uploading to TestPyPI works. Will also need to remove the API tokens from TestPyPI and PyPI.

Ok, upload to TestPyPI was successful at https://test.pypi.org/project/pygmt/0.8.1.dev115/! See logs at https://github.com/GenericMappingTools/pygmt/actions/runs/4498503524/jobs/7915200866#step:8:20. This is how it looks like on TestPyPI.

image

I've also removed the PYPI_API_TOKEN and TEST_PYPI_API_TOKEN from GitHub secrets and TestPyPI/PyPI (which apparently were under my PyPI account since #900 (comment) 😂).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants