feat: new parameter download-pattern to only download matching asset files #109

Open
fuse314 wants to merge 4 commits from fuse314/forgejo-release:feature/download-filter into main
First-time contributor

closes #103

closes #103
fix: syntax error
Some checks failed
/ integration (pull_request) Has been cancelled
/ tests (pull_request) Has been cancelled
63c75028f3
action.yml Outdated
@ -38,6 +38,8 @@ inputs:
download-latest:
description: 'Download the latest release'
default: false
download-filter:
Contributor

To match download-artifact, a better solution might be to do pattern (globs) and name (single artifact)

To match download-artifact, a better solution might be to do `pattern` (globs) and `name` (single artifact)
Author
First-time contributor

good point. Renamed parameter to download-pattern.

good point. Renamed parameter to `download-pattern`.
fuse314 marked this conversation as resolved
@ -19,6 +20,8 @@ if ${VERBOSE:-false}; then set -x; fi
: ${RETRY:=1}
: ${DELAY:=10}
IFS=',' read -a DL_FILTER <<< "$DOWNLOAD_FILTER"
Contributor

<<< is not POSIX compliant, nor is read -a. iirc POSIX handles newlines in for loops, but if not, you can do a simple tr to fix that. Comma separation should be avoided since users will input as:

pattern: pattern/1/* pattern2*

Or:

pattern: |
    pattern/1/*
    pattern2*
`<<<` is not POSIX compliant, nor is `read -a`. iirc POSIX handles newlines in for loops, but if not, you can do a simple tr to fix that. Comma separation should be avoided since users will input as: `pattern: pattern/1/* pattern2*` Or: ```yaml pattern: | pattern/1/* pattern2* ```
fuse314 marked this conversation as resolved
@ -205,0 +216,4 @@
fi
done
fi
return 1
Contributor

Please avoid arrays and [[ if possible.

download_asset() {
    name="$1"
    url="$2"
    
    curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url"
}

maybe_download() {
    name="$1"
    url="$2"
    
    if [ -z "$DL_FILTER" ]; then
        download_asset "$@"
    else
        for filt in $DL_FILTER; do
            case "$name" in
                $filt) download_asset "$@" ;;
            esac
        done
    fi
}
Please avoid arrays and `[[` if possible. ```sh download_asset() { name="$1" url="$2" curl --fail -H "Authorization: token $TOKEN" -o "$name" -L "$url" } maybe_download() { name="$1" url="$2" if [ -z "$DL_FILTER" ]; then download_asset "$@" else for filt in $DL_FILTER; do case "$name" in $filt) download_asset "$@" ;; esac done fi } ```
Author
First-time contributor

Amazing! I did not know that case implements pattern-matching!
So much simpler.

Amazing! I did not know that case implements pattern-matching! So much simpler.
fuse314 marked this conversation as resolved
@ -218,3 +235,2 @@
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
Contributor

If you use the previous function, we can just do maybe_download "$name" "$url"

If you use the previous function, we can just do `maybe_download "$name" "$url"`
fuse314 marked this conversation as resolved
feat: rename download-filter to download-pattern, implement pattern matching and improve action output
Some checks failed
/ integration (pull_request) Has been cancelled
/ tests (pull_request) Has been cancelled
1b139d6f59
@ -205,0 +223,4 @@
for pattern in $DOWNLOAD_PATTERN; do
case "$name" in
$pattern)
if [ $downloaded == 1 ]; then
Contributor

== is a ksh extension. Luckily, = does the same thing and is POSIX compliant 😁

Btw, the downloaded thing may not even be necessary. You can just return when a download is called, and I don't think mentioning ignored files is actually necessary? or maybe it is. I say we leave that to the actual maintainers and not some random weirdo like me :P

`==` is a ksh extension. Luckily, = does the same thing and is POSIX compliant 😁 Btw, the downloaded thing may not even be necessary. You can just `return` when a download is called, and I don't think mentioning ignored files is actually necessary? or maybe it is. I say we leave that to the actual maintainers and not some random weirdo like me :P
fuse314 marked this conversation as resolved
fuse314 changed title from feat: new parameter download-filter to only download some asset files to feat: new parameter download-pattern to only download matching asset files 2025-12-10 05:01:10 +00:00
fix: syntax
Some checks failed
/ integration (pull_request) Has been cancelled
/ tests (pull_request) Has been cancelled
60d39d774b
Some checks failed
/ integration (pull_request) Has been cancelled
Required
Details
/ tests (pull_request) Has been cancelled
Required
Details
This pull request has changes conflicting with the target branch.
  • action.yml
Some workflows are waiting to be reviewed.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/download-filter:fuse314-feature/download-filter
git switch fuse314-feature/download-filter
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
actions/forgejo-release!109
No description provided.