-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Upgrade PyPI upload workflow to use Trusted Publishing (#4589) #4611
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
Changes from all commits
c35007f
1234419
6cbb1d3
900c587
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,12 +10,16 @@ on: | |
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write # Required for PyPI trusted publishing | ||
|
|
||
| jobs: | ||
| main: | ||
| name: sdist + pure wheel | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'release' | ||
| environment: | ||
| name: release | ||
| url: https://pypi.org/p/black | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | ||
|
|
@@ -28,19 +32,19 @@ jobs: | |
| python-version: "3.13" | ||
| allow-prereleases: true | ||
|
|
||
| - name: Install latest pip, build, twine | ||
| - name: Install latest pip, build | ||
| run: | | ||
| python -m pip install --upgrade --disable-pip-version-check pip | ||
| python -m pip install --upgrade build twine | ||
| python -m pip install --upgrade build | ||
|
|
||
| - name: Build wheel and source distributions | ||
| run: python -m build | ||
|
Comment on lines
40
to
41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid building in the same job as publishing. Especially with the elevated OIDC privileges. The transitive build deps shouldn't have such level of access. #4589 links to proper examples.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call - but should we do that in a dedicated PR? We already have this setup today ...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think there's potentially a larger CI/CD cleanup PR (or PRs) that could be done here. I can help chip away at that with some PRs 🙂
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cooperlees the old setup doesn't give elevated privileges to the transitive build deps, this is quite coupled. |
||
|
|
||
| - if: github.event_name == 'release' | ||
| name: Upload to PyPI via Twine | ||
| env: | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
| run: twine upload --verbose -u '__token__' dist/* | ||
| name: Publish package distributions to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| verbose: true | ||
|
|
||
| generate_wheels_matrix: | ||
| name: generate wheels matrix | ||
|
|
@@ -91,6 +95,10 @@ jobs: | |
| name: mypyc wheels ${{ matrix.only }} | ||
| needs: generate_wheels_matrix | ||
| runs-on: ${{ matrix.os }} | ||
| if: github.event_name == 'release' | ||
| environment: | ||
| name: release | ||
| url: https://pypi.org/p/black | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
|
|
@@ -112,10 +120,11 @@ jobs: | |
| path: ./wheelhouse/*.whl | ||
|
|
||
| - if: github.event_name == 'release' | ||
| name: Upload wheels to PyPI via Twine | ||
| env: | ||
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} | ||
| run: pipx run twine upload --verbose -u '__token__' wheelhouse/*.whl | ||
| name: Publish package distributions to PyPI | ||
| uses: pypa/gh-action-pypi-publish@release/v1 | ||
| with: | ||
| packages-dir: wheelhouse/ | ||
| verbose: true | ||
|
|
||
| update-stable-branch: | ||
| name: Update stable branch | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting for the curious: the
environmentitself doesn't grant any special permissions to this job -- what it does is define an environment on GitHub's side, which can then be used to further constrain the publishing workflow (e.g. by adding required manual signoffs whenever the release workflow is triggered).The PyPI documentation has some details on that: https://docs.pypi.org/trusted-publishers/security-model/#provider-specific-considerations