Is there a link to GitHub for downloading a file in the latest release of a repository?
Asked Answered
C

24

241

Using GitHub's Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-page also needs to be updated.

Is there a way to get a link to a specific file of whatever the latest version of a software is?

e.g., this would be a static link:

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

What I'd like is something like:

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

NOTE: The difference between this question and GitHub latest release is that this question specifically asks for getting access to the file, not the GitHub latest release page

Convertible answered 28/7, 2014 at 1:59 Comment(2)
This is supported natively by Github now (with a slight difference in the URL format). See #24988042Gardol
It is interesting how the question is clearly about a LINK, but so many answers are about retrieving an asset :))Counterespionage
S
184

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!

Screw answered 22/2, 2019 at 22:55 Comment(13)
Documented on help.github.com/en/articles/linking-to-releases: If you'd like to link directly to a download of your latest release asset you can link to /owner/name/releases/latest/download/asset-name.zipBoult
It would be helpful if this feature worked with versioned asset names, however.Boult
Note that the order is switched .../releases/latest/download/... vs .../releases/download/v0.0.0/.... You cannot simply replace v0.0.0 with latest in place.Gardol
@Joshua Peek Maybe you could extend this to expand "LATEST" in the asset name to be the version string? That would make it useful for assets with version numbers in their name.Loquacity
What about downloading the latest source code? What is the name of the asset in that case?Metatarsus
Currently /releases/latest/download/package.zip is no longer work. Result in not found. Example: github.com/FortAwesome/Font-Awesome/releases/latest/download/…Piazza
this does still workArchaic
Doesn't work for me as well: github.com/rust-lang/mdBook/releases/latest/download/….Ignaciaignacio
I'm confused by this answer. Where did you implement this? Do you work at Github and just like that implemented the feature. Or is it an API available at an URL that's somehow not linked to?Sian
The people in the comments who are saying this isn't working are likely confused by the fact this answer is only giving an example of downloading a file called "package.zip" from the release. If your asset is called "foo.zip", you need to change it to that. If your asset is called "foo-1.2.3.zip" where 1.2.3 is the version of the release, you'll have to use a different method.Faqir
@Faqir what he is mentioning is a very common issue about that, sadly it looks like GitHub has no solution to that just yetPigskin
As github cannot know which file you want when you say 'latest' it's impossible to avoid having the file name in the link. For example : github.com/rust-lang/mdBook/releases/latest/download/… . But then this doesn't really help because when you call latest you don't know the version and maybe don't care so it's like a half working system.Avulsion
@Faqir Whilst these users both linked to package.zip files that didn't exist (causing the download to fail), I think that they are (accidentally) correct that this method no longer works. At least, it doesn't appear to work for me.Hallelujah
I
72

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

curl -s https://api.github.com/repos/boxbilling/boxbilling/releases/latest | grep browser_download_url | cut -d '"' -f 4
Implied answered 4/11, 2014 at 14:45 Comment(6)
One additional grep in the pipeline will find the file for your distribution and architecture. For the atom text editor on 64-bit Ubuntu: curl -s https://api.github.com/repos/atom/atom/releases | grep browser_download_url | grep '64[.]deb' | head -n 1 | cut -d '"' -f 4Hematology
There is no browser_download_url any more. You can use tarball_url now. curl -s https://api.github.com/repos/git-ftp/git-ftp/releases | grep tarball_url | head -n 1 | cut -d '"' -f 4Earsplitting
@Earsplitting grepping for browser_download_url still works for me.Franza
@léo-lam You are right. Just if you don't have assets, you can use the tarball_url to get the source code.Earsplitting
You can only load the latest release to avoid | head -n 1 api.github.com/repos/boxbilling/boxbilling/releases/latestMendes
@Mendes /latest only list stable release, not draft or prerelease: developer.github.com/v3/repos/releases/#get-the-latest-releaseYama
T
35

You can do an ajax request to get latest release download URL using the GitHub Releases API. It also shows when it was released and the download count:

function GetLatestReleaseInfo() {
    $.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function(release) {
        UpdateDownloadButton(release, ".exe", $(".setup"));
        UpdateDownloadButton(release, "portable.zip", $(".portable"));
    });
}

function UpdateDownloadButton(release, assetExtension, element) {
    let asset = release.assets.find(asset => asset.name.endsWith(assetExtension));
    let releaseInfo = "Version: " + release.tag_name.substring(1) +
        "\nFile size: " + (asset.size / 1024 / 1024).toFixed(2) + " MB" +
        "\nRelease date: " + new Date(asset.updated_at).toLocaleDateString("en-CA") +
        "\nDownload count: " + asset.download_count.toLocaleString();

    element.attr("href", asset.browser_download_url);
    element.attr("title", releaseInfo);
}

GetLatestReleaseInfo();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a class="setup" href="https://github.com/ShareX/ShareX/releases/latest">Setup</a>
<a class="portable" href="https://github.com/ShareX/ShareX/releases/latest">Portable</a>

When the request completes, the URL of buttons will change automatically to a direct download URL.

Troostite answered 19/10, 2014 at 18:41 Comment(12)
Cool. Do you know why this might not be working? curl -s https://api.github.com/repos/DataTables/DataTables/releases/latestGeoid
Because you don't have any release. Check: api.github.com/repos/DataTables/DataTables/releasesTroostite
Funky... github.com/DataTables/DataTables/releases shows a bunch of releases. There must be some ambiguity there.Geoid
No, these are only tags. There are no releases.Jethro
Why is this blank? api.github.com/repos/jquery/jquery/releases There should be plenty of releases.Candidacandidacy
api.github.com/repos/jquery/jquery/releases/latest returns 404. This returns empty string: api.github.com/repos/webix-hub/tracker/releases while both of these projects have releases. Why is the API behavior inconsistent? Any documentation on this?Candidacandidacy
github.com/jquery/jquery/releases they don't have any releases. It is just version tags.Troostite
This is useless for the places where it would be needed. As in: Shell scripts.Disburse
@Evi1M4chine question was asking it for web pages not shell scripts.Troostite
I think it makes more sense to do this server-sided. Also, unless someone is already using jquery, prescribing it for this one thing is overkill. Ajax with vanilla JS isn't hard. Unless you want extremely wide browser support. In that case, do it on the server side. Unless there's some reason to doing it client side, but if there is that should be mentioned in the answer.Rooftree
@CoryRs I'm using GitHub pages for static web site hosting therefore couldn't do it server side.Troostite
If what you are trying to do is automate getting the download url for the latest release available on github, then @IanB's answer below is the way to go. Using jq to parse the output from Github's API and getting the download url needed. You can then use wget to get the actual file. Tried and tested in scripts and works perfectly for me.Chub
P
19

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'
Photochemistry answered 31/3, 2015 at 4:31 Comment(2)
jq --raw-output is a cleaner way to drop the quotes. If you only want the latest it's cheaper to fetch .../releases/latest and drop the .[0] | . But fetching all releases allows queries like jq '.[] | .assets[] | .browser_download_url | select(endswith(".deb"))'...Capsular
Thanks Beni, I expanded on this for grabbing the latest docker-compose, curl --silent "https://api.github.com/repos/docker/compose/releases/latest" | jq --arg PLATFORM_ARCH "$(echo `uname -s`-`uname -m`)" -r '.assets[] | select(.name | endswith($PLATFORM_ARCH)).browser_download_url' | xargs sudo curl -L -o /usr/local/bin/docker-compose --url . The endswith was the magic and using the arch allows me to ignore the whatever.sha256 files that are typically present without doing |head -n 1.Valkyrie
F
11

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.

Fanchette answered 9/1, 2015 at 21:21 Comment(4)
My goal is to make a link on a website that always points to the latest version. A linux command will not allow that.Convertible
This is what I was looking for but you have to make sure you have the correct escape characters for wildcards and dots when using grep.Mateya
@TdotThomas thanks, that's the hint I needed for semver release numbers to escape the periods \. e.g. 2.2.0 needed /download/[0-9\.]*/Thole
No, it doesn't. No escape char. But i would presume an optional v as prefix, like a tag v0.11.0. Just input curl -s -L https://github.com/bosun-monitor/bosun/releases/latest | egrep -o '/bosun-monitor/bosun/releases/download/[v]?[0-9.]*/scollector-linux-armv6' | wget --base=http://github.com/ -i - -O scollector in your CLI and it works perfectly. Thank you, Greg!!Crowell
C
9

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
Calceolaria answered 21/8, 2019 at 9:29 Comment(3)
The same answer was already posted 6 months prior: #24988042Gardol
Thanks for bringing this to my attention @wisbucky, I dismissed it then since it sounded like a custom implementation from a developer, not someone from StackOverflow!Convertible
this doesn't seem to work even thought it's in the docs - also it would be inconsistent to see /releases/latest/download/ when download links are of the style /releases/download/0.7.1/... (the version is at the end)Snort
S
9

This can be done in a single one-liner like so:

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest \
    | grep -wo "https.*Linux.*gz" | wget -qi -

Here we're:

  • Pulling the API side of GitHub to get information about the release artifacts with the tag latest.
  • Parse that output looking for an artifact that matches the pattern https.*Linux.*gz.
  • Pass the URL to the command wget -qi - so that it'll get downloaded

To further reveal what's going on here's a broader grep of the API endpoint:

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest | grep -wo "https.*" | grep gz
https://github.com/slmingol/gorelease_ex/releases/download/0.0.78/gorelease_ex_0.0.78_Darwin_x86_64.tar.gz"
https://github.com/slmingol/gorelease_ex/releases/download/0.0.78/gorelease_ex_0.0.78_Linux_x86_64.tar.gz"

Above you can see the URLs that matched.

Further tip

You can also parameterize the grep argument so that it'll "dynamically" determine what platform it was run on and substitute in the appropriate string based on that.

$ curl -s https://api.github.com/repos/slmingol/gorelease_ex/releases/latest \
    | grep -wo "https.*$(uname).*gz" | wget -qi -

Here $(uname) will return either Darwin, Linux, etc.

Stannfield answered 12/5, 2021 at 4:58 Comment(1)
this is neat with grep regexp, thanks for sharing!Stoat
O
8

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

Orthopedist answered 13/10, 2016 at 23:28 Comment(1)
those are repos not releasesJuror
C
8

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.

Commend answered 26/3, 2017 at 21:49 Comment(0)
H
8

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)
Harvey answered 16/5, 2017 at 8:7 Comment(0)
S
8

Not possible according to GitHub support as of 2018-05-23

Contacted [email protected] 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:

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'])
Supersensible answered 26/5, 2018 at 7:51 Comment(1)
GitHub support didn't bother to check that their documentation is wrong? Plus don't they get it that end users need a consistent url and not scripts?Snort
H
6

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
Hierarchy answered 28/7, 2014 at 7:1 Comment(3)
This still requires to push a new version of the gh-pages branch everytime a new release is made; the objective is to have a static link I can use to just "refer to the latest version". Right now my best option is to just refer to the releases page.Convertible
@ChristianRondeau I agree. I didn't see anywhere in the API a way to reference the "latest" release archive full url directly.Hierarchy
Still, thanks for the tip; if no better answers are provided, I'll probably end up doing a script to update gh-pages using your script.Convertible
R
3

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 through document.referrer. Thus, the link will also work for forks.

You can find the source code here, fork or just use my repo.

Rudderhead answered 11/2, 2017 at 20:34 Comment(4)
That's a pretty clever idea :) it won't work when sharing links or using curl or the likes, but this idea can be done in the project's github pages.Convertible
SInce this is possible as a JavaScript website, one could also write a service that does a redirect. download-service.com/organization/repository/artifactRudderhead
Seems to work fine, any tips on how one can host it at their own xx.github.io site? (so that they're sure it stays alive and pointing to the files they expect it to)Snort
You should be able to fork it and then enable github pages in the settings of the fork.Rudderhead
A
3

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);
Avelar answered 29/4, 2017 at 10:12 Comment(0)
U
3

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.

Untouchability answered 24/10, 2017 at 20:41 Comment(0)
O
3

The benefit of this solution is that you don't have to specify any release or tag number- it will just grab the LATEST.

TESTING:

I conducted my testing using the following Github user & repo:

"f1linux" = Github User
"pi-ap" = Repo

The arbitrary directory name the repo is saved to is set in:

--one-top-level="pi-ap"

DIRECT:

Using Firefox's "Web Developer" tools (3 bars in upper right corner), in the "Network" section I found https://api.github.com was redirecting to https://codeload.github.com, so by piping the curl to tar I was able to grab the latest versioned repo and save it to a predictable name so it could be operated on:

curl https://codeload.github.com/f1linux/pi-ap/legacy.tar.gz/master | tar xzvf - --one-top-level="pi-ap" --strip-components 1

INDIRECT:

After I achieved fully-automated downloads of the latest versioned release using a DIRECT URL, I turned my attention to achieving the same with Github's redirection:

curl -L https://api.github.com/repos/f1linux/pi-ap/tarball | tar xzvf - --one-top-level="pi-ap" --strip-components 1

Preferred Method:

However, please note as per Von's comment below that INDIRECT is the preferred method

Further Validation:

To ensure my results were reproducible to other versioned Github repos, the same tests were successfully executed for Digital Ocean's doctl api toolkit (which is what started the whole exercise actually!):

Both DIRECT and INDIRECT work using the same form as above, just changing the username & repo:

DIRECT:

curl https://codeload.github.com/digitalocean/doctl/legacy.tar.gz/master | tar xzvf - --one-top-level="doctl" --strip-components 1 

INDIRECT:

curl -L https://api.github.com/repos/digitalocean/doctl/tarball | tar xzvf - --one-top-level="doctl" --strip-components 1
Obsolete answered 30/3, 2020 at 12:2 Comment(2)
I ran into grief with the redirection initially and as noted in the answer Firefox's "Web Developer" tools got me going on the right track. Couldn't stop there though, had to get it working with the redirection. Thanks for the upvote- most obliged!Obsolete
@Hierarchy Just added your feedback to the answer. I was totally unaware of this. Thanks for pointing it out!Obsolete
R
3

This is for Linux.

I saw the above accepted answer

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!

by Joshua Peek but a comment noted it didn't support versioned file names.

After searching for a bit, I made up a one line call that works for versioned file names. It uses curl to get the latest file version and then makes use of the redirect support that was added to download the latest versioned file.

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.

I made this up by mimicking how grep and curl were used by others and just learned all of this now, so let me know if it's doing something real naughty that I wouldn't even fathom! Also I am saying <UMBRELLA PROJECT> but a user name should be able to go there just fine as well. Shout out to https://mcmap.net/q/118548/-how-to-use-sed-grep-to-extract-text-between-two-words for the grep call, https://unix.stackexchange.com/a/10264 for the $string$concatenation.

Rodroda answered 13/10, 2020 at 7:32 Comment(0)
C
2

In case you want to use in alpine, follow these steps:

 apk add curl ca-certificates wget
wget -q $(curl -s https://api.github.com/repos/<USER>/<REPOSITORY>/releases/latest | grep browser_download_url | grep "$ARCH" | cut -d '"' -f 4)

The -q flag in wget is quiet mode. If you want to see the output then use without -q.

Choreodrama answered 16/9, 2020 at 10:41 Comment(0)
G
1

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.

Guileless answered 18/6, 2017 at 11:56 Comment(0)
S
1

There is a dirty trick that uses internal github.com webserver latest redirect rule. But this rule doesn't exist on raw.githubusercontent.com host.

For example we can install the latest available nvm using the following code:

curl -s -w '%header{location}' "https://github.com/nvm-sh/nvm/releases/latest/download/install.sh" | \
  sed -e 's/\/\/github.com/\/\/raw.githubusercontent.com/' -e 's/\/releases\/download//' | \
  xargs curl -o- | bash
Spandrel answered 17/5, 2023 at 19:12 Comment(4)
Is the file install.sh unique to NVM's repo only or is this a widespread script that is commonly found on most if not all other repositories?Selfdrive
@Selfdrive Hi, you can use it for every repo.Spandrel
I tried curl -s -w '%header{location}' "https://github.com/yasm/yasm/releases/latest/download/install.sh" | \ sed -e 's/\/\/github.com/\/\/raw.githubusercontent.com/' -e 's/\/releases\/download//' | \ xargs curl -o- | bash and i didnt work. do you know what I am doing wrong?Selfdrive
yasm release doesn't include install.sh script. See https://github.com/yasm/yasm/releases it has for example yasm-1.3.0-win64.exe. So you can do something like curl -s -w '%header{location}' "https://github.com/yasm/yasm/releases/latest/download/yasm-1.3.0-win64.exe" | xargs curl -o- | start where start is a command to run exe files in windows.Spandrel
T
0

simple command which works and download the latest package available in the github release

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 - replace it with github repo with available packages in release
  • Type of package .tar.gz can be replaced as per need. Ex - .zip etc
Threepiece answered 10/8, 2022 at 11:9 Comment(0)
H
0

There's also a way to download zipped code from a specific branch.:

https://github.com/<author>/<repo>/archive/refs/heads/main.zip

Example:

https://github.com/php-sage/sage/archive/refs/heads/main.zip

Docs:

https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives

Not release, just latest code in a branch, but I found it useful.

Heartfelt answered 14/9, 2023 at 22:4 Comment(0)
S
0

To grab a listed tar.gz tarball use the following command.

I feel like this gets easier AS LONG as curl returns a string that matches the grep regex.... what I mean is some results DO NOT have a string that will match this but the ones who do this makes it pretty easy.

git_repo=yasm/yasm
curl -fsSL https://api.github.com/repos/${git_repo}/releases/latest | grep -Eo 'http.*\.tar\.gz' | head -n1
Selfdrive answered 3/11, 2023 at 2:2 Comment(0)
T
0

This solution downloads the latest release tar.gz archive of a GitHub repository with GitHub CLI command line.

To use the gh release download command we need to pick the tag of the latest release, here is how

gh release list --limit 1 --json "tagName" --jq ".[].tagName"

Then provide this tag to the gh release download command

gh release download \
  "$(gh release list --limit 1 --json "tagName" --jq ".[].tagName")" \
  --archive="tar.gz"

The overall code 👇

#!/usr/bin/env bash
# -*- coding: UTF-8 -*-
#
# github   : https://github.com/JV-conseil
# www      : https://www.jv-conseil.net
# author   : JV-conseil
#
# gh release download & list
# see: <https://cli.github.com/manual/gh_release_download>
#
#====================================================

# Retrieve the tag of the latest release
_jvcl_::gh_release_latest_tag() {
  gh release list --limit 1 --json "tagName" --jq ".[].tagName"
}

# Download the latest release archive in tar.gz
# to a local directory
_jvcl_::gh_release_download() {
  local _dir_backup="${1:-"./Downloads"}"
  gh release download \
    "$(_jvcl_::gh_release_latest_tag)" \
    --archive="tar.gz" \
    --dir="${_dir_backup}"
}

_jvcl_::gh_release_download "./path_to_a_folder"

This solution does not provide a link stricto sensu as requested by the question, but is convenient to work with public and private repositories.

Tortoni answered 1/4, 2024 at 23:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.