Skip to content

Commit 5e54e78

Browse files
committed
download-gh-asset.sh improved
fix the situation when most recent release doesn't include the asset matching the patern (but some other does) notes: - the assets are included directly in /releases, no need for subsequent fetch - use -e to fail jq if the result is null - $pattern doesn't need to be anchored
1 parent 933d0d0 commit 5e54e78

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

.github/scripts/download-gh-asset.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ readonly file="${3?output filename must be given!}"
1515

1616
gh_release_json=$(fetch_json "https://api.github.com/repos/$repo/releases" \
1717
"${GITHUB_TOKEN-}" array)
18-
gh_release=$(jq -r '.[0].assets_url' "$gh_release_json")
18+
gh_path=$(jq -e -r '
19+
[ .[] # for each top‐level object
20+
| .assets[] # walk into its assets array
21+
| select(.name | test("'"$pattern"'")) # keep only those whose name matches
22+
| .browser_download_url # print just the URL
23+
][0] # include only 1st match
24+
' "$gh_release_json")
1925
rm -- "$gh_release_json"
20-
gh_path_json=$(fetch_json "$gh_release" "${GITHUB_TOKEN-}" array)
21-
gh_path=$(jq -r '[.[] | select(.name | test(".*'"$pattern"'.*"))] |
22-
.[0].browser_download_url' "$gh_path_json")
23-
rm -- "$gh_path_json"
2426
if [ -n "${GITHUB_TOKEN-}" ]; then
2527
set -- -H "Authorization: token $GITHUB_TOKEN"
2628
else

0 commit comments

Comments
 (0)