Skip to content

Commit ef47d78

Browse files
authored
Add rate limiting fix
Since this workflow can run across mutliple repos simultaneously due to the schedule, we need to introduce some randomization so that we don't hit GH rate limits too often. In addition to that, we check for the rate limit explicitly and wait until it resets if we're nevertheless too close to it.
1 parent b9fb0a7 commit ef47d78

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

.github/workflows/dotnet-file.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Synchronizes .netconfig-configured files with dotnet-file
1+
# Synchronizes .netconfig-configured files with dotnet-file
22
name: dotnet-file
33
on:
44
workflow_dispatch:
@@ -22,6 +22,22 @@ jobs:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2323
run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV
2424

25+
- name: ⌛ rate
26+
shell: pwsh
27+
run: |
28+
# add random sleep since we run on fixed schedule
29+
sleep (get-random -max 60)
30+
# get currently authenticated user rate limit info
31+
$rate = gh api rate_limit | convertfrom-json | select -expandproperty rate
32+
# if we don't have at least 100 requests left, wait until reset
33+
if ($rate.remaining -lt 10) {
34+
$wait = ($rate.reset - (Get-Date (Get-Date).ToUniversalTime() -UFormat %s))
35+
echo "Rate limit remaining is $($rate.remaining), waiting for $($wait / 1000) seconds to reset"
36+
sleep $wait
37+
$rate = gh api rate_limit | convertfrom-json | select -expandproperty rate
38+
echo "Rate limit has reset to $($rate.remaining) requests"
39+
}
40+
2541
- name: 🤘 checkout
2642
uses: actions/checkout@v2
2743
with:
@@ -30,6 +46,7 @@ jobs:
3046
token: ${{ env.GH_TOKEN }}
3147

3248
- name: 🔄 sync
49+
shell: pwsh
3350
run: |
3451
dotnet tool update -g dotnet-gcm
3552
dotnet gcm store --protocol=https --host=github.com --username=$env:GITHUB_ACTOR --password=$env:GH_TOKEN

0 commit comments

Comments
 (0)