Skip to content

Commit b41b924

Browse files
coadofacebook-github-bot
authored andcommitted
Add diff-api-snapshot action to danger (facebook#52045)
Summary: This PR connects breaking change detection with a danger bot. The action takes snapshot from main branch and from the PR as inputs to`diff-api-snapshot` (saved in runner temp directory). ## Changelog: [Internal] For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: facebook#52045 Reviewed By: huntie Differential Revision: D76735630 Pulled By: coado fbshipit-source-id: 9208117340c1e0bf10d58b67892727717d22e62f
1 parent 71f2f05 commit b41b924

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: diff-js-api-breaking-changes
2+
description: Check for breaking changes in the public React Native JS API
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Fetch snapshot from PR head
7+
shell: bash
8+
env:
9+
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
10+
run: |
11+
mkdir $SCRATCH_DIR
12+
git fetch --depth=1 origin ${{ github.event.pull_request.head.sha }}
13+
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
15+
- name: Run breaking change detection
16+
shell: bash
17+
env:
18+
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
19+
run: |
20+
node ./scripts/diff-api-snapshot \
21+
${{ github.workspace }}/packages/react-native/ReactNativeApi.d.ts \
22+
$SCRATCH_DIR/ReactNativeApi-after.d.ts \
23+
> $SCRATCH_DIR/output.json

.github/workflows/danger-pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222
uses: ./.github/actions/setup-node
2323
- name: Run yarn install
2424
uses: ./.github/actions/yarn-install
25+
- name: Run diff-js-api-breaking-changes
26+
uses: ./.github/actions/diff-js-api-breaking-changes
2527
- name: Danger
2628
run: yarn danger ci --use-github-checks --failOnErrors
2729
working-directory: private/react-native-bots

private/react-native-bots/dangerfile.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'use strict';
1212

1313
const {danger, fail, warn} = require('danger');
14+
const fs = require('fs');
15+
const path = require('path');
1416

1517
const body = danger.github.pr.body?.toLowerCase() ?? '';
1618

@@ -28,6 +30,25 @@ const isFromPhabricator = body_contains('differential revision:');
2830
// Provides advice if a summary section is missing, or body is too short
2931
const includesSummary = body_contains('## summary', 'summary:');
3032

33+
const snapshot_output = JSON.parse(
34+
fs.readFileSync(
35+
path.join(
36+
process.env.RUNNER_TEMP,
37+
'diff-js-api-breaking-changes/output.json',
38+
),
39+
'utf8',
40+
),
41+
);
42+
if (snapshot_output && snapshot_output.result !== 'NON_BREAKING') {
43+
const title = ':exclamation: JavaScript API change detected';
44+
const idea =
45+
'This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. ' +
46+
'Please include a clear changelog message. ' +
47+
'This change will be subject to extra review.\n\n' +
48+
`This change was flagged as: <code>${snapshot_output.result}</code>`;
49+
warn(`${title} - <i>${idea}</i>`);
50+
}
51+
3152
const hasNoUsefulBody =
3253
!danger.github.pr.body || danger.github.pr.body.length < 50;
3354
const hasTooShortAHumanSummary =

0 commit comments

Comments
 (0)