erase-install icon indicating copy to clipboard operation
erase-install copied to clipboard

FR: Use tags to get the latest download URL from github

Open bartreardon opened this issue 11 months ago • 2 comments

Regarding this block of code:

https://github.com/grahampugh/erase-install/blob/515128ae88e166e4e5868bce52a06db646a2b713/erase-install.sh#L59-L67

It would be more robust to use the release tag to get the download url rather than expect the pkg name to be in a certain format. Then if I have a lapse in memory and use a different filename things won't break and you only need the tag to get whatever the download url is (or no tag to just get the latest)

The following will work to get either the latest release or a specific tag:

getDownloadURL() {
    url="https://api.github.com/repos/swiftDialog/swiftDialog/releases"
    header="Accept: application/json"
    tag=${1:-"$(curl -sL -H "${header}" ${url}/latest | awk -F '"' '/tag_name/ { print $4; exit }')"}
    
    curl -sL -H "${header}" ${url}/tags/${tag} | awk -F '"' '/browser_download_url/ { print $4; exit }'
}

# URL for downloading the latest swiftDialog release
dialog_download_url=$(getDownloadURL)
echo "download url for latest : ${dialog_download_url}"

# URL for downloading swiftDialog (with tag version)
# This ensures a compatible swiftDialog version is used if not using the package installer
swiftdialog_tag_required="v2.4.2"
dialog_download_url=$(getDownloadURL "${swiftdialog_tag_required}")
echo "download url for tag version : ${dialog_download_url}"

# URL for downloading swiftDialog on macOS 11 (with tag version)
# This ensures a compatible swiftDialog version is used if not using the package installer
swiftdialog_bigsur_tag_required="v2.2.1"
dialog_bigsur_download_url=$(getDownloadURL "${swiftdialog_bigsur_tag_required}")
echo "download url for big sur supported version: ${dialog_bigsur_download_url}"

Do note that unauthenticated access to the github api is limited to 60 requests per hour per client.

bartreardon avatar Mar 14 '24 22:03 bartreardon

Many thanks for this @bartreardon , I've incorporated this into the pre-release of 34.0 (and the Makefile) - in the 34.0 branch.

grahampugh avatar Apr 23 '24 17:04 grahampugh

sharing is caring 🙂

bartreardon avatar Apr 26 '24 00:04 bartreardon