diff --git a/.github/workflows/review-routing.yml b/.github/workflows/review-routing.yml new file mode 100644 index 00000000000000..c1ebda61309353 --- /dev/null +++ b/.github/workflows/review-routing.yml @@ -0,0 +1,70 @@ +name: Review routing + +on: + # Runs this workflow from the target branch, not from the pull request. + # This makes it safe to give the job the decision API key, also for pull + # requests from forks. The job reads the pull request only through the + # GitHub API, and never runs its code. + pull_request_target: + types: [opened, reopened, synchronize, ready_for_review] + +# Disable permissions for all available scopes by default. +# Any needed permissions should be configured at the job level. +permissions: {} + +# Only the newest commit needs scores. +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }} + cancel-in-progress: true + +jobs: + route: + name: Score the routing rules + # Pull requests to release branches are backports, which need no + # routing. A draft gets its scores when it is ready for review. + if: ${{ ! github.event.pull_request.draft && github.event.pull_request.base.ref == github.event.repository.default_branch }} + runs-on: 'ubuntu-slim' + # This job has the API key, so its token can only read. The report goes + # to the run summary, so the job writes nothing to the pull request. + permissions: + contents: read + pull-requests: read + timeout-minutes: 5 + + steps: + # On `pull_request_target`, this checks out the base branch. The + # tool has no runtime dependencies, so `npm run` needs no install. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + sparse-checkout: | + tools/review-routing + .github/review-routing + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + # The npm that comes with this Node.js meets the `devEngines` floor + # in package.json, so the job does not install another npm. + - name: Use desired version of Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version-file: '.nvmrc' + check-latest: true + package-manager-cache: false + + # The scores do not request reviews yet, and CODEOWNERS still does. + # So a failure, such as a model that does not respond, only logs an + # error. + - name: Score the rules + continue-on-error: true + env: + DECISION_API_URL: ${{ vars.REVIEW_ROUTING_DECISION_API_URL }} + DECISION_API_KEY: ${{ secrets.REVIEW_ROUTING_DECISION_API_KEY }} + DECISION_MODEL: ${{ vars.REVIEW_ROUTING_DECISION_MODEL }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PR_NUMBER: ${{ github.event.number }} + REPO: ${{ github.repository }} + run: | + # `--silent` keeps npm's own header out of the report. + report="$(npm run --silent --workspace @wordpress/review-routing-tools route -- --pr "$PR_NUMBER" --repo "$REPO")" + printf '%s\n' "$report" + printf '%s\n' "$report" >> "$GITHUB_STEP_SUMMARY" diff --git a/tools/review-routing/README.md b/tools/review-routing/README.md index f9312a216fbfa0..d4a77444ce4201 100644 --- a/tools/review-routing/README.md +++ b/tools/review-routing/README.md @@ -19,7 +19,7 @@ Does this change add or change a public API of the design system packages? ... `threshold` is optional and defaults to 0.7. Write the body in plain language, and say when to answer no if the boundary is not clear. -Ask about one kind of change in each file. A question that combines several conditions gives a less useful probability, and the model can let one condition hide another. To route several kinds of change to a team, add a file for each kind with the same `team`. The team gets one request if any of its rules passes, and the report shows which rules did. To add a team, add a file. +Ask about one kind of change in each file. A question that combines several conditions gives a less useful probability, and the model can let one condition hide another. To route several kinds of change to a team, add a file for each kind with the same `team`. Many files can name the same team. The tool decides each rule on its own and does not combine the rules of a team, so the report shows the probability of each rule. To add a team, add a file. ## What the model reads