Skip to content

Commit 8e61d6d

Browse files
authored
[gha] monitor gha rate limit (#18193)
1 parent 5fff9a9 commit 8e61d6d

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

.github/workflows/rate-limit.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Monitor GH Rate Limit and Upload to GCS (gcloud storage)
2+
3+
on:
4+
workflow_dispatch:
5+
# schedule: # NOTE: the schedule is dictated by PIES
6+
push:
7+
branches:
8+
- 11-21-_gha_monitor_gha_rate_limit # testing
9+
10+
permissions:
11+
contents: read
12+
id-token: write
13+
14+
env:
15+
RATE_LIMIT_BUCKET: github-rate-limit-bucket
16+
17+
jobs:
18+
collect-and-upload:
19+
runs-on: runs-on,runner=2cpu-ubuntu22-x64,run-id=${{ github.run_id }}
20+
21+
steps:
22+
- name: Query GitHub API rate limits
23+
env:
24+
GITHUB_TOKEN: ${{ github.token }}
25+
run: |
26+
# Fetch rate limit from GitHub API
27+
RATE_LIMIT_DATA=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
28+
https://api.github.com/rate_limit)
29+
30+
# Wrap with metadata
31+
jq -n \
32+
--arg token_name "GITHUB_TOKEN" \
33+
--argjson rate_limit "$RATE_LIMIT_DATA" \
34+
'{
35+
metadata: {
36+
token_name: $token_name
37+
},
38+
rate_limit: $rate_limit
39+
}' > rate_limit.json
40+
41+
- name: Authenticate to GCP
42+
uses: google-github-actions/auth@v2
43+
with:
44+
workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
45+
service_account: ${{ vars.GCP_SERVICE_ACCOUNT_EMAIL }} # needed because gcloud storage is GA but under alpha surface on some images
46+
47+
- name: Upload to GCS using gcloud storage with timestamp
48+
run: |
49+
TIMESTAMP=$(date -u +%Y-%m-%d_%H%M%S)
50+
REPO_NAME="${{ github.repository }}"
51+
gcloud storage cp rate_limit.json \
52+
gs://${{ env.RATE_LIMIT_BUCKET }}/${REPO_NAME}/${TIMESTAMP}.json

0 commit comments

Comments
 (0)