Skip to content

Commit e783f73

Browse files
authored
Merge pull request DeusData#2269 from DeusData/fix/ci-changes-large-diff-fallback
ci(pr): the changes job survives an un-renderable diff and no longer fails open on large file lists
2 parents 8b57fe2 + 65d60e7 commit e783f73

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

‎.github/workflows/pr.yml‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,29 @@ 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"
69-
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
85+
# A here-string, not a pipe: under this shell's pipefail, grep -q
86+
# exits on its first match, printf dies of SIGPIPE once the list
87+
# outgrows the pipe buffer, and the MATCH is then reported as a
88+
# failure -- product=false, smoke skipped, on the largest PRs.
89+
if 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)' <<<"$FILES"; then
7090
echo "product=true" >> "$GITHUB_OUTPUT"
7191
else
7292
echo "product=false" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)