Skip to content

Commit a262a35

Browse files
committed
ci(pr): classify changed files from the merge ref when the files API 422s
The `changes` job decides whether a PR touches product code, and ci-ok requires it. It asks GitHub for the PR's file list. An earlier fix moved it off the .diff endpoint, which rejects PRs over 20k lines, onto the paginated pulls/files endpoint -- but that endpoint renders the diff server-side as well, and for a PR that regenerates a vendored parser it answers HTTP 422: Sorry, this diff is taking too long to generate. Observed on DeusData#2246 (a 42 MB sql/parser.c): `changes` red, therefore ci-ok red, for a reason that has nothing to do with the contribution. The compare endpoint fails the same way, so there is no API route to the file list for such a PR. Every grammar refresh would hit this. When the API call fails, the job now takes the list from git instead. The PR merge ref's first parent is the base, so a name-only diff across that one merge commit is exactly the PR's changed files. The fetch is depth 2 with --filter=blob:none into a bare repository under RUNNER_TEMP: commits and trees only, no blobs, nothing checked out and nothing from the PR executed. No new action, no new permission, and the API path and the classification regex are untouched, so ordinary PRs behave as before. A ::notice:: line records when the fallback was used. If the fetch fails too, the step exits non-zero and writes no output -- the gate fails closed, as it did before. Proof, by executing the workflow's own run block under `bash -eo pipefail` with a stub gh: API path, docs-only list rc 0 product=false fallback, real DeusData#2246 rc 0 product=true, the same five files `git diff --numstat` reports for the PR; 0.85 s, 188 KB fetched fallback, nonexistent merge ref rc 128 no output written Contract tests that read pr.yml -- security_gate_fail_closed, smoke_fixture_contract, windows_bundle_contract, venue_parity_contract -- pass. Not addressed here, noted for a follow-up: the classification pipes the list into `grep -q` under pipefail, which can report a match as a failure once the list outgrows the pipe buffer. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent d615088 commit a262a35

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎.github/workflows/pr.yml‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,23 @@ jobs:
6464
run: |
6565
# The full .diff endpoint rejects large-but-valid PRs at 20k lines.
6666
# The paginated files endpoint remains filename-only for this gate.
67-
FILES=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename')
67+
if FILES=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename'); then
68+
echo "file list: pulls/files API"
69+
else
70+
# The files endpoint renders the diff server-side too, and answers
71+
# 422 "this diff is taking too long to generate" for a PR that
72+
# regenerates a vendored parser (#2246: a 42 MB sql/parser.c) --
73+
# so does the compare endpoint. The PR merge ref's first parent is
74+
# the base, so a name-only diff across it is the same file list.
75+
# depth 2 + blob:none fetches commits and trees only (well under
76+
# 1 MB, under a second); nothing from the PR is checked out or run.
77+
echo "::notice::pulls/files API failed; file list taken from refs/pull/$PR/merge"
78+
CHANGES_GIT="$RUNNER_TEMP/changes.git"
79+
git init -q --bare "$CHANGES_GIT"
80+
git --git-dir="$CHANGES_GIT" fetch -q --depth=2 --filter=blob:none \
81+
"https://github.com/$REPO" "refs/pull/$PR/merge"
82+
FILES=$(git --git-dir="$CHANGES_GIT" diff --name-only --no-renames FETCH_HEAD^1 FETCH_HEAD)
83+
fi
6884
printf '%s\n' "$FILES"
6985
if printf '%s\n' "$FILES" | grep -qE '^(src/|internal/|install\.(sh|ps1)|scripts/build\.sh|scripts/smoke-test\.sh|scripts/smoke-local\.sh|scripts/smoke-fixture-server\.py|scripts/gen-third-party-notices\.sh|scripts/env\.sh|test-infrastructure/vm/(vm-smoke\.sh|windows-user-path-guard\.ps1)|Makefile\.cbm)'; then
7086
echo "product=true" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)