Skip to content
Open
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
36 changes: 36 additions & 0 deletions .github/actions/diff-js-api-changes/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: diff-js-api-changes
description: Check for breaking changes in the public React Native JS API
outputs:
message:
description: Formatted markdown message describing API changes, or empty if no changes
value: ${{ steps.format_output.outputs.message }}
runs:
using: composite
steps:
Expand Down Expand Up @@ -35,3 +39,35 @@ runs:
$SCRATCH_DIR/ReactNativeApi-before.d.ts \
$SCRATCH_DIR/ReactNativeApi-after.d.ts \
> $SCRATCH_DIR/output.json

- name: Format output message
id: format_output
shell: bash
env:
SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-changes
run: |
if [ ! -f "$SCRATCH_DIR/output.json" ]; then
echo "message=" >> $GITHUB_OUTPUT
exit 0
fi

RESULT=$(cat $SCRATCH_DIR/output.json | jq -r '.result // empty')
if [ -z "$RESULT" ] || [ "$RESULT" = "NON_BREAKING" ]; then
echo "message=" >> $GITHUB_OUTPUT
exit 0
fi

# Use delimiter for multiline output
{
echo "message<<EOF"
echo "> [!WARNING]"
echo "> **JavaScript API change detected**"
echo ">"
echo "> This PR commits an update to \`ReactNativeApi.d.ts\`, indicating a change to React Native's public JavaScript API."
echo ">"
echo "> - Please include a **clear changelog message**."
echo "> - This change will be subject to additional review."
echo ">"
echo "> This change was flagged as: \`${RESULT}\`"
echo "EOF"
} >> $GITHUB_OUTPUT
55 changes: 55 additions & 0 deletions .github/actions/post-pr-comment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: post-pr-comment
description: Post or update a PR comment, or delete if no sections
inputs:
sections:
description: 'JSON array of markdown sections to include in comment'
required: false
default: '[]'
header:
description: 'Optional header text to display at the top of the comment'
required: false
default: ''
marker:
description: 'HTML comment marker to identify this comment'
required: true
runs:
using: composite
steps:
- name: Create, update, or delete comment
uses: actions/github-script@v8
env:
SECTIONS_INPUT: ${{ inputs.sections }}
MARKER_INPUT: ${{ inputs.marker }}
HEADER_INPUT: ${{ inputs.header }}
with:
script: |
const marker = process.env.MARKER_INPUT;
const header = process.env.HEADER_INPUT;
const sections = JSON.parse(process.env.SECTIONS_INPUT)
.filter(Boolean)
.filter(s => s.trim());

const {owner, repo} = context.repo;
const issue_number = context.issue.number;

const {data: comments} = await github.rest.issues.listComments({
owner, repo, issue_number,
});

const existing = comments.find(c => c.body?.includes(marker));

if (!sections.length) {
if (existing) {
await github.rest.issues.deleteComment({owner, repo, comment_id: existing.id});
}
return;
}

const content = sections.join('\n\n');
const body = header ? `${marker}\n## ${header}\n\n${content}` : `${marker}\n${content}`;

if (existing) {
await github.rest.issues.updateComment({owner, repo, comment_id: existing.id, body});
} else {
await github.rest.issues.createComment({owner, repo, issue_number, body});
}
28 changes: 28 additions & 0 deletions .github/workflows/api-changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Validate API snapshot changes

on:
pull_request_target:
types: [opened, edited, reopened, synchronize]

permissions:
pull-requests: write

jobs:
api-changes:
runs-on: ubuntu-latest
if: github.repository == 'facebook/react-native'
steps:
- name: Check out main branch
uses: actions/checkout@v6
- name: Setup Node.js
uses: ./.github/actions/setup-node
- name: Run yarn install
uses: ./.github/actions/yarn-install
- name: Run diff-js-api-changes
id: diff-js-api-changes
uses: ./.github/actions/diff-js-api-changes
- name: Post PR comment
uses: ./.github/actions/post-pr-comment
with:
marker: '<!-- api-changes -->'
sections: '[${{ toJSON(steps.diff-js-api-changes.outputs.message) }}]'
Loading