Download latest GitHub release

前端 未结 8 1851
心在旅途
心在旅途 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 04:05

    If you using PHP try follow 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 usage example

    echo '<a href="' .getLatestTagUrl('OzzyCzech/vestibulum') .'">Download</a>';
    
    0 讨论(0)
  • 2020-12-03 04:08

    You can use the following where:

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

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

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

    The method below will strip this out, 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

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