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

Use trusted publishing with both PyPI and TestPyPI #129

Merged
merged 28 commits into from
Mar 20, 2025

Conversation

sajith
Copy link
Member

@sajith sajith commented Mar 17, 2025

Attempting to resolve #127; stacked on top of #121. I have added the repository owner (tahoe-lafs), repository name (zfec), workflow file (build.yml), and environment (release or testpypi) to add GHA as a publisher both on TestPyPI and PyPI.

image

@sajith sajith marked this pull request as draft March 18, 2025 16:21
For both the action step documentation and Python Packaging User Guide
says that repository-url is required for publishing on TestPyPI, but
the workflow run produces this warning:

> Unexpected input(s) 'repository-url', valid inputs are
> ['entryPoint', 'args', 'user', 'password', 'repository_url',
> 'packages_dir', 'verify_metadata', 'skip_existing', 'verbose',
> 'print_hash']

And this warning:

> Warning: It looks like you are trying to use an API token to
> authenticate in the package index and your token value does not
> start with "pypi-" as it typically should. This may cause an
> authentication error. Please verify that you have copied your token
> properly if such an error occurs.

And this error message:

> INFO     Response from https://upload.pypi.org/legacy/:
>          403 Invalid or non-existent authentication information. See
>          https://pypi.org/help/#invalid-auth for more information.
> INFO     <html>
>           <head>
>            <title>403 Invalid or non-existent authentication information. See
>          https://pypi.org/help/#invalid-auth for more information.</title>
>           </head>
>           <body>
>            <h1>403 Invalid or non-existent authentication information. See
>          https://pypi.org/help/#invalid-auth for more information.</h1>
>            Access was denied to this resource.<br/><br/>
>          Invalid or non-existent authentication information. See
>          https://pypi.org/help/#invalid-auth for more information.
>
>
>           </body>
>          </html>
> ERROR    HTTPError: 403 Forbidden from https://upload.pypi.org/legacy/
>          Invalid or non-existent authentication information. See
>          https://pypi.org/help/#invalid-auth for more information.

Let us give repository_url a try then!
sajith added 2 commits March 18, 2025 13:52
After updating pypa/gh-action-pypi-publish, the warning about
repository url changed:

> Warning: Input 'repository_url' has been deprecated with message:
> The inputs have been normalized to use kebab-case. Use
> `repository-url` instead.
Done with debugging the trusted publishing workflow, I hope.
@sajith
Copy link
Member Author

sajith commented Mar 19, 2025

This is ready for review. These are the changes:

  • The publish_pypi job has now been split to publish_pypi and publish_testpypi, following the example workflow in Python Packaging User Guide. This introduced some duplication but that appears to be necessary: environment.name and environment.url ought to be different for pypa/gh-action-pypi-publish to work, I believe.
  • Updated pypa/gh-action-pypi-publish to the current version, updated commentary in the workflow, etc.
  • Log the publish step more verbosely (essentially twine upload --verbose) so that we will have more details to work with if/when things go wrong.

I have tested the workflow with both PyPI and TestPyPI, and things seem to work just fine. See the yanked release at PyPI (https://pypi.org/manage/project/zfec/release/1.6.0.1.post0/) and the recent uploads to TestPyPI (https://test.pypi.org/project/zfec/#history).

@sajith sajith marked this pull request as ready for review March 19, 2025 16:27
@sajith sajith requested review from meejah, hacklschorsch and a team March 19, 2025 16:27
Copy link
Member

@hacklschorsch hacklschorsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this was much more work than I thought. Thanks for doing it! The GHA config is easy to follow. I like that you kept close to the documented examples. Looking very good to me!

@sajith sajith merged commit 801b64f into master Mar 20, 2025
79 of 104 checks passed
@sajith sajith deleted the 127.pypi-trusted-publishing branch March 20, 2025 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automated upload to PyPI fails
2 participants