Last active
August 3, 2024 16:44
-
-
Save illepic/32b8ad914f1dc80446c7e81c3be4e286 to your computer and use it in GitHub Desktop.
Download the latest release binary from a private GitHub repo. (i.e. a .tar.gz that you have manually uploaded in a GitHub release). Update OAUTH_TOKEN, OWNER, REPO, FILE_NAME with your custom values.
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 | |
# Authorize to GitHub to get the latest release tar.gz | |
# Requires: oauth token, https://help.github.com/articles/creating-an-access-token-for-command-line-use/ | |
# Requires: jq package to parse json | |
# Your oauth token goes here, see link above | |
OAUTH_TOKEN="34k234lk234lk2j3lk4j2l3k4j2kj3lk" | |
# Repo owner (user id) | |
OWNER="your-user-name" | |
# Repo name | |
REPO="the-repo-clean-name" | |
# The file name expected to download. This is deleted before curl pulls down a new one | |
FILE_NAME="file-you-are-downloading.tar.gz" | |
# Concatenate the values together for a | |
API_URL="https://$OAUTH_TOKEN:@api.github.com/repos/$OWNER/$REPO" | |
# Gets info on latest release, gets first uploaded asset id of a release, | |
# More info on jq being used to parse json: https://stedolan.github.io/jq/tutorial/ | |
ASSET_ID=$(curl $API_URL/releases/latest | jq -r '.assets[0].id') | |
echo "Asset ID: $ASSET_ID" | |
# curl does not allow overwriting file from -O, nuke | |
rm -f $FILE_NAME | |
# curl: | |
# -O: Use name provided from endpoint | |
# -J: "Content Disposition" header, in this case "attachment" | |
# -L: Follow links, we actually get forwarded in this request | |
# -H "Accept: application/octet-stream": Tells api we want to dl the full binary | |
curl -O -J -L -H "Accept: application/octet-stream" "$API_URL/releases/assets/$ASSET_ID" |
Awesome! Worked like a charm
How can we change this so we can pull the latest pre-release?
Great! Worked fine for private repo. Thanks for putting this out.
Thanks!! Worked 100%.
I wanted to download all of the files for a named release, so I rewrote this to make multiple requests and iterate over files: https://github.com/ransage/examples/blob/main/github/fetch_release_artifacts.sh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting