Improvement: new TNM regex #123
Workflow file for this run
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: Trusted PR Controller | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - labeled | |
| - unlabeled | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| permissions: | |
| actions: write | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| statuses: write | |
| jobs: | |
| dispatch-trusted-tests: | |
| name: Dispatch trusted tests | |
| if: github.event.pull_request.head.repo.fork | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const pr = context.payload.pull_request; | |
| const action = context.payload.action; | |
| const eventLabel = context.payload.label?.name; | |
| const labels = new Set(pr.labels.map((label) => label.name)); | |
| let shouldDispatch = false; | |
| let trustMode = null; | |
| if (action === "labeled" && eventLabel === "trusted-pr-once") { | |
| shouldDispatch = true; | |
| trustMode = "once"; | |
| } else if (action === "labeled" && eventLabel === "trusted-pr-forever") { | |
| shouldDispatch = true; | |
| trustMode = "forever"; | |
| } else if ( | |
| ["opened", "reopened", "synchronize"].includes(action) && | |
| labels.has("trusted-pr-forever") | |
| ) { | |
| shouldDispatch = true; | |
| trustMode = "forever"; | |
| } | |
| if (!shouldDispatch) { | |
| await github.rest.repos.createCommitStatus({ | |
| owner, | |
| repo, | |
| sha: pr.head.sha, | |
| state: "pending", | |
| context: "trusted-ci", | |
| description: "Waiting for trusted-pr-once or trusted-pr-forever", | |
| }); | |
| core.info( | |
| `No trusted run requested for action=${action} label=${eventLabel ?? "none"}.`, | |
| ); | |
| return; | |
| } | |
| await github.rest.repos.createCommitStatus({ | |
| owner, | |
| repo, | |
| sha: pr.head.sha, | |
| state: "pending", | |
| context: "trusted-ci", | |
| description: "Trusted CI has been requested", | |
| }); | |
| core.info(`Dispatching trusted tests for ${pr.head.repo.full_name}@${pr.head.sha}`); | |
| await github.rest.actions.createWorkflowDispatch({ | |
| owner, | |
| repo, | |
| workflow_id: "tests.yml", | |
| ref: pr.base.ref, | |
| inputs: { | |
| trusted_pr_number: String(pr.number), | |
| trusted_head_repository: pr.head.repo.full_name, | |
| trusted_head_sha: pr.head.sha, | |
| }, | |
| }); | |
| if (trustMode === "once" && labels.has("trusted-pr-once")) { | |
| core.info("Removing trusted-pr-once after dispatch."); | |
| await github.rest.issues.removeLabel({ | |
| owner, | |
| repo, | |
| issue_number: pr.number, | |
| name: "trusted-pr-once", | |
| }); | |
| } |