ActionsWorkflows
Knip (Unused Code) Reporter
Runs Knip sequentially across changed workspaces and posts per-component PR reports.
The Knip workflow now mirrors the CI workflow: a single job gathers the affected components and runs Knip for each one sequentially. The matrix-based execution path has been removed so the self-hosted runner only has to process one job regardless of how many workspaces changed.
Environment
- Runner: self-hosted
dokploy - Permissions:
contents: read,checks: write,issues: write,pull-requests: write - Node.js: 22 (via the shared
pnpm-setupaction) - pnpm: version declared in the lockfile
High-Level Flow
- Change Detection – Imports the reusable workflow to fetch the list of modified components.
- Discovery Step – Filters the list down to workspaces that:
- are not in
ci-ignores.json’signoredarray, - expose a
knipscript in theirpackage.json, and - are not explicitly excluded under
ignore.knip.
- Sequential Execution – Loops through every eligible component, generating both raw and cleaned Markdown reports with
pnpm exec knip --workspace <component> --reporter markdown --no-exit-code. - Comment Management – Removes prior Knip comments and posts fresh per-component updates on the PR.
- Artifacts & Failure Handling – Uploads all reports as a single artifact and fails the job if any report shows non-zero unused counts.
Behavioral Details
- Single Job: The
knip-checkjob controls discovery, execution, commenting, and artifact upload; there is no matrix or fan-out. - Graceful Skips: If discovery finds no qualifying workspaces the job exits early and no PR comments are posted.
- Report Validation: Each generated Markdown report must begin with
# Knip report. A mismatch marks the component as a failure so the issue is visible to maintainers. - Comment Content: Each PR comment explains whether unused code was found, includes the full Knip report, and carries a stable HTML marker so subsequent runs can replace it cleanly.
- Artifacts: Reports are collected into a single artifact (
knip-reports) for offline inspection.
Notes
- Keep the
knipscript defined in each workspace’spackage.json. Discovery ignores workspaces that lack it. - Adjust
ci-ignores.jsonif a workspace should skip Knip entirely or temporarily. - Because all components run sequentially, a problematic report does not block the remaining workspaces; the job fails only after every report is generated and recorded.