Skip to content

Commit 7d02474

Browse files
committed
Support multiple packages
1 parent fc7df7c commit 7d02474

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
COPY attestations.py .
3333

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
@@ -43,7 +43,8 @@ INPUT_ATTESTATIONS="$(get-normalized-input 'attestations')"
4343

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

4849
PASSWORD_DEPRECATION_NUDGE="::error title=Password-based uploads disabled::\
4950
As of 2024, PyPI requires all users to enable Two-Factor \
@@ -68,18 +69,23 @@ The workflow was run with 'attestations: true' input, but the specified \
6869
repository URL does not support PEP 740 attestations. As a result, the \
6970
attestations input is ignored."
7071

71-
if [[ ! "${INPUT_REPOSITORY_URL}" =~ pypi\.org || -z "${PACKAGE_NAME}" ]] ; then
72+
if [[ ! "${INPUT_REPOSITORY_URL}" =~ pypi\.org || ${#PACKAGE_NAMES[@]} -eq 0 ]] ; then
7273
TRUSTED_PUBLISHING_MAGIC_LINK_NUDGE=""
7374
else
7475
if [[ "${INPUT_REPOSITORY_URL}" =~ test\.pypi\.org ]] ; then
7576
INDEX_URL="https://test.pypi.org"
7677
else
7778
INDEX_URL="https://pypi.org"
7879
fi
80+
ALL_LINKS=""
81+
for PACKAGE_NAME in "${PACKAGE_NAMES[@]}"; do
82+
LINK="${INDEX_URL}/manage/project/${PACKAGE_NAME}/settings/publishing/?provider=github&owner=${GITHUB_REPOSITORY_OWNER}&repository=${REPOSITORY_NAME}&workflow_filename=${WORKFLOW_FILENAME}"
83+
ALL_LINKS+="$LINK"$'\n'
84+
done
7985
TRUSTED_PUBLISHING_MAGIC_LINK_NUDGE="::warning title=Create a Trusted Publisher::\
8086
A new Trusted Publisher for the currently running publishing workflow can be created \
81-
by accessing the following link while logged-in as a maintainer of the package: \
82-
${INDEX_URL}/manage/project/${PACKAGE_NAME}/settings/publishing/?provider=github&owner=${GITHUB_REPOSITORY_OWNER}&repository=${REPOSITORY_NAME}&workflow_filename=${WORKFLOW_FILENAME}"
87+
by accessing the following link(s) while logged-in as a maintainer of the package(s): \"
88+
${ALL_LINKS}"
8389
fi
8490

8591
[[ "${INPUT_USER}" == "__token__" && -z "${INPUT_PASSWORD}" ]] \

0 commit comments

Comments
 (0)