Github – grep code on cli
sometimes its a fucking mess to get the latest releases from repositorys on cli from GitHub, but there are ways to make it work (most time).
ways to get
branch
the simple way i to get a branch, as tar or zip file
GET https://github.com/ *:owner* / *:repo* / ( *zipball* or *tarball* ) [ / *:branch-name* ]
sample:
GET https://github.com/reactiveui/reactiveui/tarball/master
if u dont specify a branch u get the default branch
latest tags
normally you would need to know the tag, but lucky u! there is a permalink for latest-tags and -releases.
GET https://api.github.com/repos/ *:owner* / *:repo* /releases/latest
sample, with output
GET https://api.github.com/repos/reactiveui/reactiveui/releases/latest
{
[...]
"tarball_url": "https://api.github.com/repos/reactiveui/ReactiveUI/tarball/18.4.26",
"zipball_url": "https://api.github.com/repos/reactiveui/ReactiveUI/zipball/18.4.26",
[...]
}
download with wget
URL=$(wget https://api.github.com/repos/reactiveui/ReactiveUI/releases/latest -O - | \
awk -F \" -v RS="," '/tarball_url/ {print $(NF-1)}'); \
wget $URL -O $(basename "$URL").tar.gz
download with curl
URL=$(curl -s https://api.github.com/repos/reactiveui/ReactiveUI/releases/latest | \
awk -F \" -v RS="," '/tarball_url/ {print $(NF-1)}'); \
curl -L $URL -o $(basename $URL).tar.gz
latest releases
note: * binaryfiles, like executables, come with “browser_download_url” instead of tar-/zipball_url * sometimes there are platform specific releases
sample, with https://api.github.com/repos/mozilla/geckodriver/releases/latest
curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | grep browser_download_url
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux-aarch64.tar.gz"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux-aarch64.tar.gz.asc"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux32.tar.gz"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux32.tar.gz.asc"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux64.tar.gz"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-linux64.tar.gz.asc"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-macos-aarch64.tar.gz"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-macos.tar.gz"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-win-aarch64.zip"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-win32.zip"
"browser_download_url": "https://github.com/mozilla/geckodriver/releases/download/v0.32.2/geckodriver-v0.32.2-win64.zip"
at this point u need a more specific filter (exsample: win64) with awk
awk -F \" -v RS="," '/browser_download_url.*win64/ {print $(NF-1)}'
download with curl
URL=$(curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | \
awk -F \" -v RS="," '/browser_download_url/ {print $(NF-1)}'); \
curl -L $URL -o $(basename $URL)
thats it, nice enough for cli scripts
sources: [1] https://docs.github.com/de/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release [2] https://docs.github.com/de/rest/releases/releases?apiVersion=2022-11-28#get-a-release-by-tag-name [3] https://stackoverflow.com/questions/21439239/download-latest-github-release [4] https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8