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: - name: Fetch PR and main, compute merge base id: merge_base shell: bash env: PR_SHA: ${{ github.event.pull_request.head.sha }} run: | git fetch origin main git fetch origin "$PR_SHA" --depth=500 echo "merge_base=$(git merge-base "$PR_SHA" origin/main)" >> $GITHUB_OUTPUT - name: Extract before and after API snapshots shell: bash env: SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-changes MERGE_BASE: ${{ steps.merge_base.outputs.merge_base }} PR_SHA: ${{ github.event.pull_request.head.sha }} run: | mkdir -p $SCRATCH_DIR git show "$MERGE_BASE":packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-before.d.ts \ || echo "" > $SCRATCH_DIR/ReactNativeApi-before.d.ts git show "$PR_SHA":packages/react-native/ReactNativeApi.d.ts > $SCRATCH_DIR/ReactNativeApi-after.d.ts \ || echo "" > $SCRATCH_DIR/ReactNativeApi-after.d.ts - name: Run breaking change detection shell: bash env: SCRATCH_DIR: ${{ runner.temp }}/diff-js-api-changes run: | node ./scripts/js-api/diff-api-snapshot \ $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< [!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