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


当前回答

根据2018-05-23的GitHub支持,不可能

联系support@github.com 2018-05-23,留言:

你能否确认一下,目前除了干扰API,没有别的办法了?

他们回答说:

谢谢你伸出援手。我们建议使用API来获取最新的版本,因为这种方法是稳定的,有文档记录的,并且不会很快改变: https://developer.github.com/v3/repos/releases/#get-the-latest-release

我也会继续关注:https://github.com/isaacs/github/issues/658

没有任何依赖的Python解决方案

健壮、便携:

#!/usr/bin/env python3

import json
import urllib.request

_json = json.loads(urllib.request.urlopen(urllib.request.Request(
    'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases/latest',
     headers={'Accept': 'application/vnd.github.v3+json'},
)).read())
asset = _json['assets'][0]
urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])

参见:

在Python中获取HTTP GET的最快方法是什么? 基本的http文件下载和保存到磁盘在python?

还要考虑预发行版

/latest看不到预发布版本,但是很容易做到,因为/releases首先显示最新的版本:

#!/usr/bin/env python3

import json
import urllib.request

_json = json.loads(urllib.request.urlopen(urllib.request.Request(
    'https://api.github.com/repos/cirosantilli/linux-kernel-module-cheat/releases',
     headers={'Accept': 'application/vnd.github.v3+json'},
)).read())
asset = _json[0]['assets'][0]
urllib.request.urlretrieve(asset['browser_download_url'], asset['name'])

其他回答

简单的命令,工作和下载最新的包可用的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等

使用(内部)wget获取HTML内容,过滤zip文件(使用egrep),然后下载zip文件(使用外部wget)的解决方案。

wget https://github.com/$(wget https://github.com/<USER>/<PROJECT>/releases/latest -O - | egrep '/.*/.*/.*zip' -o)

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

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

晚了几年,但我只是实现了一个简单的重定向到支持https://github.com/USER/PROJECT/releases/latest/download/package.zip。这应该重定向到最新的带标签的package.zip发行资产。希望它很方便!

只需使用下面的网址下载最新版本: (以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