Using GitHub\'s Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-pag
A few years late, but I just implemented a simple redirect to support https://github.com/USER/PROJECT/releases/latest/download/package.zip
. That should redirected to the latest tagged package.zip
release asset. Hope it's handy!
Github now supports static links for downloading individual files from the latest release: https://help.github.com/en/articles/linking-to-releases
https://github.com/USER/PROJECT/releases/latest/download/package.zip
Like most visiting this question, I was absolutely frustrated with finding a way to fully automate download of the LATEST versioned release or a repo in Github. The benefit of this solution is that you do not have to specify any release or tag number- it will just grab the LATEST.
I conducted my testing using the following Github user & repo:
"f1linux" = Github User
"pi-ap" = Repo
The arbitrary directory name the repo is saved to is set in:
--one-top-level="pi-ap"
Using Firefox's "Web Developer" tools (3 bars in upper right corner), in the "Network" section I found https://api.github.com
was redirecting to https://codeload.github.com
, so by piping the curl
to tar
I was able to grab the latest versioned repo and save it to a predictable name so it could be operated on:
curl https://codeload.github.com/f1linux/pi-ap/legacy.tar.gz/master | tar xzvf - --one-top-level="pi-ap" --strip-components 1
After I achieved fully-automated downloads of the latest versioned release using a DIRECT URL, I turned my attention to achieving the same with Github's redirection:
curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1
However, please note as per Von's comment below that INDIRECT is the preferred method
To ensure my results were reproducible to other versioned Github repos, the same tests were successfully executed for Digital Ocean's doctl
api toolkit (which is what started the whole exercise actually!):
Both DIRECT and INDIRECT work using the same form as above, just changing the username & repo:
curl https://codeload.github.com/digitalocean/doctl/legacy.tar.gz/master | tar xzvf - --one-top-level="doctl" --strip-components 1
curl -L https://api.github.com/repos/digitalocean/doctl/tarball | tar xzvf - --one-top-level="doctl" --strip-components 1
A solution using (an inner) wget to get the HTML content, filter it for the zip file (with egrep) and then download the zip file (with the outer wget).
wget https://github.com/$(wget https://github.com/<USER>/<PROJECT>/releases/latest -O - | egrep '/.*/.*/.*zip' -o)
If you want to use just curl
you can try with -w '%{url_effective}'
that prints the URL after a redirect chain (followed by curl if you invoke it with -L
). So, for example
curl -sLo /dev/null -w '%{url_effective}' https://github.com/github-tools/github/releases/latest
outputs https://github.com/github-tools/github/releases/tag/v3.1.0
.
From the command line using curl
and jq
, retrieves the first file of the latest release:
curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | \
jq --raw-output '.assets[0] | .browser_download_url'