From e7f56182d69347e0680f31a495b356eb66f9d331 Mon Sep 17 00:00:00 2001 From: emily8rown Date: Wed, 10 Dec 2025 04:55:52 -0800 Subject: [PATCH] Fix JS API breaking change detection to compare against merge base (#54819) Summary: Updates the `diff-js-api-breaking-changes` action to compare the PR's changes against the merge base (where the branch diverged from main) instead of the current tip of main. ### Problem The previous implementation compared the current state of `main` to the PR head. This could produce false positive results when main had new commits to reactNativeApi.d.ts reporting breaking changes from main as if they were introduced by the PR. ### Solution - Calculate the merge base between the PR head and `origin/main` - Compare the API snapshot at the merge base to the snapshot at the PR head ## Changelog: [GENERAL] [FIXED] - Updates the `diff-js-api-breaking-changes` action to compare the PR's changes against the merge base (where the branch diverged from main) instead of the current tip of main. Pull Request resolved: https://github.com/facebook/react-native/pull/54819 Test Plan: (outputs shown for https://github.com/facebook/react-native/pull/54815) Tested locally on branch that previously got false positive: Mirror old approach: ``` mkdir -p /tmp/api-diff-old git show origin/main:packages/react-native/ReactNativeApi.d.ts > /tmp/api-diff-old/before.d.ts git show HEAD:packages/react-native/ReactNativeApi.d.ts > /tmp/api-diff-old/after.d.ts node ./scripts/js-api/diff-api-snapshot /tmp/api-diff-old/before.d.ts /tmp/api-diff-old/after.d.ts ``` output: ``` { "result": "BREAKING", "changedApis": [ "ActivityIndicatorProps", "Animated", "DrawerLayoutAndroidProps", "FlatList", "FlatListProps", "ImageBackground", "ImageBackgroundProps", "ImageProps", "ImagePropsBase", "KeyDownEvent", "KeyEvent", "KeyUpEvent", "KeyboardAvoidingView", "KeyboardAvoidingViewProps", "ModalProps", "PressableProps", "ProgressBarAndroidProps", "RefreshControl", "RefreshControlProps", "ScrollViewProps", "SectionList", "SectionListProps", "SwitchProps", "TextInputProps", "ViewProps", "VirtualizedListProps", "VirtualizedSectionListProps" ] } ``` Mirror new approach: ``` git fetch origin main MERGE_BASE=$(git merge-base HEAD origin/main) echo "Merge base: $MERGE_BASE" mkdir -p /tmp/api-diff git show $MERGE_BASE:packages/react-native/ReactNativeApi.d.ts > /tmp/api-diff/before.d.ts git show HEAD:packages/react-native/ReactNativeApi.d.ts > /tmp/api-diff/after.d.ts node ./scripts/js-api/diff-api-snapshot /tmp/api-diff/before.d.ts /tmp/api-diff/after.d.ts ``` output: ``` { "result": "NON_BREAKING", "changedApis": [] } ``` Reviewed By: huntie Differential Revision: D88654826 Pulled By: emily8rown fbshipit-source-id: 5dc2e295d7d527899b5cb6a643c4878aeebf7f0b --- .../diff-js-api-breaking-changes/action.yml | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/.github/actions/diff-js-api-breaking-changes/action.yml b/.github/actions/diff-js-api-breaking-changes/action.yml index bc45b1b207a..4b5db7bfcd2 100644 --- a/.github/actions/diff-js-api-breaking-changes/action.yml +++ b/.github/actions/diff-js-api-breaking-changes/action.yml @@ -3,21 +3,38 @@ description: Check for breaking changes in the public React Native JS API runs: using: composite steps: - - name: Fetch snapshot from PR head + - name: Checkout PR branch + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} + + - name: Get merge base commit with main + id: merge_base + shell: bash + run: | + BASE=$(git merge-base ${{ github.event.pull_request.head.sha }} origin/main) + echo "merge_base=$BASE" >> $GITHUB_OUTPUT + + - name: Fetch snapshots from PR head and merge base shell: bash env: SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes run: | - mkdir $SCRATCH_DIR - git fetch --depth=1 origin ${{ github.event.pull_request.head.sha }} + mkdir -p $SCRATCH_DIR + # Fetch from PR head git show ${{ github.event.pull_request.head.sha }}:packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-after.d.ts \ - || echo "" > $SCRATCH_DIR/ReactNativeApi.d.ts + || echo "" > $SCRATCH_DIR/ReactNativeApi-after.d.ts + # Fetch from merge base + git show ${{ steps.merge_base.outputs.merge_base }}:packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-before.d.ts \ + || echo "" > $SCRATCH_DIR/ReactNativeApi-before.d.ts + - name: Run breaking change detection shell: bash env: SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes run: | node ./scripts/js-api/diff-api-snapshot \ - ${{ github.workspace }}/packages/react-native/ReactNativeApi.d.ts \ + $SCRATCH_DIR/ReactNativeApi-before.d.ts \ $SCRATCH_DIR/ReactNativeApi-after.d.ts \ > $SCRATCH_DIR/output.json