diff --git a/README.md b/README.md index 7bfd8d6..fd1b669 100644 --- a/README.md +++ b/README.md @@ -23,7 +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` | `""` | +| `download-pattern` |Only download assets with matching names, e.g. `file1.htm style*.css` (default empty: download all assets)
| `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 1cbf54e..08acd7f 100644 --- a/action.yml +++ b/action.yml @@ -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 }}" diff --git a/forgejo-release.sh b/forgejo-release.sh index 30dfd3f..a39b7e1 100755 --- a/forgejo-release.sh +++ b/forgejo-release.sh @@ -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 ) }