Created
May 10, 2022 09:03
-
-
Save mikroskeem/19e4f24dc9606b011cae12e5fb01373f to your computer and use it in GitHub Desktop.
Download named GitHub asset by release name. Requires curl, jq and coreutils.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
: "${GH_TOKEN}" | |
repo="${1}" | |
version="${2}" | |
name="${3}" | |
asset_url="$(curl -s -H "Accept: application/vnd.github.v3+json" -u "token:${GH_TOKEN}" "https://api.github.com/repos/${repo}/releases/tags/${version}" \ | |
| jq --arg assetName "${name}" -r '.assets[] | select(.name == $assetName).url' \ | |
| head -1)" | |
if [ -z "${asset_url}" ]; then | |
echo "Could not find asset '${name}' for release '${version}' in '${repo}'" | |
exit 1 | |
fi | |
curl -L -H "Accept: application/octet-stream" -u "token:${GH_TOKEN}" "${asset_url}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment