@@ -2,16 +2,44 @@ name: Meta import risk
22
33on :
44 pull_request_target :
5- types : [opened, reopened, synchronize, labeled]
5+ types : [opened, reopened, synchronize, edited, labeled]
66
77concurrency :
88 group : meta-import-risk-${{ github.event.pull_request.number }}
99 cancel-in-progress : true
1010
1111jobs :
12- classify :
12+ check_export :
1313 if : github.repository == 'react/react-native'
1414 runs-on : ubuntu-latest
15+ permissions :
16+ contents : read
17+ pull-requests : read
18+ outputs :
19+ exported : ${{ steps.check.outputs.exported }}
20+ steps :
21+ - name : Checkout trusted base
22+ uses : actions/checkout@v6
23+ with :
24+ ref : ${{ github.event.pull_request.base.sha }}
25+ persist-credentials : false
26+ # Do this before the model job, including on the PR-opened event: the
27+ # meta-codesync label may not have arrived yet.
28+ - name : Identify Meta-exported pull requests
29+ id : check
30+ uses : actions/github-script@v8
31+ with :
32+ script : |
33+ const isMetaExportedPullRequest = require('./.github/workflow-scripts/isMetaExportedPullRequest');
34+ const {data: pr} = await github.rest.pulls.get({
35+ ...context.repo, pull_number: context.issue.number,
36+ });
37+ core.setOutput('exported', isMetaExportedPullRequest(pr));
38+
39+ classify :
40+ needs : check_export
41+ if : needs.check_export.outputs.exported == 'false'
42+ runs-on : ubuntu-latest
1543 timeout-minutes : 10
1644 permissions :
1745 contents : read
@@ -45,31 +73,56 @@ jobs:
4573 }
4674
4775 label :
48- needs : classify
76+ needs : [check_export, classify]
4977 # A newer PR event cancels the old run. Do not treat its missing output as
5078 # an unknown risk; only an explicit unknown from the classifier is fail-safe.
5179 if : >-
5280 always() && !cancelled() && github.repository == 'react/react-native' &&
53- contains(fromJSON('["low","high","unknown"]'), needs.classify.outputs.risk)
81+ (needs.check_export.outputs.exported == 'true' ||
82+ (needs.check_export.outputs.exported == 'false' &&
83+ contains(fromJSON('["low","high","unknown"]'), needs.classify.outputs.risk)))
5484 runs-on : ubuntu-latest
5585 permissions :
86+ contents : read
5687 # Applying a label to a PR requires PR write access, even though the
5788 # REST endpoint is under issues. Keep this out of the classifier job.
5889 pull-requests : write
5990 issues : write
6091 steps :
61- # This job has write access but no model secret and no PR checkout.
92+ # Only trusted base code is checked out; this job has no model secret.
93+ - name : Checkout trusted base
94+ uses : actions/checkout@v6
95+ with :
96+ ref : ${{ github.event.pull_request.base.sha }}
97+ persist-credentials : false
6298 - name : Apply Meta Review Required when needed
6399 uses : actions/github-script@v8
64100 env :
101+ EXPORTED : ${{ needs.check_export.outputs.exported }}
65102 RISK : ${{ needs.classify.outputs.risk }}
66103 with :
67104 script : |
105+ const isMetaExportedPullRequest = require('./.github/workflow-scripts/isMetaExportedPullRequest');
68106 const owner = context.repo.owner;
69107 const repo = context.repo.repo;
70108 const number = context.issue.number;
71109 const {data: pr} = await github.rest.pulls.get({owner, repo, pull_number: number});
72110 const labels = pr.labels.map(label => label.name);
111+ // Re-check current metadata in case meta-codesync labeled the PR
112+ // after the first check. An exported PR needs neither classification
113+ // nor a lingering Meta Review Required label.
114+ if (isMetaExportedPullRequest(pr)) {
115+ if (labels.includes('Meta Review Required')) {
116+ await github.rest.issues.removeLabel({
117+ owner, repo, issue_number: number, name: 'Meta Review Required',
118+ });
119+ }
120+ return;
121+ }
122+ if (process.env.EXPORTED === 'true') {
123+ core.setFailed('Export status changed after preflight; wait for a new PR event to classify it.');
124+ return;
125+ }
73126 const stale = pr.head.sha !== context.payload.pull_request.head.sha;
74127 if (process.env.RISK === 'low' && !stale && !labels.includes('high-risk')) {
75128 return;
0 commit comments