Skip to content

Instantly share code, notes, and snippets.

@mikroskeem
Created May 10, 2022 09:03
Show Gist options
  • Save mikroskeem/19e4f24dc9606b011cae12e5fb01373f to your computer and use it in GitHub Desktop.
Save mikroskeem/19e4f24dc9606b011cae12e5fb01373f to your computer and use it in GitHub Desktop.
Download named GitHub asset by release name. Requires curl, jq and coreutils.
#!/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