Skip to content

Commit e320a73

Browse files
authored
Exempt Gradle- and CocoaPods-only PRs from Meta import triage (#60397)
1 parent fb747cb commit e320a73

3 files changed

Lines changed: 195 additions & 9 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const buildToolingOnly = require('../buildToolingOnly');
13+
14+
const files = (...paths) => paths.map(filename => ({filename}));
15+
16+
describe('buildToolingOnly', () => {
17+
test('exempts Gradle-only PRs, including the prefab change in #60357', () => {
18+
expect(
19+
buildToolingOnly(
20+
files('packages/react-native/ReactAndroid/build.gradle.kts'),
21+
),
22+
).toBe('gradle');
23+
expect(
24+
buildToolingOnly(
25+
files(
26+
'settings.gradle.kts',
27+
'packages/react-native/gradle.properties',
28+
'gradle/libs.versions.toml',
29+
'gradle/wrapper/gradle-wrapper.properties',
30+
),
31+
),
32+
).toBe('gradle');
33+
});
34+
35+
test('exempts CocoaPods-only PRs', () => {
36+
expect(
37+
buildToolingOnly(
38+
files(
39+
'packages/rn-tester/Podfile',
40+
'packages/rn-tester/Podfile.lock',
41+
'packages/react-native/ReactCommon/yoga/Yoga.podspec',
42+
'packages/react-native/scripts/cocoapods/fabric.rb',
43+
'packages/react-native/scripts/react_native_pods.rb',
44+
'packages/react-native/scripts/react_native_pods_utils/script_phases.sh',
45+
),
46+
),
47+
).toBe('cocoapods');
48+
});
49+
50+
test('does not exempt mixed or non-build changes', () => {
51+
expect(
52+
buildToolingOnly(
53+
files(
54+
'packages/react-native/ReactAndroid/build.gradle.kts',
55+
'packages/react-native/ReactAndroid/src/main/java/Module.java',
56+
),
57+
),
58+
).toBeNull();
59+
expect(
60+
buildToolingOnly(
61+
files('packages/react-native/React-Core.podspec', 'build.gradle'),
62+
),
63+
).toBeNull();
64+
expect(
65+
buildToolingOnly(files('.github/workflows/test-all.yml')),
66+
).toBeNull();
67+
expect(
68+
buildToolingOnly(
69+
files('packages/gradle-plugin/src/main/kotlin/Plugin.kt'),
70+
),
71+
).toBeNull();
72+
});
73+
74+
test('does not exempt a rename from a non-build file', () => {
75+
expect(
76+
buildToolingOnly([
77+
{filename: 'build.gradle.kts', previous_filename: 'source.kt'},
78+
]),
79+
).toBeNull();
80+
});
81+
82+
test('does not trust empty or capped file lists', () => {
83+
expect(buildToolingOnly([])).toBeNull();
84+
expect(
85+
buildToolingOnly(Array(3000).fill({filename: 'build.gradle'})),
86+
).toBeNull();
87+
});
88+
89+
test('an explicit high-risk label overrides the exemption', () => {
90+
expect(
91+
buildToolingOnly(files('build.gradle.kts'), [{name: 'high-risk'}]),
92+
).toBeNull();
93+
});
94+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
function isGradleFile(path) {
13+
return (
14+
/\.gradle(?:\.kts)?$/.test(path) ||
15+
/(^|\/)(?:gradle|gradle-wrapper)\.properties$/.test(path) ||
16+
/(^|\/)gradle\/libs\.versions\.toml$/.test(path) ||
17+
/(^|\/)gradlew(?:\.bat)?$/.test(path)
18+
);
19+
}
20+
21+
function isCocoaPodsFile(path) {
22+
return (
23+
/(^|\/)(?:Podfile(?:\.lock)?|[^/]+\.podspec(?:\.json)?)$/.test(path) ||
24+
/(^|\/)scripts\/cocoapods\/.*\.(?:rb|sh)$/.test(path) ||
25+
/^packages\/react-native\/scripts\/react_native_pods(?:\.rb|_utils\/.*\.(?:rb|sh))$/.test(
26+
path,
27+
)
28+
);
29+
}
30+
31+
// Both sides of a rename must qualify. An empty or API-capped file list is not
32+
// evidence that the whole PR only changes build tooling.
33+
function buildToolingOnly(files, labels = []) {
34+
if (
35+
labels.some(label => label.name === 'high-risk') ||
36+
files.length === 0 ||
37+
files.length >= 3_000
38+
) {
39+
return null;
40+
}
41+
const paths = files.flatMap(file =>
42+
[file.filename, file.previous_filename].filter(Boolean),
43+
);
44+
if (paths.length < files.length) {
45+
return null;
46+
}
47+
if (paths.every(isGradleFile)) {
48+
return 'gradle';
49+
}
50+
if (paths.every(isCocoaPodsFile)) {
51+
return 'cocoapods';
52+
}
53+
return null;
54+
}
55+
56+
module.exports = buildToolingOnly;

‎.github/workflows/meta-import-risk.yml‎

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ concurrency:
99
cancel-in-progress: true
1010

1111
jobs:
12-
check_export:
12+
check_exemptions:
1313
if: github.repository == 'react/react-native'
1414
runs-on: ubuntu-latest
1515
permissions:
1616
contents: read
1717
pull-requests: read
1818
outputs:
1919
exported: ${{ steps.check.outputs.exported }}
20+
build_tooling: ${{ steps.check.outputs.build_tooling }}
2021
steps:
2122
- name: Checkout trusted base
2223
uses: actions/checkout@v6
@@ -25,20 +26,40 @@ jobs:
2526
persist-credentials: false
2627
# Do this before the model job, including on the PR-opened event: the
2728
# meta-codesync label may not have arrived yet.
28-
- name: Identify Meta-exported pull requests
29+
- name: Identify PRs exempt from Meta import risk triage
2930
id: check
3031
uses: actions/github-script@v8
3132
with:
3233
script: |
3334
const isMetaExportedPullRequest = require('./.github/workflow-scripts/isMetaExportedPullRequest');
35+
const buildToolingOnly = require('./.github/workflow-scripts/buildToolingOnly');
3436
const {data: pr} = await github.rest.pulls.get({
3537
...context.repo, pull_number: context.issue.number,
3638
});
37-
core.setOutput('exported', isMetaExportedPullRequest(pr));
39+
const exported = isMetaExportedPullRequest(pr);
40+
core.setOutput('exported', exported);
41+
if (exported) {
42+
core.setOutput('build_tooling', 'none');
43+
return;
44+
}
45+
// On a transient file-list error, let the classifier retry and
46+
// conservatively report an unknown risk if it cannot inspect the PR.
47+
let category = null;
48+
try {
49+
const files = await github.paginate(github.rest.pulls.listFiles, {
50+
...context.repo, pull_number: context.issue.number, per_page: 100,
51+
});
52+
category = buildToolingOnly(files, pr.labels);
53+
} catch {
54+
core.warning('Could not inspect changed paths for build-tooling exemption.');
55+
}
56+
core.setOutput('build_tooling', category ?? 'none');
3857
3958
classify:
40-
needs: check_export
41-
if: needs.check_export.outputs.exported == 'false'
59+
needs: check_exemptions
60+
if: >-
61+
needs.check_exemptions.outputs.exported == 'false' &&
62+
needs.check_exemptions.outputs.build_tooling == 'none'
4263
runs-on: ubuntu-latest
4364
timeout-minutes: 10
4465
permissions:
@@ -76,13 +97,15 @@ jobs:
7697
}
7798
7899
label:
79-
needs: [check_export, classify]
100+
needs: [check_exemptions, classify]
80101
# A newer PR event cancels the old run. Do not treat its missing output as
81102
# an unknown risk; only an explicit unknown from the classifier is fail-safe.
82103
if: >-
83104
always() && !cancelled() && github.repository == 'react/react-native' &&
84-
(needs.check_export.outputs.exported == 'true' ||
85-
(needs.check_export.outputs.exported == 'false' &&
105+
(needs.check_exemptions.outputs.exported == 'true' ||
106+
contains(fromJSON('["gradle","cocoapods"]'), needs.check_exemptions.outputs.build_tooling) ||
107+
(needs.check_exemptions.outputs.exported == 'false' &&
108+
needs.check_exemptions.outputs.build_tooling == 'none' &&
86109
contains(fromJSON('["low","high","unknown"]'), needs.classify.outputs.risk)))
87110
runs-on: ubuntu-latest
88111
permissions:
@@ -101,7 +124,8 @@ jobs:
101124
- name: Apply Meta Review Required when needed
102125
uses: actions/github-script@v8
103126
env:
104-
EXPORTED: ${{ needs.check_export.outputs.exported }}
127+
EXPORTED: ${{ needs.check_exemptions.outputs.exported }}
128+
BUILD_TOOLING: ${{ needs.check_exemptions.outputs.build_tooling }}
105129
RISK: ${{ needs.classify.outputs.risk }}
106130
with:
107131
script: |
@@ -126,6 +150,18 @@ jobs:
126150
core.setFailed('Export status changed after preflight; wait for a new PR event to classify it.');
127151
return;
128152
}
153+
if (process.env.BUILD_TOOLING !== 'none' && !labels.includes('high-risk')) {
154+
if (pr.head.sha !== context.payload.pull_request.head.sha) {
155+
core.setFailed('PR head changed after build-tooling preflight; wait for a new PR event.');
156+
return;
157+
}
158+
if (labels.includes('Meta Review Required')) {
159+
await github.rest.issues.removeLabel({
160+
owner, repo, issue_number: number, name: 'Meta Review Required',
161+
});
162+
}
163+
return;
164+
}
129165
const stale = pr.head.sha !== context.payload.pull_request.head.sha;
130166
if (process.env.RISK === 'low' && !stale && !labels.includes('high-risk')) {
131167
return;

0 commit comments

Comments
 (0)