Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
One Liner to download the latest release from your GitHub repo
LOCATION=$(curl -s<YOUR ORGANIZTION>/<YOUR REPO>/releases/latest \
| grep "tag_name" \
| awk '{print "<YOUR ORGANIZATION>/<YOUR REPO>/archive/" substr($2, 2, length($2)-3) ".zip"}') \

for example:

LOCATION=$(curl -s \
| grep "tag_name" \
| awk '{print "" substr($2, 2, length($2)-3) ".zip"}') \
; curl -L -o $LOCATION

Here is how it goes:


stores the output of all the commands in the brackets in the variable $LOCATION

curl -s

gets the latest release from your repository, in my case

grep "tag_name"

grabs the tag name of the latest release (e.g. v1.0.0)

awk '{print "" substr($2, 2, length($2)-3) ".zip"}'

prints "" v1.0.0 ".zip" --> ""

Now the $LOCATION is set to that string.

curl -L -o $LOCATION

invokes cURL and downloads $LOCATION into The -L parameter is important so that cURL follows the URL, i.e. redirect.


This comment has been minimized.

Copy link

@alecthegeek alecthegeek commented Mar 2, 2021

Awesome. Thanks for this. I shortened it to

latest_tag=$(curl -s | sed -Ene '/^ *"tag_name": *"(v.+)",$/s//\1/p')
echo "Using version $latest_tag"
curl -JLO$latest_tag.tar.gz

Very handy for Docker files and CI/CD pipelines.

(you could of course make it one line, but I did want to display the version name)


This comment has been minimized.

Copy link
Owner Author

@gvenzl gvenzl commented Mar 3, 2021

Very cool, thanks for adding your version to this! :)
I wasn't aware of the part.
Looks like one could shoot straight for tarball_url or zipball_url as well if all that is wanted is the file itself:

location=$(curl -s | grep tarball_url | awk '{ print $2 }' | sed 's/,$//' | sed 's/"//g' );

There is probably still some further optimization that can be done on the awk and sed parts there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment