get_latest_release() { | |
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api | |
grep '"tag_name":' | # Get tag line | |
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value | |
} | |
# Usage | |
# $ get_latest_release "creationix/nvm" | |
# v0.31.4 |
This comment has been minimized.
This comment has been minimized.
If you are in the repo, you can simply use: But your approach is a good trick. |
This comment has been minimized.
This comment has been minimized.
Hi,
Thanks, for sharing the great idea! |
This comment has been minimized.
This comment has been minimized.
Another alternative: You can also get the download link directly: |
This comment has been minimized.
This comment has been minimized.
To get latest tag, for example if the repo doesn't utilise GitHub releases.
|
This comment has been minimized.
This comment has been minimized.
I combined all the resources I found on the subject to come up with a one-liner to grab docker-compose assuming you have
This could easily be put into a function where you pass the name of the repository and the platform or architecture you want to download. Sadly for a lot of releases it could be anything, ie amd64, x86_64, i386, i586, i686, or others depending on the packaging tool they used. You can use |
This comment has been minimized.
This comment has been minimized.
Thanks a lot!! It worked perfectly on my problem!! I made a shell function to find assets of latest release that will work with python 3.x. getLatest() {
REPO=$1
SUFFIX=$2
curl --silent https://api.github.com/repos/$REPO/releases/latest | \
python -c "import sys; from json import loads as l; x = l(sys.stdin.read()); print(''.join(s['browser_download_url'] for s in x['assets'] if s['name'].endswith('.$SUFFIX')))"
} |
This comment has been minimized.
This comment has been minimized.
Can be done with |
This comment has been minimized.
This comment has been minimized.
only the original is valid if I try all the others I get "jq not found", jq is more bloated than sed so I dont see the logic in replacing sed with jq -P is invalid flag for grep The problem with the original is it outputs with v at the start which needs removing, otherwise its perfect. append this to end cut -c 2-
|
This comment has been minimized.
This comment has been minimized.
See https://stackoverflow.com/questions/3074288/get-url-after-curl-is-redirected An easier way: $ curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/hadolint/hadolint/releases/latest && echo
https://github.com/hadolint/hadolint/releases/tag/v1.15.0 |
This comment has been minimized.
This comment has been minimized.
That's because it's not installed or in your $PATH
From -P, --perl-regexp PATTERN is a Perl regular expression PCRE - Perl Compatible Regular Expressions
How would that be a problem? Im curious.
Using From @peschu123 Post's
to
A single character gets rid of your ennemy.
By the looks of this one, it also seems you could use a Markdown syntax refresher course, |
This comment has been minimized.
This comment has been minimized.
Very nice. |
This comment has been minimized.
This comment has been minimized.
Perfect. Thanks. |
This comment has been minimized.
This comment has been minimized.
awesome |
This comment has been minimized.
This comment has been minimized.
Thanks a lot for that! |
This comment has been minimized.
This comment has been minimized.
curl -s "https://api.github.com/repos/$REPO/releases/latest" | awk -F '"' '/tag_name/{print $4}' |
This comment has been minimized.
This comment has been minimized.
Anyone know why this doesn't work on aws/aws-cli releases? It has releases, but
produces:
|
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
same thing with https://api.github.com/repos/docker/engine/releases/latest Not found |
This comment has been minimized.
This comment has been minimized.
get_latest_release_number() {
curl --silent "https://github.com/$1/releases/latest" | sed 's#.*tag/\(.*\)\".*#\1#'
}
# Usage
# $ get_latest_release_number "creationix/nvm"
# v0.34.0 |
This comment has been minimized.
This comment has been minimized.
Windows cmd no dependencies ...
|
This comment has been minimized.
This comment has been minimized.
A more pure approach with no dependencies on Replace
What is it doing? That "location url" is a part of the header, so I pass Real Example:
|
This comment has been minimized.
This comment has been minimized.
This is a bit cleaner ... |
This comment has been minimized.
This comment has been minimized.
How about getting the release date information? I am trying to get version, and release date. I've got the version number parsed and cleaned up. Can someone please point me in the right direction? |
This comment has been minimized.
This comment has been minimized.
This is all too weak you guys. As mentioned by many - GitHub API won't return actual Releases in many cases when releases were not filed formally. Those releases that don't appear are not less releases than the others :) Thus I have created lastversion CLI tool. How about this one liner:
Will give you the version of latest release even if it's not present in the API response! :) |
This comment has been minimized.
This comment has been minimized.
# Get final URL after curl is redirected
RELEASE_URL=$(curl -Ls -o /dev/null -w %{url_effective} https://github.com/docker/compose/releases/latest)
# Extract tag after the last forward slash
TAG="${RELEASE_URL##*/}" |
This comment has been minimized.
This comment has been minimized.
I have adapted this code for one of my use cases, in which the criteria to select for is the ".tgz" extension (as opposed to .zip etc for windows).
This works as expected and downloads the release as However, another use case is more complicated, its releases have many versions, separated by format (e.g. .tgz .zip) and inclusion of JRE. I'm trying to select for the .tgz WITHOUT JRE, which is denoted in the middle of the string (BEAST_with_JRE.v2.5.2.Linux.tgz vs BEAST.v2.5.2.Linux.tgz). I've attempted to use the wildcard, i.e. Could anyone please give me a little hand here and point me in the right direction? |
This comment has been minimized.
This comment has been minimized.
Another variant that helps to install last version of dxvk before running Steam:
|
This comment has been minimized.
This comment has been minimized.
@andrew-aladev or, using lastversion
which will take care of things if repo maintainer forgets to tag a formal release. |
This comment has been minimized.
This comment has been minimized.
Thank you for this! Building on this, we can use basename $(curl -Ls -o /dev/null -w %{url_effective} ${LATEST_GITHUB_RELEASE_URL}
# Example:
basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/latest
v0.4.0 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
My solution for
Produces:
|
This comment has been minimized.
This comment has been minimized.
My hero |
This comment has been minimized.
This comment has been minimized.
@dvershinin thank you for that tool! Just what I need and seems so much more simple than trying to use these various other approaches. If only everything could be so universal!
|
This comment has been minimized.
This comment has been minimized.
A somewhat simpler one:
|
This comment has been minimized.
This comment has been minimized.
It's your trailing slash |
This comment has been minimized.
This comment has been minimized.
@trentmillar this is due to API limitations. You can use lastversion, e.g.:
|
This comment has been minimized.
This comment has been minimized.
No, but I get his question and my response to it could be off topic, I was replying to @vwal's issue where he was attempting to hit an unknown route because he appended "/" at the end of the endpoint. If you simply attempt to execute |
This comment has been minimized.
This comment has been minimized.
thanks you ! |
This comment has been minimized.
This comment has been minimized.
what about using
|
This comment has been minimized.
This comment has been minimized.
Excellent! More concise! |
This comment has been minimized.
This comment has been minimized.
if you need a more universal answer, you can use |
This comment has been minimized.
This comment has been minimized.
@lestofante That is also a very good suggestion! But this solution will
only work if there are no more tags than just the release version tags. And
as long as release versions are tracked as tags in the repository.
**edit** It would probably not differantiate between pre-releases and stable releases either.
|
This comment has been minimized.
This comment has been minimized.
From what I can tell, the github. com/github/hub command line command will help us a lot with these things in the near future! |
This comment has been minimized.
This comment has been minimized.
@artheus yes I focus on be able to support any git repo more than specific github functionality. Just some little correction
in that case you can add some grep/awk to extrapolate only what you need.
i am pretty sure github (and others) create a tag for every release automatically and you cant opt-out
yes you are right! |
This comment has been minimized.
This comment has been minimized.
Good tip, thx! but... might not work as
I'm using |
This comment has been minimized.
This comment has been minimized.
Probably not Pythonic but Python way: import requests
url = 'https://github.com/roundcube/roundcubemail/releases/latest'
r = requests.get(url)
version = r.url.split('/')[-1]
print(version) Source: https://gist.github.com/zeldor/604a7817f9d142e908335e041ece0718 |
This comment has been minimized.
This comment has been minimized.
Very nice. |
This comment has been minimized.
This comment has been minimized.
Nice! This is the one that works best for me (I prefer not depending on Anyway, just to make it even a little bit easier to use:
You may also want to add another |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
Must say I |
This comment has been minimized.
This comment has been minimized.
In function get_latest_release_version \
--argument-names user_repo
curl \
--silent \
"https://api.github.com/repos/$user_repo/releases/latest" \
| string match --regex '"tag_name": "\K.*?(?=")'
end Usage:
|
This comment has been minimized.
This comment has been minimized.
Why not use jq?
|
This comment has been minimized.
This comment has been minimized.
Example to get highest version, not just latest - because an LTS bugfix 1.2.3 could be released after a new major 3.x version
or find latest version for a specific major version:
|
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
Nice one! Thanks!