NexisChat Docs
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-setup action)
  • pnpm: version declared in the lockfile

High-Level Flow

  1. Change Detection – Imports the reusable workflow to fetch the list of modified components.
  2. Discovery Step – Filters the list down to workspaces that:
  • are not in ci-ignores.json’s ignored array,
  • expose a knip script in their package.json, and
  • are not explicitly excluded under ignore.knip.
  1. 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.
  2. Comment Management – Removes prior Knip comments and posts fresh per-component updates on the PR.
  3. 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-check job 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 knip script defined in each workspace’s package.json. Discovery ignores workspaces that lack it.
  • Adjust ci-ignores.json if 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.