Repository navigation
Tools: Move the PHPStan report script into a tools/phpstan workspace - #86222
Conversation
The script that reports the PHPStan results in CI lived in `.github/workflows/scripts`, outside every workspace, so it was neither linted nor type checked, and had nowhere to declare a dependency should it ever need one. It is now `tools/phpstan/report.ts`, in a new `@wordpress/phpstan-tools` workspace alongside the rest of the PHPStan tooling, with its JSDoc types rewritten as TypeScript and a `tsconfig.json` referenced from the root, so `npm run typecheck` and `npm run lint:js` cover it. Its behavior is unchanged: on the same report, it prints the same annotations, writes the same job summary, and exits with the same status. Node runs the script by stripping the types, as with `tools/pr-meta`, so the PHPStan job now sets up the Node version in `.nvmrc` before the report step, rather than relying on the runner's default. The script imports nothing outside Node, so the job still installs no npm dependencies. The CODEOWNERS entry for the old path is removed, since the existing `/tools/phpstan` entry now covers the script. Co-Authored-By: Claude Opus 5.5 (high effort) <noreply@anthropic.com> Claude-Code-Session-Id: 0e3bd725-76b2-4ebf-9478-771dc675b691
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: 0 B Total Size: 8.58 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in
|
| # the pull request did not change and those with no line, such as an out-of-date baseline. | ||
| - name: Report the PHPStan results | ||
| run: node .github/workflows/scripts/phpstan-report.js "${RUNNER_TEMP}/phpstan-report.json" | ||
| run: node tools/phpstan/report.ts "${RUNNER_TEMP}/phpstan-report.json" |
There was a problem hiding this comment.
Instead of invoking it from root, let us create a script in the workspace and then use npm run —workspace … syntax here like we do for other tools.
There was a problem hiding this comment.
🤖 Comment by Claude Opus 5.5 · high effort
Done in 42df232: tools/phpstan/package.json now has a report script, and the job runs npm run --workspace @wordpress/phpstan-tools report -- "${RUNNER_TEMP}/phpstan-report.json".
Since npm run requires the npm version in the devEngines of the root package.json, the job now also runs ./.github/setup-npm (with cache: false) after setting up Node, as static-checks.yml does. No npm dependencies are installed, since npm run --workspace only reads the package.json files.
As npm run runs the script in tools/phpstan, the file paths in the report are made relative to the repository root, found from the script's own location when GITHUB_WORKSPACE is not set, and a relative path to the report is resolved from INIT_CWD, so it can also be run locally from the root. The output in CI is unchanged.
CI now runs the report with `npm run --workspace @wordpress/phpstan-tools report`, as it does for the other tools, rather than invoking the file from the repository root. `npm run` requires the npm version in the `devEngines` of package.json, so the job sets it up with `./.github/setup-npm` after Node. The dependencies are still not installed, since `npm run --workspace` only reads the package.json files. `npm run` also runs the script in the workspace directory. The paths in the report are therefore made relative to the repository root, found from the script's own location when `GITHUB_WORKSPACE` is not set, and a relative path to the report is resolved from `INIT_CWD`, the directory that npm was run in. In CI, the report path is absolute and `GITHUB_WORKSPACE` is set, so the output is unchanged. Co-Authored-By: Claude Opus 5.5 (high effort) <noreply@anthropic.com> Claude-Code-Session-Id: 0e3bd725-76b2-4ebf-9478-771dc675b691
What?
Follow-up to #66693, addressing #66693 (comment).
This moves the script that reports the PHPStan results in CI from
.github/workflows/scripts/phpstan-report.jstotools/phpstan/report.ts, in a new@wordpress/phpstan-toolsworkspace, so that it is linted and type checked.Why?
The script lived outside every workspace, so neither
npm run lint:jsnornpm run typecheckcovered it, and it had nowhere to declare a dependency should it ever need one.tools/phpstanalready holds the rest of the PHPStan tooling, so it becomes the workspace.How?
tools/phpstangets apackage.json(@wordpress/phpstan-tools, private, with@types/nodeas its only dependency), atsconfig.jsonextending@wordpress/monorepo-tools/tsconfig/node.base.jsonliketools/pr-metaandtools/validation, a reference in the roottsconfig.json, its entries inpackage-lock.json, areportscript that runsreport.ts, and aREADME.mddescribing what the directory holds.require( 'node:fs' )becomes an ES import. Sincenpm runruns the script in the workspace directory, the paths in the report are made relative to the repository root, found from the script's own location whenGITHUB_WORKSPACEis not set, and a relative path to the report is resolved fromINIT_CWD, the directory that npm was run in. Otherwise the logic is unchanged: on the same report, the old and new scripts print the same annotations, write the same job summary, and exit with the same status.PHP static analysisjob runs the report withnpm run --workspace @wordpress/phpstan-tools report, as other workflows do for the other tools. Node runs the script by stripping its types, as withtools/pr-meta, so the job now sets up the Node version in.nvmrcbefore the report step, rather than relying on the runner's default, followed by./.github/setup-npm, sincenpm runrequires the npm version in thedevEnginesofpackage.json. The script imports nothing outside Node, andnpm run --workspaceonly reads thepackage.jsonfiles, so the job still installs no npm dependencies. The PHPStan result cache key hashes only the.neon,.php, and.stubfiles intools/phpstanandtools/phpstan/src/**, so the new files do not invalidate it./tools/phpstanentry now covers the script.Testing Instructions
npm run typecheck -- tools/phpstan/tsconfig.jsonandnpm run lint:js -- tools/phpstan/report.ts, and confirm that both pass.tools/phpstan/report.ts, such as passing a number toescapeHtml(), and confirm thatnpm run typecheckreports it.composer phpstan -- --error-format=json --no-progress > report.json, thennpm run --workspace @wordpress/phpstan-tools report -- report.json, and confirm that it prints an::errorannotation for each error, or nothing when there are none.PHP static analysisjob passes in CI, and that its job summary lists the results as before.Testing Instructions for Keyboard
Not applicable, since there are no UI changes.
Use of AI Tools
This was done with Claude Code (Claude Opus 5.5, high effort): moving the script and converting it to TypeScript, setting up the workspace and the CI step, comparing the output of the old and new scripts, and drafting the commit message and this description, under the direction and review of @westonruter.