Skip to content

Commit 8e4a9e7

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. ## 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 Reviewed By: huntie Differential Revision: D76735630 Pulled By: coado
1 parent bda6639 commit 8e4a9e7

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&#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)