Files
Alberto Schiabel 15a03c10fb ci: add dead-code detection (knip + vulture + orphaned-CI check) (#3787)
## What

Adds a **report-only** `Dead Code` CI workflow that surfaces
likely-orphaned code on every PR, across all three surfaces —
TypeScript, Python, and GitHub Actions. Follow-up to the root
`Dockerfile` cleanup (#3783) and the dead-code sweep in #3786: instead
of finding this stuff by hand, catch it automatically.

| Surface | Tool | Wiring |
|---|---|---|
| TypeScript | [**knip**](https://knip.dev) | `knip.json`; runs via
`pnpm dlx knip@5`. Finds unused files, exports, types, and dependencies.
|
| Python | [**vulture**](https://github.com/jendrikseipp/vulture) |
`dead_code` nox session + `make dead-code`; allowlist at
`python/config/vulture_allowlist.py`. Finds unused
functions/classes/variables (complements Ruff's F401/F841). |
| GitHub Actions | small bash script |
`.github/scripts/check-orphan-ci.sh` — flags reusable workflows and
composite actions with no callers. |

## Why report-only (not blocking)

Every job writes findings to the run's **Step Summary** and **never
fails the build**. These tools carry unavoidable false positives on a
library monorepo — public API surface, dynamic imports, import-map
targets (e.g. core's `#platform`), framework entry points. A red ❌ on
false positives would just train everyone to ignore the check. Once a
job's config is refined enough that a clean run is the steady state, it
can be flipped to blocking.

## Validation (ran each locally)

- **knip**: 0 unused *files* after scoping out the e2e-test workspaces
(knip crashes traversing `ts/e2e-tests/**` — pre-existing knip bug,
filed via `ignoreWorkspaces`) and build/docs artifacts. Export/dep
categories surface advisory items.
- **vulture**: clean run (report-only); allowlist suppresses the 3
`TYPE_CHECKING` re-exports in `custom_tool.py`; `build/`/`dist/`
excluded. Surfaces 4 genuine minor items (`bases`, `desc`×3).
- **orphan-CI script**: finds none — the repo has no orphaned CI
plumbing today.
- **Pinning**: `jk actions check` clean for this workflow;
`actions/checkout` is SHA-pinned, the two local composite actions need
no pin.

Local usage is documented under **Dead code detection** in
`CONTRIBUTING.md`.

## Note on scope

These cover TS/Python/GHA — they would *not* have caught the root
`Dockerfile` itself (an arbitrary root file no tool tracks). That class
stays a manual-review concern; the orphan-CI script is the closest
analogue for the CI surface.
2026-07-10 02:17:54 +04:00

72 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Report orphaned CI plumbing — the GitHub Actions analogue of the "dead file"
# problem knip/vulture catch for TS/Python:
#
# * composite actions under .github/actions/* that no workflow `uses:`
# * reusable workflows (on: workflow_call) that nothing calls AND that have
# no self-trigger (push/pull_request/schedule/...), i.e. truly unreachable
#
# Report-only: prints findings and always exits 0 so it never blocks CI on a
# heuristic. Vet anything it prints by hand before deleting.
set -uo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
workflows_dir="$repo_root/.github/workflows"
actions_dir="$repo_root/.github/actions"
findings=0
note() {
findings=$((findings + 1))
echo " - $1"
}
echo "### Orphaned CI check"
echo ""
echo "Composite actions with no callers:"
if [[ -d "$actions_dir" ]]; then
for action_yml in "$actions_dir"/*/action.yml "$actions_dir"/*/action.yaml; do
[[ -f "$action_yml" ]] || continue
name="$(basename "$(dirname "$action_yml")")"
# A caller references it as `uses: ./.github/actions/<name>`.
if ! grep -rqs "uses:.*\.github/actions/$name\b" "$workflows_dir" "$actions_dir"; then
note "action \`$name\` (.github/actions/$name) is referenced by no workflow"
fi
done
fi
[[ $findings -eq 0 ]] && echo " _(none)_"
before_wf=$findings
echo ""
echo "Reusable workflows that are unreachable:"
for wf in "$workflows_dir"/*.yml "$workflows_dir"/*.yaml; do
[[ -f "$wf" ]] || continue
# Only reusable workflows are candidates.
grep -qs "workflow_call:" "$wf" || continue
base="$(basename "$wf")"
# Called by another workflow?
if grep -rqs "uses:.*\.github/workflows/$base\b" "$workflows_dir"; then
continue
fi
# Self-triggering (has a real event trigger besides workflow_call)?
if grep -Eqs "^[[:space:]]+(push|pull_request|schedule|workflow_dispatch|release|issues|issue_comment|repository_dispatch|merge_group):" "$wf"; then
continue
fi
note "workflow \`$base\` exposes workflow_call but has no caller and no self-trigger"
done
[[ $findings -eq $before_wf ]] && echo " _(none)_"
echo ""
if [[ $findings -eq 0 ]]; then
echo "No orphaned CI plumbing found."
else
echo "Found $findings orphaned CI item(s) above — review before removing."
fi
# Report-only.
exit 0