使用GitHub的发布功能,可以提供一个链接来下载已发布软件的特定版本。然而,每次发布时,gh-page也需要更新。

有没有一种方法可以获取到软件最新版本的特定文件的链接?

例如,这将是一个静态链接:

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

我想要的是:

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

注意:这个问题和 GitHub最新发布 这个问题特别要求访问文件, 而不是GitHub最新发布的页面


当前回答

我想从README下载版本。Md文件在存储库描述中。在那里,我无法执行JavaScript。

我可以为我所有的存储库在README文件或github页面中添加这样的链接:

https://niccokunzmann.github.io/download_latest/ <用户名> / <库> / <文件> 从存储库下载最新的发布文件。 https://niccokunzmann.github.io/download_latest/ <文件> 这是因为JavaScript引用器已经设置好,要下载的存储库是通过document.referrer确定的。因此,该链接也适用于分叉。

你可以在这里找到源代码,fork或使用我的repo。

其他回答

另一个Linux解决方案使用curl和wget从最新版本页面下载单个二进制文件

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

解释:

curl -s -L是无声地下载最新版本的HTML(在执行重定向之后)

鹭-o '…'使用正则表达式找到你想要的文件

wget——base=http://github.com/ -i将管道的相对路径转换为绝对URL

和-O sccollector设置所需的文件名。

如果文件更新,可以添加-N到下载,但S3给出了403禁止错误。

使用curl和jq从命令行检索最新版本的第一个文件:

curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | \
  jq --raw-output '.assets[0] | .browser_download_url'

在PHP -重定向到最新版本下载。简单地放在你的网络空间

<?php

/**
 * Download latest release from github release articats
 * License: Public Domain
 */

define('REPO', 'imi-digital/iRobo');

$opts = [
    'http' => [
        'method' => 'GET',
        'header' => [
            'User-Agent: PHP'
        ]
    ]
];

$context = stream_context_create($opts);

$releases = file_get_contents('https://api.github.com/repos/' . REPO . '/releases', false, $context);
$releases = json_decode($releases);

$url = $releases[0]->assets[0]->browser_download_url;

header('Location: ' . $url);

简单的命令,工作和下载最新的包可用的github发行版

curl -ks https://api.github.com/repos/<reponame>/releases/latest | grep "browser_download_url.*linux-amd64.tar.gz" | cut -d : -f 2,3 | tr -d \" | xargs wget --no-check-certificate

Reponame -替换它与github repo与可用的包 释放 可以根据需要替换包的.tar.gz类型。除 . zip等

如果你只想使用curl,你可以尝试使用-w '%{url_effective}',它会在重定向链之后打印URL(如果你使用-L调用它,后面跟着curl)。举个例子

curl -sLo /dev/null -w '%{url_effective}' https://github.com/github-tools/github/releases/latest

输出https://github.com/github-tools/github/releases/tag/v3.1.0。