Skip to content

Commit e7f5618

Browse files
emily8rownmeta-codesync[bot]
authored andcommitted
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: #54819 Test Plan: (outputs shown for #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
1 parent c36665f commit e7f5618

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

  • .github/actions/diff-js-api-breaking-changes

.github/actions/diff-js-api-breaking-changes/action.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,38 @@ description: Check for breaking changes in the public React Native JS API
33
runs:
44
using: composite
55
steps:
6-
- name: Fetch snapshot from PR head
6+
- name: Checkout PR branch
7+
uses: actions/checkout@v3
8+
with:
9+
fetch-depth: 0
10+
ref: ${{ github.event.pull_request.head.sha }}
11+
12+
- name: Get merge base commit with main
13+
id: merge_base
14+
shell: bash
15+
run: |
16+
BASE=$(git merge-base ${{ github.event.pull_request.head.sha }} origin/main)
17+
echo "merge_base=$BASE" >> $GITHUB_OUTPUT
18+
19+
- name: Fetch snapshots from PR head and merge base
720
shell: bash
821
env:
922
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
1023
run: |
11-
mkdir $SCRATCH_DIR
12-
git fetch --depth=1 origin ${{ github.event.pull_request.head.sha }}
24+
mkdir -p $SCRATCH_DIR
25+
# Fetch from PR head
1326
git show ${{ github.event.pull_request.head.sha }}:packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-after.d.ts \
14-
|| echo "" > $SCRATCH_DIR/ReactNativeApi.d.ts
27+
|| echo "" > $SCRATCH_DIR/ReactNativeApi-after.d.ts
28+
# Fetch from merge base
29+
git show ${{ steps.merge_base.outputs.merge_base }}:packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-before.d.ts \
30+
|| echo "" > $SCRATCH_DIR/ReactNativeApi-before.d.ts
31+
1532
- name: Run breaking change detection
1633
shell: bash
1734
env:
1835
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
1936
run: |
2037
node ./scripts/js-api/diff-api-snapshot \
21-
${{ github.workspace }}/packages/react-native/ReactNativeApi.d.ts \
38+
$SCRATCH_DIR/ReactNativeApi-before.d.ts \
2239
$SCRATCH_DIR/ReactNativeApi-after.d.ts \
2340
> $SCRATCH_DIR/output.json

0 commit comments

Comments
 (0)