2022-12-06 18:02:01 -05:00
|
|
|
#! /bin/bash
|
|
|
|
|
2022-12-06 18:07:43 -05:00
|
|
|
if [[ -n "${DEBUG}" ]]
|
|
|
|
then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2019-08-20 16:48:52 -04:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2019-09-12 08:38:56 -04:00
|
|
|
|
2022-12-06 15:40:38 -05:00
|
|
|
# NOTE: These variables are needed to combat GitHub passing broken env vars
|
|
|
|
# NOTE: from the runner VM host runtime.
|
|
|
|
# Ref: https://github.com/pypa/gh-action-pypi-publish/issues/112
|
2022-12-06 20:41:32 -05:00
|
|
|
export HOME="/root" # So that `python -m site` doesn't get confused
|
2022-12-06 18:07:20 -05:00
|
|
|
export PATH="/usr/bin:${PATH}" # To find `id`
|
2022-12-06 17:55:06 -05:00
|
|
|
. /etc/profile # Makes python and other executables findable
|
2022-12-06 15:40:38 -05:00
|
|
|
export PATH="$(python -m site --user-base)/bin:${PATH}"
|
|
|
|
export PYTHONPATH="$(python -m site --user-site):${PYTHONPATH}"
|
|
|
|
|
|
|
|
|
2023-03-10 19:18:41 -05:00
|
|
|
function get-normalized-input() {
|
|
|
|
local var_name=${1}
|
|
|
|
python -c \
|
|
|
|
'
|
|
|
|
from os import getenv
|
|
|
|
from sys import argv
|
|
|
|
envvar_name = f"INPUT_{argv[1].upper()}"
|
2023-03-10 21:06:39 -05:00
|
|
|
print(
|
|
|
|
getenv(envvar_name) or getenv(envvar_name.replace("-", "_")) or "",
|
|
|
|
end="",
|
|
|
|
)
|
2023-03-10 19:18:41 -05:00
|
|
|
' \
|
|
|
|
"${var_name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INPUT_REPOSITORY_URL="$(get-normalized-input 'repository-url')"
|
|
|
|
INPUT_PACKAGES_DIR="$(get-normalized-input 'packages-dir')"
|
|
|
|
INPUT_VERIFY_METADATA="$(get-normalized-input 'verify-metadata')"
|
|
|
|
INPUT_SKIP_EXISTING="$(get-normalized-input 'skip-existing')"
|
|
|
|
INPUT_PRINT_HASH="$(get-normalized-input 'print-hash')"
|
|
|
|
|
2023-07-10 11:44:56 -04:00
|
|
|
TRUSTED_PUBLISHING_NUDGE="::warning title=Upgrade to Trusted Publishing::\
|
|
|
|
Trusted Publishers allows publishing packages to PyPI from automated \
|
|
|
|
environments like GitHub Actions without needing to use username/password \
|
|
|
|
combinations or API tokens to authenticate with PyPI. Read more: \
|
|
|
|
https://docs.pypi.org/trusted-publishers"
|
|
|
|
|
2023-03-06 15:03:34 -05:00
|
|
|
if [[ "${INPUT_USER}" == "__token__" && -z "${INPUT_PASSWORD}" ]] ; 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.
|
2023-03-22 10:41:35 -04:00
|
|
|
echo \
|
2023-04-03 08:30:44 -04:00
|
|
|
'::notice::Attempting to perform trusted publishing exchange' \
|
2023-03-29 14:22:09 -04:00
|
|
|
'to retrieve a temporary short-lived API token for authentication' \
|
2023-04-02 09:20:08 -04:00
|
|
|
"against ${INPUT_REPOSITORY_URL} due to __token__ username with no" \
|
2023-04-01 08:09:00 -04:00
|
|
|
'supplied password field'
|
2023-03-06 15:03:34 -05:00
|
|
|
INPUT_PASSWORD="$(python /app/oidc-exchange.py)"
|
2023-03-22 10:41:35 -04:00
|
|
|
elif [[ "${INPUT_USER}" == '__token__' ]]; then
|
|
|
|
echo \
|
2023-03-29 14:22:09 -04:00
|
|
|
'::notice::Using a user-provided API token for authentication' \
|
2023-03-22 10:41:35 -04:00
|
|
|
"against ${INPUT_REPOSITORY_URL}"
|
2023-07-10 12:11:56 -04:00
|
|
|
|
|
|
|
if [[ "${INPUT_REPOSITORY_URL}" =~ pypi\.org ]]; then
|
|
|
|
echo "${TRUSTED_PUBLISHING_NUDGE}"
|
|
|
|
fi
|
2023-03-22 10:41:35 -04:00
|
|
|
else
|
|
|
|
echo \
|
2023-03-29 14:22:09 -04:00
|
|
|
'::notice::Using a username + password pair for authentication' \
|
2023-06-08 08:56:32 -04:00
|
|
|
"against ${INPUT_REPOSITORY_URL}"
|
2023-07-10 12:11:56 -04:00
|
|
|
|
|
|
|
if [[ "${INPUT_REPOSITORY_URL}" =~ pypi\.org ]]; then
|
|
|
|
echo "${TRUSTED_PUBLISHING_NUDGE}"
|
|
|
|
fi
|
2023-03-06 15:03:34 -05:00
|
|
|
fi
|
2023-03-10 19:18:41 -05:00
|
|
|
|
2019-09-12 08:38:56 -04:00
|
|
|
if [[
|
|
|
|
"$INPUT_USER" == "__token__" &&
|
|
|
|
! "$INPUT_PASSWORD" =~ ^pypi-
|
|
|
|
]]
|
|
|
|
then
|
2023-02-23 11:11:08 -05:00
|
|
|
if [[ -z "$INPUT_PASSWORD" ]]; then
|
|
|
|
echo \
|
|
|
|
::warning file='# >>' PyPA publish to PyPI GHA'%3A' \
|
|
|
|
EMPTY TOKEN \
|
|
|
|
'<< ':: \
|
|
|
|
It looks like you have not passed a password or it \
|
|
|
|
is otherwise empty. Please verify that you have passed it \
|
|
|
|
directly or, preferably, through a secret.
|
|
|
|
else
|
|
|
|
echo \
|
|
|
|
::warning file='# >>' PyPA publish to PyPI GHA'%3A' \
|
|
|
|
POTENTIALLY INVALID TOKEN \
|
|
|
|
'<< ':: \
|
|
|
|
It looks like you are trying to use an API token to \
|
|
|
|
authenticate in the package index and your token value does \
|
|
|
|
not start with '"pypi-"' as it typically should. This may \
|
|
|
|
cause an authentication error. Please verify that you have \
|
|
|
|
copied your token properly if such an error occurs.
|
|
|
|
fi
|
2019-09-12 08:38:56 -04:00
|
|
|
fi
|
|
|
|
|
2020-06-28 05:43:30 -04:00
|
|
|
if ( ! ls -A ${INPUT_PACKAGES_DIR%%/}/*.tar.gz &> /dev/null && \
|
|
|
|
! ls -A ${INPUT_PACKAGES_DIR%%/}/*.whl &> /dev/null )
|
2019-09-12 11:53:53 -04:00
|
|
|
then
|
2020-06-03 19:06:14 -04:00
|
|
|
echo \
|
2020-06-03 19:23:32 -04:00
|
|
|
::warning file='# >>' PyPA publish to PyPI GHA'%3A' \
|
|
|
|
MISSING DISTS \
|
|
|
|
'<< ':: \
|
2019-09-16 07:01:16 -04:00
|
|
|
It looks like there are no Python distribution packages to \
|
2020-06-03 19:21:51 -04:00
|
|
|
publish in the directory "'${INPUT_PACKAGES_DIR%%/}/'". \
|
2020-06-03 19:06:14 -04:00
|
|
|
Please verify that they are in place should you face this \
|
|
|
|
problem.
|
2019-09-12 11:53:53 -04:00
|
|
|
fi
|
|
|
|
|
2020-06-03 11:04:52 -04:00
|
|
|
if [[ ${INPUT_VERIFY_METADATA,,} != "false" ]] ; then
|
2020-06-03 11:40:16 -04:00
|
|
|
twine check ${INPUT_PACKAGES_DIR%%/}/*
|
2020-06-02 11:08:43 -04:00
|
|
|
fi
|
|
|
|
|
2020-06-19 15:30:53 -04:00
|
|
|
TWINE_EXTRA_ARGS=
|
|
|
|
if [[ ${INPUT_SKIP_EXISTING,,} != "false" ]] ; then
|
|
|
|
TWINE_EXTRA_ARGS=--skip-existing
|
|
|
|
fi
|
|
|
|
|
2020-09-25 18:42:02 -04:00
|
|
|
if [[ ${INPUT_VERBOSE,,} != "false" ]] ; then
|
2020-09-15 00:31:21 -04:00
|
|
|
TWINE_EXTRA_ARGS="--verbose $TWINE_EXTRA_ARGS"
|
|
|
|
fi
|
2019-09-12 08:38:56 -04:00
|
|
|
|
2022-01-08 18:05:27 -05:00
|
|
|
if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; then
|
2022-01-12 23:50:40 -05:00
|
|
|
python /app/print-hash.py ${INPUT_PACKAGES_DIR%%/}
|
2022-01-07 23:12:15 -05:00
|
|
|
fi
|
|
|
|
|
2019-08-23 07:17:10 -04:00
|
|
|
TWINE_USERNAME="$INPUT_USER" \
|
|
|
|
TWINE_PASSWORD="$INPUT_PASSWORD" \
|
|
|
|
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
|
2020-06-19 15:30:53 -04:00
|
|
|
exec twine upload ${TWINE_EXTRA_ARGS} ${INPUT_PACKAGES_DIR%%/}/*
|