diff --git a/scripts/bin/update-packages b/scripts/bin/update-packages index 42685181b1fcf6..af8b271f150f17 100755 --- a/scripts/bin/update-packages +++ b/scripts/bin/update-packages @@ -31,6 +31,9 @@ TERMUX_PACKAGES_DIRECTORIES=$(jq --raw-output 'del(.pkg_format) | keys | .[]' "$ # shellcheck source=scripts/properties.sh . "${TERMUX_SCRIPTDIR}/scripts/properties.sh" +# my GH_TOKEN for debugging, this is already passed in for the CI. +. "${TERMUX_SCRIPTDIR}/gh.env" || : + # Utility function to write error message to stderr. # shellcheck source=scripts/updates/utils/termux_error_exit.sh . "${TERMUX_SCRIPTDIR}"/scripts/updates/utils/termux_error_exit.sh @@ -77,7 +80,7 @@ TERMUX_PACKAGES_DIRECTORIES=$(jq --raw-output 'del(.pkg_format) | keys | .[]' "$ # shellcheck source=scripts/updates/termux_pkg_auto_update.sh . "${TERMUX_SCRIPTDIR}"/scripts/updates/termux_pkg_auto_update.sh -# Converts milliseconds to human-readable format. +# Converts milliseconds to human-readable format. # Example: `ms_to_human_readable 123456789` => 34h 17m 36s 789ms ms_to_human_readable() { echo "$(($1/3600000))h $(($1%3600000/60000))m $(($1%60000/1000))s $(($1%1000))ms" | sed 's/0h //;s/0m //;s/0s //' @@ -94,6 +97,15 @@ quiet() { return $? } +# Check GitHub rate limits +_gh_check_rate_limit() { + curl -L \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/rate_limit | jq '.resources.core' +} + _update() { export TERMUX_PKG_NAME TERMUX_PKG_NAME="$(basename "$1")" @@ -117,6 +129,10 @@ _update() { . "${TERMUX_PKG_BUILDER_DIR}"/build.sh 2>/dev/null set -e -u + [[ "$TERMUX_PKG_SRCURL" == *"github.com"* ]] && { + _gh_check_rate_limit + } + echo # Newline. echo "INFO: Updating ${TERMUX_PKG_NAME} [Current version: ${TERMUX_PKG_VERSION}]" termux_pkg_auto_update