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

@ -23,7 +23,7 @@ Upload or download the assets of a release to a Forgejo instance.
| `gpg-passphrase` | <p>Passphrase of the GPG Private Key</p> | `false` | `""` |
| `download-retry` | <p>Number of times to retry if the release is not ready (default 1)</p> | `false` | `""` |
| `download-latest` | <p>Download the latest release</p> | `false` | `false` |
| `download-filter` | <p>Filter assets to download by name (Comma-separated values, e.g. `file1.htm,file3.css`)</p> | `false` | `""` |
| `download-pattern` | <p>Only download assets with matching names, e.g. `file1.htm style*.css` (default empty: download all assets)</p> | `false` | `""` |
| `verbose` | <p>Increase the verbosity level</p> | `false` | `false` |
| `override` | <p>Override an existing release by the same <code>{tag}</code></p> | `false` | `false` |
| `prerelease` | <p>Mark Release as Pre-Release</p> | `false` | `false` |

View file

@ -38,8 +38,8 @@ inputs:
download-latest:
description: 'Download the latest release'
default: false
download-filter:
description: 'Filter assets to download by name (Comma-separated values, e.g. `file1.htm,file3.css`)'
download-pattern:
description: 'Only download assets with matching names, e.g. `file1.htm style*.css` (default empty: download all assets)'
verbose:
description: 'Increase the verbosity level'
default: false
@ -82,7 +82,7 @@ runs:
export TITLE="${{ inputs.title }}"
export DOWNLOAD_LATEST="${{ inputs.download-latest }}"
export DOWNLOAD_FILTER="${{ inputs.download-filter }}"
export DOWNLOAD_PATTERN="${{ inputs.download-pattern }}"
export PRERELEASE="${{ inputs.prerelease }}"

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
)
}