diff --git a/.github/workflows/risk-gate.yml b/.github/workflows/risk-gate.yml new file mode 100644 index 0000000..1521b6a --- /dev/null +++ b/.github/workflows/risk-gate.yml @@ -0,0 +1,100 @@ +name: PR risk gate + +# Copy to .github/workflows/risk-gate.yml and replace CodeGovernanceLab/PrGovernance with +# the owner's governance repository (for example CodeGovernanceLab/PrGovernance). +# The job names in this file are the required status check contexts; keep them. + +on: + pull_request_target: + types: [opened, reopened, synchronize, edited, labeled, unlabeled, ready_for_review, closed] + issue_comment: + types: [created, edited, deleted] + # A review or inline comment on a fork or Dependabot pull request gets a + # read-only token, so those events are relayed through the permissionless + # `PR review signal` workflow and evaluated by this trusted run. + workflow_run: + workflows: ["PR review signal"] + types: [completed] + push: + branches: [main, master] + # A merge made with GITHUB_TOKEN raises no push, and nothing raises an event + # for a resolved review thread, so a daily sweep closes both gaps. + schedule: + - cron: '17 3 * * *' + workflow_dispatch: + inputs: + pr_number: + description: Existing pull request number to evaluate + required: true + type: string + +# The gate reads metadata only. It never checks out or runs pull request code. +permissions: + contents: read + pull-requests: read + issues: read + statuses: write + actions: write + +jobs: + # The labeled payload is the only authenticated record of which head a + # clearing label was added to. Recording it in its own job keeps the evidence + # independent of an evaluation that a later event may supersede. + record_label: + name: Record the head a clearing label was added to + if: github.event_name == 'pull_request_target' && github.event.action == 'labeled' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + issues: read + pull-requests: read + statuses: write + steps: + - name: Record label head + uses: CodeGovernanceLab/PrGovernance/pr-governance@5c4348e9d9ffbacf5526164a5be7f5c9f74fbfaf + env: + GOVERNANCE_OWNER_ID: ${{ vars.RISK_GATE_OWNER_ID }} + GOVERNANCE_OWNER_LOGIN: ${{ vars.RISK_GATE_OWNER }} + with: + mode: gate + record-label: 'true' + + evaluate: + name: Evaluate PR governance + needs: record_label + # A skipped recorder is the normal case for every other event. + if: >- + always() && needs.record_label.result != 'cancelled' && + (github.event_name != 'issue_comment' || + (github.event.issue.pull_request && + (github.event.comment.user.type == 'Bot' || + contains(github.event.comment.body || '', 'codex-review') || + contains(github.event.comment.body || '', 'ai-review-receipt')))) + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: read + pull-requests: read + issues: read + statuses: write + actions: write + # Job-level, so an irrelevant comment skips the job without cancelling an + # evaluation already running. Label evidence no longer rides on this run. + concurrency: + group: pr-governance-${{ github.event.pull_request.number || github.event.issue.number || github.event.workflow_run.pull_requests[0].number || inputs.pr_number || github.run_id }} + cancel-in-progress: true + steps: + - name: Evaluate + uses: CodeGovernanceLab/PrGovernance/pr-governance@5c4348e9d9ffbacf5526164a5be7f5c9f74fbfaf + env: + GOVERNANCE_OWNER_ID: ${{ vars.RISK_GATE_OWNER_ID }} + GOVERNANCE_OWNER_LOGIN: ${{ vars.RISK_GATE_OWNER }} + # Optional: a repository that keeps account identifiers out of public + # source configures the reviewer here instead of in policy.json. + GOVERNANCE_REVIEWER_APP_ID: ${{ vars.RISK_GATE_REVIEWER_APP_ID }} + GOVERNANCE_REVIEWER_USER_ID: ${{ vars.RISK_GATE_REVIEWER_USER_ID }} + GOVERNANCE_REVIEWER_LOGIN: ${{ vars.RISK_GATE_REVIEWER_LOGIN }} + GOVERNANCE_REVIEWERS_JSON: ${{ vars.GOVERNANCE_REVIEWERS_JSON }} + with: + mode: gate + record-label: 'false'