GitHub url for latest _download_ file?

Although this question is similar to the latest release of GitHub , it is completely different - it refers to a link that means "latest version of the download file itself."

GitHub provides the β€œLatest” URL, which redirects to the information page for the latest version. For example: https://github.com/reactiveui/ReactiveUI/releases/latest will be redirected to https://github.com/reactiveui/ReactiveUI/releases/tag/5.99.6 (as I type this, or to a page for more new version, someday).

This is great, but I need the URL of the download file itself. In this example, the .zip file associated with the green download button is https://github.com/reactiveui/ReactiveUI/releases/download/5.99.6/ReactiveUI-5.99.6.zip (as I type it in or new zip file, someday).

Why? I want the URL to freeze, as part of the Travis CI script, to download the latest version.

I guessed at several URLs, for example / releases / download / latest /file.zip (replacing the "last" for the version part) and /releases/download/file.zip, but those that are listed in 404.

Is there a way to do this - in the context of the shell script and curl (note: not on the browser page with JS)?

+19
github
Jun 06 '14 at 15:52
source share
5 answers

As @florianb pointed out, I have to use git .

Initially, my .travis.yml was something like:

before_install: - curl -L https://raw.githubusercontent.com/greghendershott/travis-racket/master/install-racket.sh | bash 

This will automatically get any latest version from the repo.

But someone pointed out to me that GitHub does not want people to use raw.github.com to download. Instead, people should use "releases." Thus, I was a good helper and manually did the release every time. Then my .travis.yml was something like:

 before_install: - curl -L https://github.com/greghendershott/travis-racket/releases/download/v0.6/install-racket.sh | bash 

But it is PITA to do a release every time. Even worse, all .travis.yml files must be updated to indicate a newer version of the file.

Instead, just use git to clone the repo and use the file inside it:

 before_install: - git clone https://github.com/greghendershott/travis-racket.git - cat travis-racket/install-racket.sh | bash # pipe to bash not sh! 
-one
Jun 06 '14 at 23:52
source share

Here's a way to do it without Github if there is one download in the release:

 wget $(curl -s https://api.github.com/repos/USERNAME/REPONAME/releases/latest | grep 'browser_' | cut -d\" -f4) 

This is pretty easy (although not very), and of course you can swap wget for another curl call if you want to pass it to something.

Basically, the curl call binds the JSON structure, and I just use the basic shell utilities to retrieve the download URL.

+10
Apr 08 '15 at 0:09
source share

Very interesting, I have not noticed the "last" tag in GitHub releases. As I understand it, they are issued if you use the "preliminary version" - the capabilities of the GitHubs release system. But I do not know how to access binary files through the last path.

I would suggest you use git (which is available in your travis-vm) to load the last tag.

As Julien Renault describes in his blog post , you can check the last tag in the repository as follows:

 # this step should be optional git fetch --tags latestTag=$(git describe --tags `git rev-list --tags --max-count=1`) git checkout $latestTag 

This decision is based on the assumption that the latest tag is also the latest version.

+2
Jun 06 '14 at 16:25
source share

I use this to get the download URL in PowerShell 5+ (replace ACCOUNT and REPO)

 Invoke-RestMethod -uri https://api.github.com/repos/ACCOUNT/REPO/releases/latest | select -ExpandProperty assets | select -expand browser_download_url 

Please note that if they have more than one package, this will be a list. If you want to select a specific part, find the unique part of the name, i.e. win for Windows and use: (replace ACCOUNT, REPO and SELECTOR)

 Invoke-RestMethod -uri https://api.github.com/repos/ACCOUNT/REPO/releases/latest | select -ExpandProperty assets | ? { $_.name.Contains("SELECTOR")} | select -expand browser_download_url 

As a bonus, if you assigned the above value to a variable, you can grab the file and extract it as follows (assuming you assign $ uri):

 Invoke-WebRequest $uri -OutFile "release.zip" Expand-Archive .\release.zip 

In PowerShell 6+, this should work on platforms other than Windows.

+1
Aug 04 '17 at 16:21
source share

In windows, using only powershell, this works for me. It can probably be written much shorter.

 #Downloads latest paket.bootstrapper.exe from github $urlbase = "https://github.com" $latestPage="$urlbase/fsprojects/Paket/releases/latest" Write-Host "Parsing latest release page: $latestPage" $page=Invoke-Webrequest -uri $latestPage $latestBootStrapper=($page.Links | Where-Object { $_.href -match "bootstrapper" }).href $dlurl="$urlbase$latestBootStrapper" Write-Host "Downloading paket.bootstrapper.exe from $dlurl" $wc=new-object net.webclient $wc.UseDefaultCredentials=$true $wc.Proxy.Credentials=$wc.Credentials $wc.DownloadFile($dlurl, (join-path (resolve-path ".\") "paket.bootstrapper.exe")) 
0
May 07 '17 at 19:45
source share



All Articles