Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
kiwidream marked this conversation as resolved.

- 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
Expand Down
14 changes: 12 additions & 2 deletions config/scripts/git-pull-request-diff-base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand All @@ -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"`,
Expand Down
15 changes: 15 additions & 0 deletions config/scripts/git-pull-request-diff-base.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
Loading