-
-
Save KyMidd/dbcc29364956a19e666f8fe1f43e8ff0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### | |
| ### Functions | |
| ### | |
| # Hold until rate-limit success | |
| hold_until_rate_limit_success() { | |
| # Loop forever | |
| while true; do | |
| # Any call to AWS returns rate limits in the response headers | |
| API_RATE_LIMIT_UNITS_REMAINING=$(curl -sv \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/$gh_org/ActionPRValidate_AnyJobRun/autolinks 2>&1 1>/dev/null \ | |
| | grep -E '< x-ratelimit-remaining' \ | |
| | cut -d ' ' -f 3 \ | |
| | xargs \ | |
| | tr -d '\r') | |
| # If API rate-limiting is hit, sleep for 1 minute | |
| # Rounded parenthesis are used to trigger arithmetic expansion, which compares more than the first numeric digit (bash is weird) | |
| if (( "$API_RATE_LIMIT_UNITS_REMAINING" < 100 )); then | |
| echo "ℹ️ We have less than 100 GitHub API rate-limit tokens left ($API_RATE_LIMIT_UNITS_REMAINING), sleeping for 1 minute" | |
| sleep 60 | |
| # If API rate-limiting shows remaining units, break out of loop and function | |
| else | |
| echo "💥 Rate limit checked, we have "$API_RATE_LIMIT_UNITS_REMAINING" core tokens remaining so we are continuing" | |
| break | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment