dsaltares / fetch-gh-release-asset

Github Action to download an asset from a Github release
MIT License
114 stars 70 forks source link

Missing asset ID detection does not work #28

Closed vojtapol closed 2 years ago

vojtapol commented 2 years ago

The script has an error on this line https://github.com/dsaltares/fetch-gh-release-asset/blob/master/fetch_github_asset.sh#L48

The jq command returns null when it can't find the asset which is then turned into 4 character string "null". Therefore the condition that should exit the script with 1 is never true because the string is not empty.

This can be verified on this example of empty assets array:

ASSET_ID=$(echo "{ \"assets\": [] }" | jq ".assets | map(select(.name == \"myasset.jar\"))[0].id")

if [[ -z "$ASSET_ID" ]]; then
  echo "Could not find asset ID"
  exit 1
fi

echo "Asset ID exists: $ASSET_ID"

exit 0

The script above will output Asset ID exists: null and exit with status 0.

dsaltares commented 2 years ago

Thanks for reporting. I would love to receive a PR to fix this problem.

vojtapol commented 2 years ago

Thanks for reporting. I would love to receive a PR to fix this problem.

https://github.com/dsaltares/fetch-gh-release-asset/pull/30