Download latest GitHub release

前端 未结 8 1850
心在旅途
心在旅途 2020-12-03 03:36

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

相关标签:
8条回答
  • 2020-12-03 03:43

    As noted by @Dan Dascalescu in a comment to accepted answer, there are some projects (roughly 30%) which do not bother to file formal releases, so neither "Latest release" button nor /releases/latest API call would return useful data.

    To reliably fetch the latest release for a GitHub project, you can use lastversion.

    0 讨论(0)
  • 2020-12-03 03:44

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

    GET /repos/:owner/:repo/releases/latest
    
    0 讨论(0)
  • 2020-12-03 03:45

    As I didn't see the answer here, but it was quite helpful for me while running continuous integration tests, this one-liner that only requires you to have curl will allow to search the Github repo's releases to download the latest version

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

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

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

    0 讨论(0)
  • 2020-12-03 03:46

    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>

    0 讨论(0)
  • 2020-12-03 03:56

    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

    0 讨论(0)
  • 2020-12-03 04:00

    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

    0 讨论(0)
提交回复
热议问题