From 11b53096a6544e8332b6dcc4d894b096d3365b64 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 19 Oct 2025 15:58:05 -1000 Subject: [PATCH] [ci] Fix fork PR workflow failing to find PRs from forks (#11396) --- .../workflows/ci-memory-impact-comment.yml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-memory-impact-comment.yml b/.github/workflows/ci-memory-impact-comment.yml index 4ce7abfb85..eea1d2c148 100644 --- a/.github/workflows/ci-memory-impact-comment.yml +++ b/.github/workflows/ci-memory-impact-comment.yml @@ -28,20 +28,23 @@ jobs: run: | # Get PR details by searching for PR with matching head SHA # The workflow_run.pull_requests field is often empty for forks + # Use paginate to handle repos with many open PRs head_sha="${{ github.event.workflow_run.head_sha }}" - pr_data=$(gh api "/repos/${{ github.repository }}/commits/$head_sha/pulls" \ - --jq '.[0] | {number: .number, base_ref: .base.ref}') - if [ -z "$pr_data" ] || [ "$pr_data" == "null" ]; then + pr_data=$(gh api --paginate "/repos/${{ github.repository }}/pulls" \ + --jq ".[] | select(.head.sha == \"$head_sha\") | {number: .number, base_ref: .base.ref}" \ + | head -n 1) + + if [ -z "$pr_data" ]; then echo "No PR found for SHA $head_sha, skipping" - echo "skip=true" >> $GITHUB_OUTPUT + echo "skip=true" >> "$GITHUB_OUTPUT" exit 0 fi pr_number=$(echo "$pr_data" | jq -r '.number') base_ref=$(echo "$pr_data" | jq -r '.base_ref') - echo "pr_number=$pr_number" >> $GITHUB_OUTPUT - echo "base_ref=$base_ref" >> $GITHUB_OUTPUT + echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT" + echo "base_ref=$base_ref" >> "$GITHUB_OUTPUT" echo "Found PR #$pr_number targeting base branch: $base_ref" - name: Check out code from base repository @@ -87,9 +90,9 @@ jobs: if: steps.pr.outputs.skip != 'true' run: | if [ -f ./memory-analysis/memory-analysis-target.json ] && [ -f ./memory-analysis/memory-analysis-pr.json ]; then - echo "found=true" >> $GITHUB_OUTPUT + echo "found=true" >> "$GITHUB_OUTPUT" else - echo "found=false" >> $GITHUB_OUTPUT + echo "found=false" >> "$GITHUB_OUTPUT" echo "Memory analysis artifacts not found, skipping comment" fi