Fix PyPI Trusted Publisher configuration by adding environment field #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The GitHub Actions workflow for publishing the Python package to PyPI was failing with the error:
This prevented automatic package publishing to PyPI via the Trusted Publisher authentication system.
Solution
Added the missing
environment: pypifield to the deploy job in.github/workflows/python-publish.yml.What Changed
Why This Fix Works
PyPI Trusted Publishers use OpenID Connect (OIDC) tokens from GitHub Actions to authenticate package uploads without requiring manual API tokens. The system verifies the publisher's identity by matching several claims between the GitHub Actions workflow and the PyPI project configuration:
Without the
environmentfield, the OIDC token from GitHub Actions was missing a critical claim, causing PyPI to reject the authentication attempt.Next Steps
After merging this PR, the repository owner should:
Configure PyPI Trusted Publisher at https://pypi.org/manage/project/cfbd/settings/publishing/ with:
zachringnight/cfbd-pythonpython-publish.ymlpypiCreate GitHub Environment (if not already exists):
pypiTest the workflow by pushing a commit to the main branch
Benefits
References
Original prompt
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.