Repository navigation
Bump terser from 5.31.6 to 5.51.4 #864
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Meta import risk | ||
|
Check warning on line 1 in .github/workflows/meta-import-risk.yml
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, reopened, synchronize, edited, labeled] | ||
| concurrency: | ||
| group: meta-import-risk-${{ github.event.pull_request.number }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| check_exemptions: | ||
| if: github.repository == 'react/react-native' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| 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 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.sha }} | ||
| 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 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, | ||
| }); | ||
| 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_exemptions | ||
| if: >- | ||
| needs.check_exemptions.outputs.exported == 'false' && | ||
| needs.check_exemptions.outputs.build_tooling == 'none' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
| outputs: | ||
| risk: ${{ steps.assess.outputs.risk }} | ||
| steps: | ||
| # pull_request_target has access to the model secret even for fork PRs. | ||
| # Only the trusted base commit is checked out; PR code is read as data | ||
| # through the GitHub API and is never executed on this runner. | ||
| - name: Checkout trusted base | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.sha }} | ||
| persist-credentials: false | ||
| - name: Assess changed files and patch with Muse | ||
| id: assess | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| META_API_KEY: ${{ secrets.EXPO_CODE_REVIEW_API_KEY }} | ||
| with: | ||
| script: | | ||
| const {assessPullRequest} = require('./.github/workflow-scripts/metaImportRisk'); | ||
| const result = await assessPullRequest({ | ||
| github, context, apiKey: process.env.META_API_KEY, | ||
| }); | ||
| core.setOutput('risk', result.status); | ||
| core.info(`Meta import risk: ${result.status}`); | ||
| // Log only the validated, bounded decision and failure category. | ||
| // Never log the raw patch, model response, or API credential. | ||
| core.info(`Meta import Muse trace: ${JSON.stringify(result.trace)}`); | ||
| if (!result.aiComplete) { | ||
| core.setFailed('Muse did not assess the complete PR diff; the labeling job will conservatively request Meta review.'); | ||
| } | ||
| label: | ||
| 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_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: | ||
| contents: read | ||
| # Applying a label to a PR requires PR write access, even though the | ||
| # REST endpoint is under issues. Keep this out of the classifier job. | ||
| pull-requests: write | ||
| issues: write | ||
| steps: | ||
| # Only trusted base code is checked out; this job has no model secret. | ||
| - name: Checkout trusted base | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| ref: ${{ github.event.pull_request.base.sha }} | ||
| persist-credentials: false | ||
| - name: Apply Meta Review Required when needed | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| EXPORTED: ${{ needs.check_exemptions.outputs.exported }} | ||
| BUILD_TOOLING: ${{ needs.check_exemptions.outputs.build_tooling }} | ||
| RISK: ${{ needs.classify.outputs.risk }} | ||
| with: | ||
| script: | | ||
| const isMetaExportedPullRequest = require('./.github/workflow-scripts/isMetaExportedPullRequest'); | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const number = context.issue.number; | ||
| const {data: pr} = await github.rest.pulls.get({owner, repo, pull_number: number}); | ||
| const labels = pr.labels.map(label => label.name); | ||
| // Re-check current metadata in case meta-codesync labeled the PR | ||
| // after the first check. An exported PR needs neither classification | ||
| // nor a lingering Meta Review Required label. | ||
| if (isMetaExportedPullRequest(pr)) { | ||
| if (labels.includes('Meta Review Required')) { | ||
| await github.rest.issues.removeLabel({ | ||
| owner, repo, issue_number: number, name: 'Meta Review Required', | ||
| }); | ||
| } | ||
| return; | ||
| } | ||
| if (process.env.EXPORTED === 'true') { | ||
| 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; | ||
| } | ||
| if (labels.includes('Meta Review Required')) { | ||
| return; | ||
| } | ||
| // The destination label does not yet exist in every repository. | ||
| // Create it once on first use, then apply it idempotently. | ||
| try { | ||
| await github.rest.issues.getLabel({owner, repo, name: 'Meta Review Required'}); | ||
| } catch (error) { | ||
| if (error.status !== 404) throw error; | ||
| try { | ||
| await github.rest.issues.createLabel({ | ||
| owner, repo, name: 'Meta Review Required', color: 'b60205', | ||
| description: 'This PR is considered risky and requires Meta to import it to do more testing before merging.', | ||
| }); | ||
| } catch (createError) { | ||
| // A concurrent PR may have created the same label. | ||
| if (createError.status !== 422) throw createError; | ||
| } | ||
| } | ||
| await github.rest.issues.addLabels({ | ||
| owner, repo, issue_number: number, labels: ['Meta Review Required'], | ||
| }); | ||