최신 리포지토리 릴리스에서 파일을 다운로드하기위한 GitHub에 대한 링크가 있습니까?
GitHub의 Release 기능을 사용 하면 게시 된 소프트웨어의 특정 버전을 다운로드 할 수있는 링크를 제공 할 수 있습니다. 그러나 릴리스 할 때마다 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 최신 릴리스 페이지가 아니라 파일에 대한 액세스를 요청한다는 것입니다
몇 년 늦었지만 지원을위한 간단한 리디렉션을 구현했습니다 https://github.com/USER/PROJECT/releases/latest/download/package.zip
. 최신 태그가 지정된 package.zip
릴리스 자산으로 리디렉션되어야합니다 . 그것이 편리하기를 바랍니다!
최신 릴리스 자산 다운로드 링크를 얻는 Linux 솔루션 (릴리스에 하나의 자산 만있는 경우에만 작동)
curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4
GitHub Releases API를 사용하여 최신 릴리스 다운로드 URL을 얻기 위해 ajax 요청을 수행 할 수 있습니다 . 또한 출시시기와 다운로드 횟수도 표시됩니다.
function GetLatestReleaseInfo() {
$.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function(release) {
var asset = release.assets[0];
var downloadCount = 0;
for (var i = 0; i < release.assets.length; i++) {
downloadCount += release.assets[i].download_count;
}
var oneHour = 60 * 60 * 1000;
var oneDay = 24 * oneHour;
var dateDiff = new Date() - new Date(asset.updated_at);
var timeAgo;
if (dateDiff < oneDay) {
timeAgo = (dateDiff / oneHour).toFixed(1) + " hours ago";
} else {
timeAgo = (dateDiff / oneDay).toFixed(1) + " days ago";
}
var releaseInfo = release.name + " was updated " + timeAgo + " and downloaded " + downloadCount.toLocaleString() + " times.";
$(".download").attr("href", asset.browser_download_url);
$(".release-info").text(releaseInfo);
$(".release-info").fadeIn("slow");
});
}
GetLatestReleaseInfo();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="download" href="https://github.com/ShareX/ShareX/releases/latest">Download</a>
<p class="release-info"></p>
브라우저가 아약스 (또는 자바 스크립트)를 지원하지 않거나 너무 느릴 경우 기본 버튼 URL을 릴리스 페이지 ( https://github.com/ShareX/ShareX/releases/latest 등 ) 로 설정하는 것이 중요 합니다. URL을 얻으면 다운로드 버튼이 계속 작동합니다.
When the Ajax request completes, the URL of this button will change automatically to a direct download URL.
Edit:
I also made a downloads page that shows multiple releases which you can find here: https://getsharex.com/downloads/
Source code of it: https://github.com/ShareX/sharex.github.io/blob/master/js/downloads.js
From the command line using curl
and jq
, retrieves the first file of the latest release:
curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | \
jq --raw-output '.assets[0] | .browser_download_url'
Another Linux solution using curl and wget to download a single binary file from the latest release page
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
Explanation:
curl -s -L
is to silently download the latest release HTML (after following redirect)
egrep -o '...'
uses regex to find the file you want
wget --base=http://github.com/ -i -
converts the relative path from the pipeline to absolute URL
and -O scollector
sets the desired file name.
may be able to add -N
to only download if the file is newer but S3 was giving a 403 Forbidden error.
As noted previously, jq is useful for this and other REST APIs.
tl;dr - more details below
Assuming you want the macOS release:
URL=$( curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
| jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url' )
curl -LO "$URL"
Solution for atom releases
Note each repo can have different ways of providing the desired artifact, so I will demonstrate for a well-behaved one like atom.
Get the names of the assets published
curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
| jq -r '.assets[] | .name'
atom-1.15.0-delta.nupkg
atom-1.15.0-full.nupkg
atom-amd64.deb
...
Get the download URL for the desired asset
Below atom-mac is my desired asset via jq's select(.name=="atom-mac.zip")
curl -s "https://api.github.com/repos/atom/atom/releases/latest" \
| jq -r '.assets[] | select(.name=="atom-mac.zip") | .browser_download_url'
https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip
Download the artifact
curl -LO "https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip"
jq Playground
jq syntax can be difficult. Here's a playground for experimenting with the jq
above: https://jqplay.org/s/h6_LfoEHLZ
Security
You should take measures to ensure the validity of the downloaded artifact via sha256sum and gpg, if at all possible.
A solution using (an inner) wget to get the HTML content, filter it for the zip file (with egrep) and then download the zip file (with the outer wget).
wget https://github.com/$(wget https://github.com/<USER>/<PROJECT>/releases/latest -O - | egrep '/.*/.*/.*zip' -o)
Just use one of the urls below to download the latest release: (took urls from boxbilling project for example): https://api.github.com/repos/boxbilling/boxbilling/releases
Download the latest release as zip: https://api.github.com/repos/boxbilling/boxbilling/zipball
Download the latest release as tarball: https://api.github.com/repos/boxbilling/boxbilling/tarball
Click on one of the urls to download the latest release instantly. As i wrote this lines it's currently: boxbilling-boxbilling-4.20-30-g452ad1c[.zip/.tar.gz]
UPDATE: Found an other url in my logfiles (ref. to example above) https://codeload.github.com/boxbilling/boxbilling/legacy.tar.gz/master
Not possible according to GitHub support as of 2018-05-23
Contacted support@github.com on 2018-05-23 with message:
Can you just confirm that there is no way besides messing with API currently?
and they replied:
Thanks for reaching out. We recommend using the API to fetch the latest release because that approach is stable, documented, and not subject to change any time soon:
https://developer.github.com/v3/repos/releases/#get-the-latest-release
I will also keep tracking this at: https://github.com/isaacs/github/issues/658
Python solution without any dependencies
Robust and portable:
#!/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'])
See also:
- What is the quickest way to HTTP GET in Python?
- Basic http file downloading and saving to disk in python?
Also consider pre-releases
/latest
does not see pre-releases, but it is easy to do since /releases
shows the latest one first:
#!/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'])
The Linking to releases help page does mention a "Latest Release" button, but that doesn't get you a download link.
https://github.com/reactiveui/ReactiveUI/releases/latest
For that, you need to get the latest tag first (as mentioned in "GitHub URL for latest release of the download file?"):
latestTag=$(git describe --tags `git rev-list --tags --max-count=1`)
curl -L https://github.com/reactiveui/ReactiveUI/releases/download/$latestTag/ReactiveUI-$latestTag.zip
in PHP - redirect to the latest release download. Simply put on your webspace
<?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);
If you want to use just curl
you can try with -w '%{url_effective}'
that prints the URL after a redirect chain (followed by curl if you invoke it with -L
). So, for example
curl -sLo /dev/null -w '%{url_effective}' https://github.com/github-tools/github/releases/latest
outputs https://github.com/github-tools/github/releases/tag/v3.1.0
.
Github now supports static links for downloading individual files from the latest release: https://help.github.com/en/articles/linking-to-releases
https://github.com/USER/PROJECT/releases/latest/download/package.zip
I want to download the releases from the README.md
file in the repository description. There, I cannot execute JavaScript.
I can add links like these to the README file or github pages for all of my repositories:
https://niccokunzmann.github.io/download_latest/<USER>/<REPOSITORY>/<FILE>
Downloads the latest release file from the repository.https://niccokunzmann.github.io/download_latest/<FILE>
This works because the JavaScript referrer is set and the repository to download is determined throughdocument.referrer
. Thus, the link will also work for forks.
You can find the source code here, fork or just use my repo.
In case that the repo is using just tags instead of release -- cf. jQuery -- the solutions which based on one URL does not work.
Instead, you have to query all tags, sort them and construct the download URL. I implemented such a solution for the language Go and the jQuery repo: Link to Github.
Perhaps, this helps someone.
'IT박스' 카테고리의 다른 글
rake db : test : prepare는 실제로 무엇을합니까? (0) | 2020.07.14 |
---|---|
Windows에서 변수의 명령 결과를 어떻게 얻습니까? (0) | 2020.07.14 |
gradle 플러그인 적용의 차이점 (0) | 2020.07.14 |
Q_OBJECT 매크로는 무엇을합니까? (0) | 2020.07.14 |
하스켈 데이터 타입의 메모리 풋 프린트 (0) | 2020.07.14 |