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

support PyPI trusted publishers #18

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Other features (supported by both) include:

- Supports checking built files
- Supports skipping existing uploads
- Supports OIDC PyPI trusted publishing

## Inputs

Expand All @@ -54,7 +55,11 @@ inputs:
default: __token__
password:
description: PyPI password or API token
required: true
required: false
registry_domain:
description: PyPI trusted publisher URL
required: false
default: https://upload.pypi.org
requirements:
description: Packages to `pip install` before building
default: twine wheel build
Expand Down
13 changes: 12 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ inputs:
default: __token__
password:
description: PyPI password or API token
required: true
required: false
registry_domain:
description: PyPI trusted publisher URL
required: false
default: https://upload.pypi.org
requirements:
description: Packages to `pip install` before building
required: false
Expand Down Expand Up @@ -121,6 +125,12 @@ runs:
TWINE_OPTS="$TWINE_OPTS --skip-existing"
fi
python -m pip install twine
if [[ -z "$TWINE_PASSWORD" ]]; then
# vis https://docs.pypi.org/trusted-publishers/using-a-publisher/#the-manual-way
oidc_token=$(curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=pypi" | jq -r '.value')
export TWINE_PASSWORD=$(curl https://pypi.org/_/oidc/mint-token -d "{\"token\": \"${oidc_token}\"}" | jq -r '.token')
echo "::add-mask::$TWINE_PASSWORD"
fi
python -m twine upload $TWINE_OPTS "${DIST}"/*
fi
pushd "$DIST"
Expand All @@ -138,6 +148,7 @@ runs:
TWINE_REPOSITORY_URL: ${{ inputs.url }}
TWINE_USERNAME: ${{ inputs.user }}
TWINE_PASSWORD: ${{ inputs.password }}
INPUT_REGISTRY_DOMAIN: ${{ inputs.registry_domain }}
branding:
icon: upload-cloud
color: blue
Loading