Skip to content

Commit 612ac72

Browse files
committed
Support multiple packages
1 parent dc232ce commit 612ac72

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ WORKDIR /app
2727
COPY LICENSE.md .
2828
COPY twine-upload.sh .
2929
COPY print-hash.py .
30-
COPY print-pkg-name.py .
30+
COPY print-pkg-names.py .
3131
COPY oidc-exchange.py .
3232

3333
RUN chmod +x twine-upload.sh

print-pkg-name.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

print-pkg-names.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pathlib
2+
import sys
3+
4+
from packaging import utils
5+
6+
7+
def debug(msg: str):
8+
print(f'::debug::{msg.title()}', file=sys.stderr)
9+
10+
11+
def safe_parse_pkg_name(file_path: pathlib.Path) -> str | None:
12+
if file_path.suffix == '.whl':
13+
try:
14+
return utils.parse_wheel_filename(file_path.name)[0]
15+
except utils.InvalidWheelFilename:
16+
debug(f'Invalid wheel filename: {file_path.name}')
17+
return None
18+
elif file_path.suffix == '.gz':
19+
try:
20+
return utils.parse_sdist_filename(file_path.name)[0]
21+
except utils.InvalidSdistFilename:
22+
debug(f'Invalid sdist filename: {file_path.name}')
23+
return None
24+
return None
25+
26+
27+
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
28+
29+
pkg_names = {safe_parse_pkg_name(f) for f in packages_dir.iterdir()}
30+
pkg_names.discard(None)
31+
32+
for p in pkg_names:
33+
print(p)

twine-upload.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ INPUT_PRINT_HASH="$(get-normalized-input 'print-hash')"
4242

4343
REPOSITORY_NAME="$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f2)"
4444
WORKFLOW_FILENAME="$(echo ${GITHUB_WORKFLOW_REF} | cut -d'/' -f5- | cut -d'@' -f1)"
45-
PACKAGE_NAME="$(python /app/print-pkg-name.py ${INPUT_PACKAGES_DIR%%/})"
45+
PACKAGE_NAMES=()
46+
while IFS='' read -r line; do PACKAGE_NAMES+=("$line"); done < <(python /app/print-pkg-names.py "${INPUT_PACKAGES_DIR%%/}")
4647

4748
PASSWORD_DEPRECATION_NUDGE="::error title=Password-based uploads disabled::\
4849
As of 2024, PyPI requires all users to enable Two-Factor \
@@ -58,18 +59,23 @@ combinations or API tokens to authenticate with PyPI. Read more: \
5859
https://docs.pypi.org/trusted-publishers"
5960

6061

61-
if [[ ! "${INPUT_REPOSITORY_URL}" =~ pypi\.org || -z "${PACKAGE_NAME}" ]] ; then
62+
if [[ ! "${INPUT_REPOSITORY_URL}" =~ pypi\.org || ${#PACKAGE_NAMES[@]} -eq 0 ]] ; then
6263
TRUSTED_PUBLISHING_MAGIC_LINK_NUDGE=""
6364
else
6465
if [[ "${INPUT_REPOSITORY_URL}" =~ test\.pypi\.org ]] ; then
6566
INDEX_URL="https://test.pypi.org"
6667
else
6768
INDEX_URL="https://pypi.org"
6869
fi
70+
ALL_LINKS=""
71+
for PACKAGE_NAME in "${PACKAGE_NAMES[@]}"; do
72+
LINK="${INDEX_URL}/manage/project/${PACKAGE_NAME}/settings/publishing/?provider=github&owner=${GITHUB_REPOSITORY_OWNER}&repository=${REPOSITORY_NAME}&workflow_filename=${WORKFLOW_FILENAME}"
73+
ALL_LINKS+="$LINK"$'\n'
74+
done
6975
TRUSTED_PUBLISHING_MAGIC_LINK_NUDGE="::warning title=Create a Trusted Publisher::\
7076
A new Trusted Publisher for the currently running publishing workflow can be created \
71-
by accessing the following link while logged-in as a maintainer of the package: \
72-
${INDEX_URL}/manage/project/${PACKAGE_NAME}/settings/publishing/?provider=github&owner=${GITHUB_REPOSITORY_OWNER}&repository=${REPOSITORY_NAME}&workflow_filename=${WORKFLOW_FILENAME}"
77+
by accessing the following link(s) while logged-in as a maintainer of the package(s): \"
78+
${ALL_LINKS}"
7379
fi
7480

7581
if [[ "${INPUT_USER}" == "__token__" && -z "${INPUT_PASSWORD}" ]] ; then

0 commit comments

Comments
 (0)