Есть ли ссылка на GitHub для загрузки файла в последней версии репозитория?

Используя функцию выпуска GitHub , вы можете предоставить ссылку для загрузки определенной версии опубликованного программного обеспечения. Тем не менее, каждый раз, когда происходит релиз, gh-страница также нуждается в обновлении.

Есть ли способ получить ссылку на конкретный файл любой последней версии программного обеспечения?

например, это будет статическая ссылка:

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

То, что я хотел бы, это что-то вроде:

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

ПРИМЕЧАНИЕ. Разница между этим вопросом и последней версией GitHub заключается в том, что в этом вопросе конкретно предлагается получить доступ к файлу, а не к последней странице выпуска GitHub

github,download,release,github-pages,

99

Ответов: 13


24 голосов принято

Вы можете выполнить функцию GetLatestReleaseInfo () { $ . getJSON ( "https://api.github.com/repos/ShareX/ShareX/releases/latest" ). Выполненные ( функция ( выпуск ) { вар активов = выпуск . активы [ 0 ]; вар DOWNLOADCOUNT = 0 ; для ( вар я = 0 ; я < выпуск . активов . Длина ; я ++) { 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();uery.com/<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>uery.ajax/" rel="nofollow noreferrer">ajax request to get latest release download URL using the GitHub Releases API. It also shows when it was released and the download count:

curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4
curl

It is important for you to set the default button URL to the releases page (like https://github.com/ShareX/ShareX/releases/latest) so if the browser does not support ajax (or javascript) or is too slow to get the URL, the download button will still work.

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


52

Linux solution to get latest release asset download link (works only if release has one asset only)

jq

14

From the command line using curl -s https://api.github.com/repos/porjo/staticserve/releases/latest | jq --raw-output '.assets[0] | .browser_download_url' and jq, retrieves the first file of the latest release:

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

8

Another Linux solution using curl and wget to download a single binary file from the latest release page

curl -s -L

Explanation:

egrep -o '...' is to silently download the latest release HTML (after following redirect)

wget --base=http://github.com/ -i - uses regex to find the file you want

-O scollector converts the relative path from the pipeline to absolute URL

and -N sets the desired file name.

may be able to add 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" to only download if the file is newer but S3 was giving a 403 Forbidden error.


5

As noted previously, jq is useful for this and other REST APIs.

tl;dr - more details below

Assuming you want the macOS release:

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
...

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

select(.name=="atom-mac.zip")

Get the download URL for the desired asset

Below atom-mac is my desired asset via jq's 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

curl -LO "https://github.com/atom/atom/releases/download/v1.15.0/atom-mac.zip"

Download the artifact

jq

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.

github,download,release,github-pages,
Похожие вопросы
Яндекс.Метрика