Skip to content

Add diff-api-snapshot action to danger #52045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/diff-js-api-breaking-changes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: diff-js-api-breaking-changes
description: Check for breaking changes in the public React Native JS API=
runs:
using: composite
steps:
- name: Fetch snapshot from PR head
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 }}
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
- name: Run breaking change detection
shell: bash
env:
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-breaking-changes
run: |
node ./scripts/diff-api-snapshot \
${{ github.workspace }}/packages/react-native/ReactNativeApi.d.ts \
$SCRATCH_DIR/ReactNativeApi-after.d.ts \
> $SCRATCH_DIR/output.json
2 changes: 2 additions & 0 deletions .github/workflows/danger-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
uses: ./.github/actions/setup-node
- name: Run yarn install
uses: ./.github/actions/yarn-install
- name: Run diff-js-api-breaking-changes
uses: ./.github/actions/diff-js-api-breaking-changes
- name: Danger
run: yarn danger ci --use-github-checks --failOnErrors
working-directory: private/react-native-bots
Expand Down
21 changes: 21 additions & 0 deletions private/react-native-bots/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
'use strict';

const {danger, fail, warn} = require('danger');
const fs = require('fs');
const path = require('path');

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

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

const snapshot_output = JSON.parse(
fs.readFileSync(
path.join(
process.env.RUNNER_TEMP,
'diff-js-api-breaking-changes/output.json',
),
'utf8',
),
);
if (snapshot_output && snapshot_output.result !== 'NON_BREAKING') {
const title = ':exclamation: JavaScript API change detected';
const idea =
'This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API. ' +
'Please include a clear changelog message. ' +
'This change will be subject to extra review.\n\n' +
`This change was flagged as: <code>${snapshot_output.result}</code>`;
warn(`${title} - <i>${idea}</i>`);
}

const hasNoUsefulBody =
!danger.github.pr.body || danger.github.pr.body.length < 50;
const hasTooShortAHumanSummary =
Expand Down
Loading