Created
September 21, 2018 22:48
-
-
Save umohi/bfc7ad9a845fc10289c03d532e3d2c2f to your computer and use it in GitHub Desktop.
use curl to download release artifact from github private repository
This file contains hidden or 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
# in order to download release artifacts from github, you have to first retreive the | |
# list of asset URLs using the github repo REST API. Use the asset URL to download | |
# the artifact as a octet-stream data stream. You will need to get an access token | |
# from "settings -> developer settings -> personal access tokens" on the github UI | |
#!/bin/bash -e | |
owner="MY_ORG_NAME" | |
repo="MY_REPO_NAME" | |
tag="ARTIFACT_TAG" | |
artifact="ARTIFACT_NAME" | |
token="MY_ACCESS_TOKEN" | |
list_asset_url="https://api.github.com/repos/${owner}/${repo}/releases/tags/${tag}?access_token=${token}" | |
# get url for artifact with name==$artifact | |
asset_url=$(curl "${list_asset_url}" | jq ".assets[] | select(.name==\"${artifact}\") | .url" | sed 's/\"//g') | |
# download the artifact | |
curl -vLJO -H 'Accept: application/octet-stream' \ | |
"${asset_url}?access_token=${token}" |
Based on this work, I created a dedicated script:
https://github.com/thenets/bash-helpers/blob/main/scripts/github-release-downloader.sh
Example of usage:
$ ./github-release-downloader.sh \
gohugoio \
hugo \
"_linux-amd64.tar.gz"
>> [INFO ] Parameters:
>> [INFO ] GITHUB_ORG : gohugoio
>> [INFO ] GITHUB_REPO : hugo
>> [INFO ] SEARCH_PATTERN : _linux-amd64.tar.gz
>> [INFO ] [get_releases] checking https://api.github.com/repos/gohugoio/hugo/releases
>> [INFO ] [get_latest_release] latest release identified: name=v0.134.2 id=174307672
>> [INFO ] [get_release_assets] release=v0.134.2 - total_of_assets=22
>> [INFO ] [search_asset_by_name] found hugo_0.134.2_linux-amd64.tar.gz
>> [INFO ] [search_asset_by_name] https://github.com/gohugoio/hugo/releases/download/v0.134.2/hugo_0.134.2_linux-amd64.tar.gz
>> [INFO ] Downloading...
>> $ curl --progress-bar -o /home/user/path/hugo_0.134.2_linux-amd64.tar.gz https://github.com/gohugoio/hugo/releases/download/v0.134.2/hugo_0.134.2_linux-amd64.tar.gz
>> [SUCCESS] Saved on: /home/user/path/hugo_0.134.2_linux-amd64.tar.gz
Based on @thenets work, I extended his script with GITHUB_TOKEN support, please check - https://gist.github.com/frozer/6dcdf9a901f32688c4e89163a65b17bd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Workflow Artifacts
I arrived here from Google looking for how to download GH Workflow Artifacts.
This will get the most recent.
This is what is used to select the first listed (latest).
You can also filter on
.artifacts[]
to fetch by workflow run id, etc.The payload from
.artifacts[]
looks like:Which should be useful to get the artifact you're looking for.