feat: rename download-filter to download-pattern, implement pattern matching and improve action output

This commit is contained in:
fuse314 2025-12-05 21:57:04 +00:00
parent 63c75028f3
commit 1b139d6f59
3 changed files with 34 additions and 21 deletions

View file

@ -10,7 +10,7 @@ if ${VERBOSE:-false}; then set -x; fi
: ${TITLE:=$TAG}
: ${RELEASE_DIR:=dist/release}
: ${DOWNLOAD_LATEST:=false}
: ${DOWNLOAD_FILTER:=''}
: ${DOWNLOAD_PATTERN:=''}
: ${TMP_DIR:=$(mktemp -d)}
: ${GNUPGHOME:=$TMP_DIR}
: ${TEA_BIN:=$TMP_DIR/tea}
@ -20,8 +20,6 @@ if ${VERBOSE:-false}; then set -x; fi
: ${RETRY:=1}
: ${DELAY:=10}
IFS=',' read -a DL_FILTER <<< "$DOWNLOAD_FILTER"
RELEASE_NOTES_ASSISTANT_VERSION=v1.4.1 # renovate: datasource=forgejo-releases depName=forgejo/release-notes-assistant registryUrl=https://code.forgejo.org
TAG_FILE="$TMP_DIR/tag$$.json"
@ -205,18 +203,37 @@ wait_release() {
fi
}
download_asset() {
name="$1"
url="$2"
echo "Downloading asset $name"
curl --fail -s -H "Authorization: token $TOKEN" -o "$name" -L "$url"
}
maybe_download() {
if (( ${#DL_FILTER[@]} == 0 )); then
return 0
name="$1"
url="$2"
downloaded=1
if [ -z "$DOWNLOAD_PATTERN" ]; then
download_asset "$@"
downloaded=0
else
for flt in "${DL_FILTER[@]}"
do
if [[ "$flt" == "$1" ]]; then
return 0
fi
for pattern in $DOWNLOAD_PATTERN; do
case "$name" in
$pattern)
if [ $downloaded == 1 ]; then
download_asset "$@"
downloaded=0
fi
;;
esac
done
fi
return 1
if [ $downloaded == 1 ]; then
echo "Ignoring asset $name - no matching download-pattern."
fi
}
download() {
@ -233,12 +250,8 @@ download() {
api GET repos/$REPO/releases/tags/"$TAG_URL" >"$TMP_DIR"/assets.json
fi
jq --raw-output '.assets[] | "\(.browser_download_url) \(.name)"' <"$TMP_DIR"/assets.json | while read url name; do # `name` may contain whitespace, therefore, it must be last
if maybe_download "$name" ; then
url=$(echo "$url" | sed "s#/download/${TAG}/#/download/${TAG_URL}/#")
curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url"
else
echo "Ignoring $name due to filter."
fi
url=$(echo "$url" | sed "s#/download/${TAG}/#/download/${TAG_URL}/#")
maybe_download "$name" "$url"
done
)
}