使用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最新发布的页面


当前回答

这是针对Linux的。

我看到了上面被接受的答案

A few years late, but I just implemented a simple redirect to support https://github.com/USER/PROJECT/releases/latest/download/package.zip. That should redirected to the latest tagged package.zip release asset. Hope it's handy!

但有评论指出,它不支持版本化文件名。

在搜索了一会儿之后,我编写了一个适用于版本化文件名的一行调用。它使用curl获取最新的文件版本,然后使用添加的重定向支持来下载最新版本的文件。

wget $'https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest/download/<FILE NAME START>-'$(curl -s https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest | grep -o -P '(?<=releases/tag/).*(?=\">)')$'<FILE NAME END>'

So it targets a file that's named like <REPO NAME>-linux64_arm-<VERSION NUMBER>.tar.gz that's on the webpage https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest after it redirects. It does this by looking for the <VERSION NUMBER> between releases/tag/ and the "> in the text that's returned from the curl call. So to be really explicit, <FILE NAME START> is the <REPO NAME>-linux64_arm- and <FILE NAME END> is the .tar.gz in the above example. Get the START and END bits by looking at what the https://github.com/<UMBRELLA PROJECT>/<REPO NAME>/releases/latest uses as its file naming scheme.

我通过模仿其他人如何使用grep和curl来创建这个,现在才学会所有这些,所以如果它做了一些我甚至无法理解的真正淘气的事情,请告诉我!我还说<UMBRELLA PROJECT>,但用户名应该能够去那里就好了。大声喊出https://stackoverflow.com/a/13245961/2403531的grep调用,https://unix.stackexchange.com/a/10264的$字符串$连接。

其他回答

Github现在支持从最新版本下载单个文件的静态链接:https://help.github.com/en/articles/linking-to-releases

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

链接到版本帮助页面确实提到了“最新版本”按钮,但这并没有给你一个下载链接。

https://github.com/reactiveui/ReactiveUI/releases/latest

为此,你需要首先获得最新的标签(如“GitHub URL For最新发布的下载文件?”所述):

latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)

curl -L https://github.com/reactiveui/ReactiveUI/releases/download/$latestTag/ReactiveUI-$latestTag.zip

另一个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禁止错误。

只需使用下面的网址下载最新版本: (以boxbilling项目中的url为例):https://api.github.com/repos/boxbilling/boxbilling/releases

以zip格式下载最新版本: https://api.github.com/repos/boxbilling/boxbilling/zipball

下载最新版本为tarball: https://api.github.com/repos/boxbilling/boxbilling/tarball

点击其中一个网址立即下载最新版本。当我写这一行时,它目前是:boxbilling-boxbilling-4.20-30-g452ad1c[.zip/.tar.gz]

更新:在我的日志文件中发现了另一个url(参考上面的例子) https://codeload.github.com/boxbilling/boxbilling/legacy.tar.gz/master

如果回购只是使用标签而不是发布——参考jQuery——基于一个URL的解决方案是行不通的。

相反,您必须查询所有标记,对它们进行排序并构造下载URL。我为语言Go和jQuery实现了这样一个解决方案:链接到Github。

也许,这对某些人有帮助。