Skip to main content
A workflow doesn’t have to change code. This one counts console.log calls per package, returns the counts as a report, and fails CI when there are more than you allow. The run only reads, so it works on a repository with uncommitted changes too. You need Node.js 22.18 or later and Git.

1. The project

packages/api/src/orders.ts
packages/web/src/app.ts
packages/web/src/util.ts

2. The workflow

workflow.ts
  • The callback returns how many calls one file has.
  • The reducer, (counts, found, path) => …, folds those numbers into one object per package, starting from {}. The step’s result has it as reduced. A reducer keeps only the running result in memory, so it works on targets with many thousands of files.
  • containing: "console.log" skips files that don’t mention it.
  • What main returns is the run’s output. fail(message, { output }) ends the run as failed, keeps the report as its output, and makes the CLI exit 2.
  • Params declares the parameters the workflow takes. --param max=5 sets max.

3. Run it

Allow five and it passes:
--param max=5 arrives as the number 5. A parameter declared string keeps the same input as text ("5").

4. Read the report as JSON

Every run is saved. Read the failed one back, for a CI summary or a dashboard:
(Trimmed: the real output also has the workflow and target paths, params, timestamps and durations.)
  • output is the report, also for a failed run.
  • exitCode is the code fail() gave the CLI to exit with.
  • Each step has its result, here the reduced counts, and files: how many files it worked on and how many failed.
With --format jsonl, the run’s last line, run_finished, carries the same status and output, so a program driving the run doesn’t need a second command.

Use it in CI

The exit code is all CI needs: 0 passes, 2 fails the job. See Exit codes and Running in CI and from agents. fail() takes another code if 2 means something else to you: fail(message, { output, exitCode: 4 }), any code from 1 to 125.