Download the latest version of GitHub

I want my site to have a “Download the latest version” button that will provide a link to the latest version (stored in the GitHub release ). I tried to create a release tag with the name "last", but it became difficult for me when I tried to download a new version (confusion with the date the tag was created, tag replacement, etc.). Manually updating the download links on my website is also a laborious and meticulous task. I see the only way - redirect all download buttons to some html, which, in turn, will be redirected to the latest latest version.

Please note that my site is hosted on GitHub (static hosting) pages, so I just cannot use server-side scripts to create links. Any ideas?

+16
github tags release
Jan 29 '14 at 18:13
source share
7 answers

Github now provides the “Last Release” button on the project’s release page after you create your first release .

In the above example, this button refers to https://github.com/reactiveui/ReactiveUI/releases/latest

+15
Mar 19 '14 at 13:26
source share

You do not need any scripts to create download links for the latest version. Just 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 get a link to the latest version of the download, including its version number, you can get this from get the latest API release :

 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> 
+10
Sep 01 '15 at 21:02
source share

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

 GET /repos/:owner/:repo/releases/latest 
+3
Feb 18 '15 at 21:41
source share

Perhaps you could use some client scripts and dynamically generate a link target by invoking the GitHub api using some jQuery magic?

The release API provides a way to get a list of all releases from the repository . For example, this link returns a Json formatted list from all ReactiveUI project releases .

Retrieving the first will result in the latest version.

Within this payload:

  • The html_url attribute will contain the first part of the building URL (i.e. https://github.com/{owner}/{repository}/releases/{version} ).

  • The assets array will display a list of downloaded archives. Each asset will have a name attribute.

Building the download destination URL is just a few chaining operations.

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

The resulting URL will be in the following format: https://github.com/{owner}/{repository}/releases/download/{version}/name_of_asset

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

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

+2
Jan 29 '14 at 19:59
source share

You can use the following where:

  • $ {Organization} as a user or GitHub organization
  • $ {Repository} is the name of the repository

curl -L https://api.github.com/repos/${Organization}/${Repository}/tarball > ${Repository}.tar.gz

The top level directory in the .tar.gz file has a hash of the commit in the directory name, which can be a problem if you need an automatic way to change the resulting directory and do something.

In the method below, this will be excluded and leave the files in a folder with a predictable name.

mkdir ${Repository} curl -L https://api.github.com/repos/${Organization}/${Repository}/tarball | tar -zxv -C ${Repository} --strip-components=1

+1
Apr 29 '17 at 16:21
source share

If you are using PHP, try running the code:

 function getLatestTagUrl($repository, $default = 'master') { $file = @json_decode(@file_get_contents("https://api.github.com/repos/$repository/tags", false, stream_context_create(['http' => ['header' => "User-Agent: Vestibulum\r\n"]]) )); return sprintf("https://github.com/$repository/archive/%s.zip", $file ? reset($file)->name : $default); } 

Function example

 echo '<a href="' .getLatestTagUrl('OzzyCzech/vestibulum') .'">Download</a>'; 
0
Sep 28 '14 at 19:08
source share

Since I didn’t see the answer here, but it was very useful for me when running continuous integration tests, this one-liner, which only needs to have curl, will let you search for Github repository releases to download the latest version

https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8

I use it to run PHPSTan in our repository using the following script

https://gist.github.com/rvanlaak/7491f2c4f0c456a93f90e31774300b62

0
Nov 01 '17 at 20:19 on
source share



All Articles