feat: new parameter download-filter

This commit is contained in:
fuse314 2025-12-01 20:33:51 +00:00
parent e132301eee
commit a17d224780
3 changed files with 27 additions and 2 deletions

View file

@ -23,6 +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` | `""` | | `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-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-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` | `""` |
| `verbose` | <p>Increase the verbosity level</p> | `false` | `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` | | `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` | | `prerelease` | <p>Mark Release as Pre-Release</p> | `false` | `false` |

View file

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

View file

@ -10,6 +10,7 @@ if ${VERBOSE:-false}; then set -x; fi
: ${TITLE:=$TAG} : ${TITLE:=$TAG}
: ${RELEASE_DIR:=dist/release} : ${RELEASE_DIR:=dist/release}
: ${DOWNLOAD_LATEST:=false} : ${DOWNLOAD_LATEST:=false}
: ${DOWNLOAD_FILTER:=''}
: ${TMP_DIR:=$(mktemp -d)} : ${TMP_DIR:=$(mktemp -d)}
: ${GNUPGHOME:=$TMP_DIR} : ${GNUPGHOME:=$TMP_DIR}
: ${TEA_BIN:=$TMP_DIR/tea} : ${TEA_BIN:=$TMP_DIR/tea}
@ -19,6 +20,8 @@ if ${VERBOSE:-false}; then set -x; fi
: ${RETRY:=1} : ${RETRY:=1}
: ${DELAY:=10} : ${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 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" TAG_FILE="$TMP_DIR/tag$$.json"
@ -202,6 +205,20 @@ wait_release() {
fi fi
} }
maybe_download() {
if (( ${#DL_FILTER[@]} == 0 )); then
return 0
else
for flt in "${DL_FILTER[@]}"
do
if [[ "$flt" == "$1"]]; then
return 0
fi
done
fi
return 1
}
download() { download() {
setup_api setup_api
( (
@ -216,8 +233,12 @@ download() {
api GET repos/$REPO/releases/tags/"$TAG_URL" >"$TMP_DIR"/assets.json api GET repos/$REPO/releases/tags/"$TAG_URL" >"$TMP_DIR"/assets.json
fi 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 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
url=$(echo "$url" | sed "s#/download/${TAG}/#/download/${TAG_URL}/#") if maybe_download "$name" ; then
curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url" 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
done done
) )
} }