Skip to content

Use twine's built-in Trusted Publishing support #360

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

Open
wants to merge 1 commit into
base: unstable/v1
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ COPY LICENSE.md .
COPY twine-upload.sh .
COPY print-hash.py .
COPY print-pkg-names.py .
COPY oidc-exchange.py .
COPY attestations.py .

RUN chmod +x twine-upload.sh
Expand Down
277 changes: 0 additions & 277 deletions oidc-exchange.py

This file was deleted.

12 changes: 2 additions & 10 deletions requirements/runtime.in
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
-c runtime-constraints.in # limits known broken versions

# NOTE: v6.1 is needed to support metadata v2.4 including PEP 639
# NOTE: v6.1 is needed to support metadata v2.4 including PEP 639,
# and also uploading via Trusted Publishing
twine >= 6.1

# NOTE: Used to detect an ambient OIDC credential for OIDC publishing,
# NOTE: as well as PEP 740 attestations.
id ~= 1.0

# NOTE: This is pulled in transitively through `twine`, but we also declare
# NOTE: it explicitly here because `oidc-exchange.py` uses it.
# Ref: https://github.com/di/id
requests

# NOTE: Used to generate attestations.
pypi-attestations ~= 0.0.15
sigstore ~= 3.5.1
Expand Down
2 changes: 0 additions & 2 deletions requirements/runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ hyperframe==6.1.0
# via h2
id==1.5.0
# via
# -r runtime.in
# sigstore
# twine
idna==3.10
Expand Down Expand Up @@ -104,7 +103,6 @@ readme-renderer==44.0
# via twine
requests==2.32.3
# via
# -r runtime.in
# id
# pypi-attestations
# requests-toolbelt
Expand Down
23 changes: 16 additions & 7 deletions twine-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ fi

if "${TRUSTED_PUBLISHING}" ; then
# No password supplied by the user implies that we're in the OIDC flow;
# retrieve the OIDC credential and exchange it for a PyPI API token.
# call twine with an empty password, since twine will detect it's running
# inside CI/CD, retrieve the OIDC token and exchange it for a PyPI API token.
echo "::debug::Authenticating to ${INPUT_REPOSITORY_URL} via Trusted Publishing"
INPUT_PASSWORD="$(python /app/oidc-exchange.py)"
INPUT_PASSWORD=""
elif [[ "${INPUT_USER}" == '__token__' ]]; then
echo \
'::debug::Using a user-provided API token for authentication' \
Expand All @@ -145,7 +146,8 @@ fi

if [[
"$INPUT_USER" == "__token__" &&
! "$INPUT_PASSWORD" =~ ^pypi-
! "$INPUT_PASSWORD" =~ ^pypi- &&
"${TRUSTED_PUBLISHING}" == false
]]
then
if [[ -z "$INPUT_PASSWORD" ]]; then
Expand Down Expand Up @@ -208,7 +210,14 @@ if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; the
python /app/print-hash.py ${INPUT_PACKAGES_DIR%%/}
fi

TWINE_USERNAME="$INPUT_USER" \
TWINE_PASSWORD="$INPUT_PASSWORD" \
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
exec twine upload ${TWINE_EXTRA_ARGS} ${INPUT_PACKAGES_DIR%%/}/*
# Using Trusted Publishing with twine requires not setting the password env var.
if "${TRUSTED_PUBLISHING}" ; then
TWINE_USERNAME="$INPUT_USER" \
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
exec twine upload ${TWINE_EXTRA_ARGS} ${INPUT_PACKAGES_DIR%%/}/*
else
TWINE_USERNAME="$INPUT_USER" \
TWINE_PASSWORD="$INPUT_PASSWORD" \
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
exec twine upload ${TWINE_EXTRA_ARGS} ${INPUT_PACKAGES_DIR%%/}/*
fi
Loading