From b0291778cf138efba7c1c35ecfe6b947d2353776 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 30 Nov 2026 11:57:27 +0000 Subject: [PATCH] Exempt Gradle- and CocoaPods-only PRs from Meta import triage --- .../__tests__/buildToolingOnly-test.js | 94 +++++++++++++++++++ .github/workflow-scripts/buildToolingOnly.js | 56 +++++++++++ .github/workflows/meta-import-risk.yml | 54 +++++++++-- 3 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 .github/workflow-scripts/__tests__/buildToolingOnly-test.js create mode 100644 .github/workflow-scripts/buildToolingOnly.js diff --git a/.github/workflow-scripts/__tests__/buildToolingOnly-test.js b/.github/workflow-scripts/__tests__/buildToolingOnly-test.js new file mode 100644 index 000000000000..031eda3b17ed --- /dev/null +++ b/.github/workflow-scripts/__tests__/buildToolingOnly-test.js @@ -0,0 +1,94 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +'use strict'; + +const buildToolingOnly = require('../buildToolingOnly'); + +const files = (...paths) => paths.map(filename => ({filename})); + +describe('buildToolingOnly', () => { + test('exempts Gradle-only PRs, including the prefab change in #60357', () => { + expect( + buildToolingOnly( + files('packages/react-native/ReactAndroid/build.gradle.kts'), + ), + ).toBe('gradle'); + expect( + buildToolingOnly( + files( + 'settings.gradle.kts', + 'packages/react-native/gradle.properties', + 'gradle/libs.versions.toml', + 'gradle/wrapper/gradle-wrapper.properties', + ), + ), + ).toBe('gradle'); + }); + + test('exempts CocoaPods-only PRs', () => { + expect( + buildToolingOnly( + files( + 'packages/rn-tester/Podfile', + 'packages/rn-tester/Podfile.lock', + 'packages/react-native/ReactCommon/yoga/Yoga.podspec', + 'packages/react-native/scripts/cocoapods/fabric.rb', + 'packages/react-native/scripts/react_native_pods.rb', + 'packages/react-native/scripts/react_native_pods_utils/script_phases.sh', + ), + ), + ).toBe('cocoapods'); + }); + + test('does not exempt mixed or non-build changes', () => { + expect( + buildToolingOnly( + files( + 'packages/react-native/ReactAndroid/build.gradle.kts', + 'packages/react-native/ReactAndroid/src/main/java/Module.java', + ), + ), + ).toBeNull(); + expect( + buildToolingOnly( + files('packages/react-native/React-Core.podspec', 'build.gradle'), + ), + ).toBeNull(); + expect( + buildToolingOnly(files('.github/workflows/test-all.yml')), + ).toBeNull(); + expect( + buildToolingOnly( + files('packages/gradle-plugin/src/main/kotlin/Plugin.kt'), + ), + ).toBeNull(); + }); + + test('does not exempt a rename from a non-build file', () => { + expect( + buildToolingOnly([ + {filename: 'build.gradle.kts', previous_filename: 'source.kt'}, + ]), + ).toBeNull(); + }); + + test('does not trust empty or capped file lists', () => { + expect(buildToolingOnly([])).toBeNull(); + expect( + buildToolingOnly(Array(3000).fill({filename: 'build.gradle'})), + ).toBeNull(); + }); + + test('an explicit high-risk label overrides the exemption', () => { + expect( + buildToolingOnly(files('build.gradle.kts'), [{name: 'high-risk'}]), + ).toBeNull(); + }); +}); diff --git a/.github/workflow-scripts/buildToolingOnly.js b/.github/workflow-scripts/buildToolingOnly.js new file mode 100644 index 000000000000..56e99c2e6c76 --- /dev/null +++ b/.github/workflow-scripts/buildToolingOnly.js @@ -0,0 +1,56 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +'use strict'; + +function isGradleFile(path) { + return ( + /\.gradle(?:\.kts)?$/.test(path) || + /(^|\/)(?:gradle|gradle-wrapper)\.properties$/.test(path) || + /(^|\/)gradle\/libs\.versions\.toml$/.test(path) || + /(^|\/)gradlew(?:\.bat)?$/.test(path) + ); +} + +function isCocoaPodsFile(path) { + return ( + /(^|\/)(?:Podfile(?:\.lock)?|[^/]+\.podspec(?:\.json)?)$/.test(path) || + /(^|\/)scripts\/cocoapods\/.*\.(?:rb|sh)$/.test(path) || + /^packages\/react-native\/scripts\/react_native_pods(?:\.rb|_utils\/.*\.(?:rb|sh))$/.test( + path, + ) + ); +} + +// Both sides of a rename must qualify. An empty or API-capped file list is not +// evidence that the whole PR only changes build tooling. +function buildToolingOnly(files, labels = []) { + if ( + labels.some(label => label.name === 'high-risk') || + files.length === 0 || + files.length >= 3_000 + ) { + return null; + } + const paths = files.flatMap(file => + [file.filename, file.previous_filename].filter(Boolean), + ); + if (paths.length < files.length) { + return null; + } + if (paths.every(isGradleFile)) { + return 'gradle'; + } + if (paths.every(isCocoaPodsFile)) { + return 'cocoapods'; + } + return null; +} + +module.exports = buildToolingOnly; diff --git a/.github/workflows/meta-import-risk.yml b/.github/workflows/meta-import-risk.yml index 9408e87a08c4..e043c3e1a4b6 100644 --- a/.github/workflows/meta-import-risk.yml +++ b/.github/workflows/meta-import-risk.yml @@ -9,7 +9,7 @@ concurrency: cancel-in-progress: true jobs: - check_export: + check_exemptions: if: github.repository == 'react/react-native' runs-on: ubuntu-latest permissions: @@ -17,6 +17,7 @@ jobs: pull-requests: read outputs: exported: ${{ steps.check.outputs.exported }} + build_tooling: ${{ steps.check.outputs.build_tooling }} steps: - name: Checkout trusted base uses: actions/checkout@v6 @@ -25,20 +26,40 @@ jobs: persist-credentials: false # Do this before the model job, including on the PR-opened event: the # meta-codesync label may not have arrived yet. - - name: Identify Meta-exported pull requests + - name: Identify PRs exempt from Meta import risk triage id: check uses: actions/github-script@v8 with: script: | const isMetaExportedPullRequest = require('./.github/workflow-scripts/isMetaExportedPullRequest'); + const buildToolingOnly = require('./.github/workflow-scripts/buildToolingOnly'); const {data: pr} = await github.rest.pulls.get({ ...context.repo, pull_number: context.issue.number, }); - core.setOutput('exported', isMetaExportedPullRequest(pr)); + const exported = isMetaExportedPullRequest(pr); + core.setOutput('exported', exported); + if (exported) { + core.setOutput('build_tooling', 'none'); + return; + } + // On a transient file-list error, let the classifier retry and + // conservatively report an unknown risk if it cannot inspect the PR. + let category = null; + try { + const files = await github.paginate(github.rest.pulls.listFiles, { + ...context.repo, pull_number: context.issue.number, per_page: 100, + }); + category = buildToolingOnly(files, pr.labels); + } catch { + core.warning('Could not inspect changed paths for build-tooling exemption.'); + } + core.setOutput('build_tooling', category ?? 'none'); classify: - needs: check_export - if: needs.check_export.outputs.exported == 'false' + needs: check_exemptions + if: >- + needs.check_exemptions.outputs.exported == 'false' && + needs.check_exemptions.outputs.build_tooling == 'none' runs-on: ubuntu-latest timeout-minutes: 10 permissions: @@ -76,13 +97,15 @@ jobs: } label: - needs: [check_export, classify] + needs: [check_exemptions, classify] # A newer PR event cancels the old run. Do not treat its missing output as # an unknown risk; only an explicit unknown from the classifier is fail-safe. if: >- always() && !cancelled() && github.repository == 'react/react-native' && - (needs.check_export.outputs.exported == 'true' || - (needs.check_export.outputs.exported == 'false' && + (needs.check_exemptions.outputs.exported == 'true' || + contains(fromJSON('["gradle","cocoapods"]'), needs.check_exemptions.outputs.build_tooling) || + (needs.check_exemptions.outputs.exported == 'false' && + needs.check_exemptions.outputs.build_tooling == 'none' && contains(fromJSON('["low","high","unknown"]'), needs.classify.outputs.risk))) runs-on: ubuntu-latest permissions: @@ -101,7 +124,8 @@ jobs: - name: Apply Meta Review Required when needed uses: actions/github-script@v8 env: - EXPORTED: ${{ needs.check_export.outputs.exported }} + EXPORTED: ${{ needs.check_exemptions.outputs.exported }} + BUILD_TOOLING: ${{ needs.check_exemptions.outputs.build_tooling }} RISK: ${{ needs.classify.outputs.risk }} with: script: | @@ -126,6 +150,18 @@ jobs: core.setFailed('Export status changed after preflight; wait for a new PR event to classify it.'); return; } + if (process.env.BUILD_TOOLING !== 'none' && !labels.includes('high-risk')) { + if (pr.head.sha !== context.payload.pull_request.head.sha) { + core.setFailed('PR head changed after build-tooling preflight; wait for a new PR event.'); + return; + } + if (labels.includes('Meta Review Required')) { + await github.rest.issues.removeLabel({ + owner, repo, issue_number: number, name: 'Meta Review Required', + }); + } + return; + } const stale = pr.head.sha !== context.payload.pull_request.head.sha; if (process.env.RISK === 'low' && !stale && !labels.includes('high-risk')) { return;