Skip to content

Commit e11aca5

Browse files
coadofacebook-github-bot
authored andcommitted
Add diff-api-snapshot action to danger (#52045)
Summary: This is a work in progress PR that adds breaking change detection to danger. The danger is ran on a base revision from which there is no easy access to the API snapshot from the PR. The Github action fetches the PR and stores the "current" snapshot in the temporary directory which is then used in the `diff-api-snapshot` script. It is compared to the previous snapshot from the base revision which can be easily accessed by reading from `packages/react-native/ReactNativeApi.d.ts`. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Test Plan: Tested on react-native fork with personal access token. {F1979339175} coado#16 Differential Revision: D76735630 Pulled By: coado
1 parent f338db9 commit e11aca5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
env:
6+
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
7+
steps:
8+
- name: Fetch snapshot from PR head
9+
shell: bash
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+
run: |
18+
node ./scripts/diff-api-snapshot \
19+
${{ github.workspace }}/packages/react-native/ReactNativeApi.d.ts \
20+
$SCRATCH_DIR/ReactNativeApi-after.d.ts \
21+
> $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&#39;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)