GitHub URL for latest release of the _download file_?

For releases that do not contain the version number or other variable content in their assets' names, you can use a URL of the format:

https://github.com/owner/repository/releases/latest/download/ASSET.ext

As per the docs:

If you'd like to link directly to a download of your latest release asset you can link to /owner/name/releases/latest/download/asset-name.zip.


I use this to get the download URLs in PowerShell 5+ (replace ACCOUNT & REPO)

Invoke-RestMethod -uri  https://api.github.com/repos/ACCOUNT/REPO/releases/latest | select -ExpandProperty assets | select -expand browser_download_url 

Note if they have more than one package this will be a list. If you want to pick a certain one find a unique part of the name i.e. win for Windows and use: (replace ACCOUNT, REPO & SELECTOR)

Invoke-RestMethod -uri  https://api.github.com/repos/ACCOUNT/REPO/releases/latest | select -ExpandProperty assets | ? { $_.name.Contains("SELECTOR")} | select -expand browser_download_url

As a bonus if you assign the above to a variable you can then grab the file and extract it with the following (assuming you assign to $uri):

Invoke-WebRequest $uri -OutFile "release.zip"
Expand-Archive .\release.zip

In PowerShell 6+ this should work on other platforms than Windows.


Here is a way to do it w/o Github if you have a single download in the release:

wget $(curl -s https://api.github.com/repos/USERNAME/REPONAME/releases/latest | grep 'browser_' | cut -d\" -f4)

It is pretty easy (though not pretty), and of course you can swap out wget for another curl call if you want to pipe it to something.

Basically, the curl call nets you a JSON structure, and I'm just using basic shell utilities to extract the URL to the download.


Very interesting, I haven't noticed a "latest" tag in GitHub-releases yet. As i now figured out, they're given away if you're using the "pre-release"-capabilities of GitHubs release-system. But i don't know any way to access binaries via a latest-path.

I would like to suggest you using git (which is available in your travis-vm) to download the latest tag.

Like Julien Renault describes in his blog post, you will be able to checkout the latest tag in the repository like this:

# this step should be optional
git fetch --tags

latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $latestTag

This solution is based on the assumption that the latest tag is also the latest version.

Tags:

Github