diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 27fc5215044d..9ca603c319ad 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -218,12 +218,36 @@ jobs: - uses: ./.github/actions/install-mobile-dependencies if: needs.code_paths.outputs.mobile_dependencies == 'true' + # LOCAL: a sync PR merges all of upstream into swaplabs/main, and every upstream line + # would otherwise count as changed here. Gate only the fork's own lines: those added + # since the upstream commit the PR merges, where it meets this repository's mirror `main`. + # Only the two changed-line gates read it; trigger checks below keep diffing against HEAD^1. + - name: Scope changed-line gates to the fork's own lines on a sync PR + id: sync-pr-diff-base + if: >- + github.event.pull_request.head.repo.full_name == github.repository && + github.base_ref == 'swaplabs/main' && + (github.head_ref == 'main' || startsWith(github.head_ref, 'sync/upstream-')) + run: | + set -uo pipefail + if git fetch --no-tags --depth=50 origin main && + upstream="$(git merge-base HEAD FETCH_HEAD)"; then + echo "base=$upstream" >> "$GITHUB_OUTPUT" + echo "Gating the fork's lines since upstream $upstream" + else + echo "::warning::Could not find where this sync PR meets upstream main; gating every changed line." + fi + - name: Enforce changed-code quality id: changed-code-quality background: true + env: + ORCA_SYNC_PR_DIFF_BASE: ${{ steps.sync-pr-diff-base.outputs.base }} run: pnpm run check:code-quality:changed -- "${{ github.event.pull_request.base.sha }}" - name: Enforce React Doctor on changed lines + env: + ORCA_SYNC_PR_DIFF_BASE: ${{ steps.sync-pr-diff-base.outputs.base }} run: pnpm run check:react-doctor:changed -- "${{ github.event.pull_request.base.sha }}" - wait: changed-code-quality diff --git a/config/scripts/git-pull-request-diff-base.mjs b/config/scripts/git-pull-request-diff-base.mjs index 0dd5b825ef78..1a81ff1a9556 100644 --- a/config/scripts/git-pull-request-diff-base.mjs +++ b/config/scripts/git-pull-request-diff-base.mjs @@ -2,7 +2,12 @@ import { execFileSync } from 'node:child_process' import process from 'node:process' import { pathToFileURL } from 'node:url' -export function selectPullRequestDiffBase(requestedBase, headParents, eventName) { +export function selectPullRequestDiffBase(requestedBase, headParents, eventName, syncBase) { + // LOCAL: a SwapLabs sync PR brings in all of upstream, which upstream's own CI already gated. + // The workflow sets the upstream commit it merges so changed-line gates see only the fork's lines. + if (syncBase) { + return syncBase + } if (eventName === 'pull_request' && headParents.length >= 2) { return headParents[0] } @@ -20,7 +25,12 @@ export function resolvePullRequestDiffBase( }) .trim() .split(/\s+/) - return selectPullRequestDiffBase(requestedBase, headParents, eventName) + return selectPullRequestDiffBase( + requestedBase, + headParents, + eventName, + process.env.ORCA_SYNC_PR_DIFF_BASE + ) } // Why a CLI: the workflow's inline gates used `git diff --merge-base "$BASE_SHA" "$HEAD_SHA"`, diff --git a/config/scripts/git-pull-request-diff-base.test.mjs b/config/scripts/git-pull-request-diff-base.test.mjs index 4c1e0b8497f4..ed7ef1e24f32 100644 --- a/config/scripts/git-pull-request-diff-base.test.mjs +++ b/config/scripts/git-pull-request-diff-base.test.mjs @@ -16,4 +16,19 @@ describe('pull request diff base selection', () => { 'requested-base' ) }) + + // LOCAL: set only for the fork's own upstream sync PRs. + it('prefers the sync base over the merge commit first parent', () => { + expect( + selectPullRequestDiffBase( + 'event-base', + ['current-base', 'sync-head'], + 'pull_request', + 'upstream-tip' + ) + ).toBe('upstream-tip') + expect( + selectPullRequestDiffBase('event-base', ['current-base', 'sync-head'], 'pull_request', '') + ).toBe('current-base') + }) })