joshjohanning / joshjohanning.github.io

josh-ops.com | a devops blog
https://josh-ops.com
MIT License
8 stars 0 forks source link

Programmatically Download Latest Release from GitHub Repo | josh-ops #39

Open utterances-bot opened 3 months ago

utterances-bot commented 3 months ago

Programmatically Download Latest Release from GitHub Repo | josh-ops

Programmatically download the latest release from a GitHub Repo without having to hardcode the version or use separate API calls

https://josh-ops.com/posts/github-download-latest-release/

bkozell commented 3 months ago

Interesting statement regarding version numbers, but not accurate. You can still use a single one-line wget statement to perform the download, and wget will traverse the page and do it's magic. You need to alter a few parameters. I'm a tech & regularly need to download many updates from various sites, many of which come from github. Only caveat is my script that once worked for every project up until about a year ago doesn't work for a majority of github pages today. I'm still trying to resolve this.

To prove my point regarding not having to worry about version numbers, feel free to try this example (it's one of the rare few updates from github my script still works with):

wget.exe -a C:\Apps\Log.txt -r --accept=zip -np --content-disposition -erobots=off -nd "https://github.com/xmrig/xmrig/releases" --no-if-modified-since --trust-server-names -P "C:\Apps"

Your example above would have the following command:

wget.exe -a C:\Apps-Test\Log.txt -r --accept=gz -np --content-disposition -erobots=off -nd "https://github.com/aquasecurity/tfsec/releases/latest" --no-if-modified-since --trust-server-names -P "C:\Apps-Test"

But, alas, it doesn't work due to wget not properly translating something on the web page. If you inspect the log that is created, the files are downloaded as .tmp files, but never saved properly as the first example I supplied.

This is frustrating as wget has the tools built into it to do the task without any additional coding. Would love to be able to download from github reliably using wget again.

bkozell commented 3 months ago

I made an error for your example. If you drop the "/latest" part from the URL, one file of the bunch will download & it will contain the version number, too. Why the other .gz files aren't picked up is a mystery to me. This isn't rocket science - I've been able to tailor my large script to almost any web site to download the updated files I need without spending hours doing it manually. Github has proven to be a huge pain in the rear end.