I recently needed to download the latest release from a GitHub repo but didn’t want to hardcode the version number or use separate API calls to get the latest release. I found a few one-liner solutions online, but most of these made two separate calls:
- an API call to get the latest release
- then another to download that release asset
I swore there was a way to get this in one call, but it took a little bit of digging for me to find it. I’m posting this here for posterity and future searchers 😀.
Well, it’s not much of a script, more of a command, but here it is for both
curl. The only thing you need to know is the filename of the asset you want to download. In this case, it’s
tfsec-linux-amd64 . If the maintainers chose to add in version numbers in the filename, like
tfsec-linux-amd64-v1.28.1 , you would need to use an alternative one-liner to make that second API call to get the version number.
How to download the latest version of a release asset:
1 wget https://github.com/aquasecurity/tfsec/releases/latest/download/tfsec-linux-amd64
1 curl -O https://github.com/aquasecurity/tfsec/releases/latest/download/tfsec-linux-amd64
-O(case sensitive) saves the file as the same name specified in the URL
Download a Specific Version
I’m posting this here in case you have the exact opposite problem and need to download a specific version of a release asset.
If you need to download a specific version of a release, you can use:
1 wget https://github.com/aquasecurity/tfsec/releases/download/v1.28.1/tfsec-linux-amd64
To make your CI jobs repeatable, it makes more sense to have a hardcoded version of a release asset. Just make sure to update the version every now and then 😁. If you just need to download the latest version of a release asset, then the above solution will be perfect!