diff --git a/README.md b/README.md index 0758032..7bfd8d6 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Upload or download the assets of a release to a Forgejo instance. | `gpg-passphrase` |
Passphrase of the GPG Private Key
| `false` | `""` | | `download-retry` |Number of times to retry if the release is not ready (default 1)
| `false` | `""` | | `download-latest` |Download the latest release
| `false` | `false` | +| `download-filter` |Filter assets to download by name (Comma-separated values, e.g. `file1.htm,file3.css`)
| `false` | `""` | | `verbose` |Increase the verbosity level
| `false` | `false` | | `override` |Override an existing release by the same {tag}
Mark Release as Pre-Release
| `false` | `false` | diff --git a/action.yml b/action.yml index f6725c7..1cbf54e 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +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`)' verbose: description: 'Increase the verbosity level' default: false @@ -80,6 +82,7 @@ runs: export TITLE="${{ inputs.title }}" export DOWNLOAD_LATEST="${{ inputs.download-latest }}" + export DOWNLOAD_FILTER="${{ inputs.download-filter }}" export PRERELEASE="${{ inputs.prerelease }}" diff --git a/forgejo-release.sh b/forgejo-release.sh index 5ba1c6e..4d9af04 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -10,6 +10,7 @@ if ${VERBOSE:-false}; then set -x; fi : ${TITLE:=$TAG} : ${RELEASE_DIR:=dist/release} : ${DOWNLOAD_LATEST:=false} +: ${DOWNLOAD_FILTER:=''} : ${TMP_DIR:=$(mktemp -d)} : ${GNUPGHOME:=$TMP_DIR} : ${TEA_BIN:=$TMP_DIR/tea} @@ -19,6 +20,8 @@ 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" @@ -202,6 +205,20 @@ wait_release() { 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() { setup_api ( @@ -216,8 +233,12 @@ 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 - url=$(echo "$url" | sed "s#/download/${TAG}/#/download/${TAG_URL}/#") - curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url" + 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 done ) }