Skip to content

Commit a52b862

Browse files
committed
CI: use gh api for cuda_bindings policy checks
Align the PR metadata workflow with repo conventions by using gh to paginate the PR file list, keeping the bindings restriction check simpler and easier to review. Made-with: Cursor
1 parent 90625f6 commit a52b862

1 file changed

Lines changed: 17 additions & 28 deletions

File tree

.github/workflows/pr-metadata-check.yml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ jobs:
4242
IS_DRAFT: ${{ github.event.pull_request.draft }}
4343

4444
# API request context/auth
45-
GITHUB_API_URL: ${{ github.api_url }}
4645
GH_TOKEN: ${{ github.token }}
4746
REPO: ${{ github.repository }}
4847
run: |
@@ -119,33 +118,23 @@ jobs:
119118
120119
# Only NVIDIA organization members may change code under cuda_bindings.
121120
if [ "$AUTHOR_ASSOCIATION" != "MEMBER" ] && [ "$AUTHOR_ASSOCIATION" != "OWNER" ]; then
122-
page=1
123-
TOUCHES_CUDA_BINDINGS=false
124-
while true; do
125-
FILES_JSON=$(curl --silent --show-error --fail \
126-
-H "Authorization: Bearer $GH_TOKEN" \
127-
-H "Accept: application/vnd.github+json" \
128-
-H "X-GitHub-Api-Version: 2022-11-28" \
129-
"$GITHUB_API_URL/repos/$REPO/pulls/$PR_NUMBER/files?per_page=100&page=$page")
130-
131-
if jq -e '
132-
.[]
133-
| select(
134-
(.filename | startswith("cuda_bindings/"))
135-
or ((.previous_filename // "") | startswith("cuda_bindings/"))
136-
)
137-
' <<<"$FILES_JSON" >/dev/null; then
138-
TOUCHES_CUDA_BINDINGS=true
139-
break
140-
fi
141-
142-
FILE_COUNT=$(jq 'length' <<<"$FILES_JSON")
143-
if [ "$FILE_COUNT" -lt 100 ]; then
144-
break
145-
fi
146-
147-
page=$((page + 1))
148-
done
121+
if ! TOUCHES_CUDA_BINDINGS=$(
122+
gh api \
123+
--paginate \
124+
--slurp \
125+
--jq '
126+
flatten
127+
| any(
128+
.[];
129+
(.filename | startswith("cuda_bindings/"))
130+
or ((.previous_filename // "") | startswith("cuda_bindings/"))
131+
)
132+
' \
133+
"repos/$REPO/pulls/$PR_NUMBER/files"
134+
); then
135+
echo "::error::Failed to inspect the PR file list."
136+
exit 1
137+
fi
149138
150139
if [ "$TOUCHES_CUDA_BINDINGS" = "true" ]; then
151140
ERRORS="${ERRORS}- **cuda_bindings policy**: See \`cuda_bindings/LICENSE\`. Only NVIDIA organization members may modify files under \`cuda_bindings/\` (PR author \`$PR_AUTHOR\` has association \`$AUTHOR_ASSOCIATION\`).\n"

0 commit comments

Comments
 (0)