-
Notifications
You must be signed in to change notification settings - Fork 13
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
[WIP] Add optional pypi release job inside the reusable tox workflow #243
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,11 +54,16 @@ on: | |
description: Command to run after test commands. | ||
required: false | ||
type: string | ||
publish_pypi: | ||
default: false | ||
description: Whether to publish to PyPI | ||
required: false | ||
type: boolean | ||
# keep permissions at top level because this is a composite workflow | ||
permissions: | ||
checks: read | ||
contents: read | ||
id-token: write | ||
id-token: write # release | ||
packages: write # some tox environments might produce containers | ||
pull-requests: write # allow codenotify to comment on pull-request | ||
env: | ||
|
@@ -247,3 +252,44 @@ jobs: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
# https://github.com/sourcegraph/codenotify/issues/19 | ||
continue-on-error: true | ||
|
||
pypi: | ||
name: release ${{ github.event.ref }} | ||
# if: github.ref_type == 'tag' || inputs.publish_pypi == 'true' | ||
needs: check | ||
environment: release # keep it here to allow users to prompt for release | ||
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. I finally updated PyPI and its docs to suggest using |
||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Switch to using Python 3.12 by default | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
- name: Install tox | ||
run: python3 -m pip install --user "tox>=4.0.0" | ||
|
||
- name: Check out src from Git | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # needed by setuptools-scm | ||
|
||
- name: Build dists | ||
run: python3 -m tox -e pkg | ||
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. Following the previous comment, building within the publishing job with OIDC is a popular example of letting the possibility of being impersonated over OIDC into your life. Don't do this, it's not supported. |
||
|
||
- name: Fail if secrets are not available | ||
env: | ||
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
if [ -z "${PYPI_API_TOKEN}" ]; then | ||
echo "PYPI_API_TOKEN is not set, please add it to your repository environment named 'release'." | ||
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. I think the current environment name is available in the context vars somewhere, it's usually better than hardcoding. |
||
exit 1 | ||
fi | ||
|
||
- name: Publish to pypi.org | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
if: inputs.publish_pypi | ||
with: | ||
# trusted publishing is not possible with shared workflows due to | ||
# https://github.com/pypi/warehouse/issues/11096 so we need to use | ||
# secrets instead. | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
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.
Setting the OIDC privilege is highly discouraged because giving such elevated privileges to random scripts like transitive build dependencies, testing automation and other things can lead to privilege elevation and impersonation attacks and who knows what else. For this reason, I emphasize this in all the docs for
pypi-publish
that are in my reach. We even managed to update GitHub's own PyPI+OIDC doc to show that it's only acceptable in the publishing job that only downloads the dists and callspypi-publish
but nothing else.So whenever I see
id-token: write
anywhere outside of the narrow scope of a single job doing this single thing, I know immediately that it's a security vulnerability.