Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bartreardon opened this issue Mar 14, 2024 · 2 comments
Closed

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

bartreardon opened this issue Mar 14, 2024 · 2 comments

Comments

@bartreardon
Copy link

bartreardon commented Mar 14, 2024

Regarding this block of code:

# URL for downloading swiftDialog (with tag version)
# This ensures a compatible swiftDialog version is used if not using the package installer
swiftdialog_version_required="2.4.2-4755"
dialog_download_url="https://github.com/swiftDialog/swiftDialog/releases/download/v${swiftdialog_version_required/-*/}/dialog-${swiftdialog_version_required}.pkg"
# 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_version_required="2.2.1-4591"
dialog_bigsur_download_url="https://github.com/swiftDialog/swiftDialog/releases/download/v${swiftdialog_bigsur_version_required/-*/}/dialog-${swiftdialog_bigsur_version_required}.pkg"

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.

@grahampugh
Copy link
Owner

grahampugh commented Apr 23, 2024

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

@bartreardon
Copy link
Author

sharing is caring 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants