Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download latest GitHub release

I'd like to have "Download Latest Version" button on my website which would represent the link to the latest release (stored at GitHub Releases). I tried to create release tag named "latest", but it became complicated when I tried to load new release (confusion with tag creation date, tag interchanging, etc.). Updating download links on my website manually is also a time-consuming and scrupulous task. I see the only way - redirect all download buttons to some html, which in turn will redirect to the actual latest release.

Note that my website is hosted at GitHub Pages (static hosting), so I simply can't use server-side scripting to generate links. Any ideas?

like image 286
kefir500 Avatar asked Jan 29 '14 18:01

kefir500


People also ask

How do I download all assets from GitHub?

To download from GitHub, you should navigate to the top level of the project (SDN in this case) and then a green "Code" download button will be visible on the right. Choose the Download ZIP option from the Code pull-down menu. That ZIP file will contain the entire repository content, including the area you wanted.

How do I download from GitHub terminal?

Open up Git Bash, type in “cd Downloads” and hit Enter. This will take you to the Downloads folder in the command window, you can also type whatever file location you want to save the file in.

What is GitHub releases Githubusercontent com?

The raw.githubusercontent.com domain is used to serve unprocessed versions of files stored in GitHub repositories. If you browse to a file on GitHub and then click the Raw link, that's where you'll go.

What is a GitHub release?

GitHub Releases are a great resource for open source projects to expand on the simple git tag concept. You can add release notes in Markdown format, and you can upload finalized assets – such as compiled executables. As a user I had the question – how do I script "download the latest release, please?"

How do I link to a release asset on GitHub?

To link directly to a download of your latest release asset, link to /owner/name/releases/latest/download/asset-name.zip. docs.github.com/en/github/administering-a-repository/releasing-projects-on-github/linking-to-releases

How to fetch the latest version of a Git tag?

# 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.

How much does it cost to join this conversation on GitHub?

Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment


4 Answers

You don't need any scripting to generate a download link for the latest release. Simply use this format:

https://github.com/:owner/:repo/zipball/:branch

Examples:

https://github.com/webix-hub/tracker/zipball/master
https://github.com/iDoRecall/selection-menu/zipball/gh-pages

If for some reason you want to obtain a link to the latest release download, including its version number, you can obtain that from the get latest release API:

GET /repos/:owner/:repo/releases/latest

Example:

$.get('https://api.github.com/repos/idorecall/selection-menu/releases/latest', function (data) {
  $('#result').attr('href', data.zipball_url);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="result">Download latest release (.ZIP)</a>
like image 151
Dan Dascalescu Avatar answered Oct 19 '22 06:10

Dan Dascalescu


Github now provides a "Latest release" button on the release page of a project, after you have created your first release.

In the example you gave, this button links to https://github.com/reactiveui/ReactiveUI/releases/latest

like image 33
dod Avatar answered Oct 19 '22 07:10

dod


Since February 18th, 2015, the GitHUb V3 release API has a get latest release API.

GET /repos/:owner/:repo/releases/latest

See also "Linking to releases".


Still, the name of the asset can be tricky.

Git-for-Windows, for instance, requires a command like:

curl -IkLs -o NUL -w %{url_effective} \
   https://github.com/git-for-windows/git/releases/latest|\
grep -o "[^/]*$"| sed "s/v//g"|\
xargs -I T echo \
  https://github.com/git-for-windows/git/releases/download/vT/PortableGit-T-64-bit.7z.exe \
  -o PortableGit-T-64-bit.7z.exe| \
sed "s/.windows.1-64/-64/g"|sed "s/.windows.\(.\)-64/.\1-64/g"|\
xargs curl -kL

The first 3 lines extract the latest version 2.35.1.windows.2
The rest will build the right URL

https://github.com/git-for-windows/git/releases/download/
        v2.35.1.windows.2/PortableGit-2.35.1.2-64-bit.7z.exe
        ^^^^^^^^^^^^^^^^^             ^^^^^^^^^
like image 3
VonC Avatar answered Oct 19 '22 07:10

VonC


Maybe could you use some client-side scripting and dynamically generate the target of the link by invoking the GitHub api, through some JQuery magic?

The Releases API exposes a way to retrieve the list of all the releases from a repository. For instance, this link return a Json formatted list of all the releases of the ReactiveUI project.

Extracting the first one would return the latest release.

Within this payload:

  • The html_url attribute will hold the first part of the url to build (ie. https://github.com/{owner}/{repository}/releases/{version}).

  • The assets array will list of the downloadable archives. Each asset will bear a name attribute

Building the target download url is only a few string operations away.

  • Insert the download/ keyword between the releases/ segment from the html_url and the version number
  • Append the name of the asset to download

Resulting url will be of the following format: https://github.com/{owner}/{repository}/releases/download/{version}/name_of_asset

For instance, regarding the Json payload from the link ReactiveUI link above, we've got html_url: "https://github.com/reactiveui/ReactiveUI/releases/5.99.0" and one asset with name: "ReactiveUI.6.0.Preview.1.zip".

As such, the download url is https://github.com/reactiveui/ReactiveUI/releases/download/5.99.0/ReactiveUI.6.0.Preview.1.zip

like image 2
nulltoken Avatar answered Oct 19 '22 05:10

nulltoken