Is there a link to GitHub for downloading a file in the latest release of a repository?

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-page also needs to be updated.

Is there a way to get a link to a specific file of whatever the latest version of a software is?

e.g., this would be a static link:

https://github.com/USER/PROJECT/releases/download/v0.0.0/package.zip

What I'd like is something like:

https://github.com/USER/PROJECT/releases/download/latest/package.zip

NOTE: The difference between this question and GitHub latest release is that this question specifically asks for getting access to the file, not the GitHub latest release page


Solution 1:

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!

Solution 2:

Linux solution to get latest release asset download link (works only if release has one asset only)

curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4

Solution 3:

You can do an ajax request to get latest release download URL using the GitHub Releases API. It also shows when it was released and the download count:

function GetLatestReleaseInfo() {
  $.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function(release) {
    var asset = release.assets[0];
    var downloadCount = 0;
    for (var i = 0; i < release.assets.length; i++) {
      downloadCount += release.assets[i].download_count;
    }
    var oneHour = 60 * 60 * 1000;
    var oneDay = 24 * oneHour;
    var dateDiff = new Date() - new Date(asset.updated_at);
    var timeAgo;
    if (dateDiff < oneDay) {
      timeAgo = (dateDiff / oneHour).toFixed(1) + " hours ago";
    } else {
      timeAgo = (dateDiff / oneDay).toFixed(1) + " days ago";
    }
    var releaseInfo = release.name + " was updated " + timeAgo + " and downloaded " + downloadCount.toLocaleString() + " times.";
    $(".download").attr("href", asset.browser_download_url);
    $(".release-info").text(releaseInfo);
    $(".release-info").fadeIn("slow");
  });
}

GetLatestReleaseInfo();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="download" href="https://github.com/ShareX/ShareX/releases/latest">Download</a>
<p class="release-info"></p>

It is important for you to set the default button URL to the releases page (like https://github.com/ShareX/ShareX/releases/latest) so if the browser does not support ajax (or javascript) or is too slow to get the URL, the download button will still work.

When the Ajax request completes, the URL of this button will change automatically to a direct download URL.

Edit:

I also made a downloads page that shows multiple releases which you can find here: https://getsharex.com/downloads/

Source code of it: https://github.com/ShareX/sharex.github.io/blob/master/js/downloads.js

Solution 4:

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'

Solution 5:

Another Linux solution using curl and wget to download a single binary file from the latest release page

curl -s -L https://github.com/bosun-monitor/bosun/releases/latest | egrep -o '/bosun-monitor/bosun/releases/download/[0-9]*/scollector-linux-armv6' | wget --base=http://github.com/ -i - -O scollector

Explanation:

curl -s -L is to silently download the latest release HTML (after following redirect)

egrep -o '...' uses regex to find the file you want

wget --base=http://github.com/ -i - converts the relative path from the pipeline to absolute URL

and -O scollector sets the desired file name.

may be able to add -N to only download if the file is newer but S3 was giving a 403 Forbidden error.