chore: add auto-format bot and scope CI format check to changed files#31109
chore: add auto-format bot and scope CI format check to changed files#31109MohamedH1998 wants to merge 3 commits into
Conversation
Review⏸️ Automatic reviews for this PR are paused. This PR has already received 2 automatic reviews. To run another review, a codeowner can comment
✅ No style-guide issues found in commit CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
There was a problem hiding this comment.
3 issues need addressing before merge.
- CRITICAL
.github/workflows/auto-format-build.ymlline 7: The branch filter[auto-format-canary]appears to be a testing artifact. If the bot is meant to run on production PRs, this should beproductionor the filter should be removed. - CRITICAL
.github/workflows/auto-format-apply.ymllines 182–185:pr.head.repocan benullif a fork is deleted. Add optional chaining (?.) to prevent aTypeErrorfrom crashing the workflow. - HIGH Address the existing CodeQL alerts on
auto-format-apply.ymlabout checking out untrusted code in a privileged context. Add suppression comments with justification if the existing validations are sufficient.
Other notes: The PR description is empty — a brief summary of the infrastructure change would help reviewers.
|
The PR review for #31109 has already been completed. I applied the labels
If there's anything else you'd like me to do with this PR or another task, just let me know! |
|
/bonk review |
|
Posted a review on PR #31109 with 5 inline comments. Cleared
Suggested
|
|
Preview URL: https://36db133b.preview.developers.cloudflare.com |
Summary
Adds a two-workflow auto-formatter that fixes prettier issues on PRs without contributors having to run prettier locally. Also scopes the existing CI format check from the entire repo to only the files changed in a PR, so the bot and CI agree on what's in scope.
auto-format-build.yml— runs onpull_request, no secrets. Runs prettier against changed files, uploads any diff as aformat-patchartifact.auto-format-apply.yml— runs onworkflow_runafter the build completes, withcloudflare-docs-botApp credentials. Downloads the artifact, validates the patch only touches allowlisted paths, applies it to the PR head, and pushes back via the App.The split is deliberate: untrusted PR code runs only in the build workflow (no secrets); the privileged push workflow never executes PR-controlled code. This is the pattern recommended by GitHub Security Lab for safely auto-fixing community PRs.
Staged rollout — the build workflow is filtered to
branches: [auto-format-canary]on merge. It does not fire on any existing or new PR againstproductionuntil a one-line follow-up PR flips the filter (Stage B). The repo becomes prettier-clean incrementally as PRs touch files — no bulk reformat needed.What reviewers should focus on:
auto-format-build.ymlpull_request(notpull_request_target),permissions: contents: read,pnpm install --frozen-lockfile --ignore-scripts, prettier invoked directly (not viapnpm run).auto-format-apply.ymlpersist-credentials: false, post-apply re-validation.ci.ymlCheck formatting (changed files)step replaces the globalformat:core:check.package.json<category>:<action>matrix with paired:check/:fixvariants..github/,package.json, lockfiles, or other sensitive paths (blocklisted in the apply workflow).Known item: CodeQL alert flagging the workflow_run + checkout pattern was reviewed and dismissed — the privileged workflow never installs or executes PR code.
Screenshots (optional)
Documentation checklist