# Add Coverage Reporting to a GitHub Action's CI

Yes. An agent turns the coverage your action's Jest run already collects into a CI check: a threshold, a job summary, an artifact and a badge that cannot go stale.

[Run this on Rush](https://cloud.getrush.ai/run/add-coverage-to-ci/github-actions/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads what exists before adding anything, because in an action shaped like actions/typescript-action most of the work is already configured and simply unused. jest.config.js sets `collectCoverage: true`, `collectCoverageFrom: ['./src/**']`, `coverageDirectory: './coverage'` and three reporters, `json-summary`, `text` and `lcov`, and carries a commented-out `coverageThreshold` block. package.json has a `coverage` script, `npx make-coverage-badge --output-path ./badges/coverage.svg`, which reads coverage/coverage-summary.json, and README.md embeds badges/coverage.svg as an image from the committed badges/ directory. The tests are __tests__/main.test.ts and __tests__/wait.test.ts, mocking `@actions/core` through __fixtures__/core.ts, and src/index.ts is excluded with an istanbul ignore comment. So every local `npm test` prints a coverage table and writes lcov, and CI throws it away.

Then it reads .github/workflows/ci.yml. The `test-typescript` job checks out with actions/checkout v6, runs actions/setup-node v6 with `node-version-file: .node-version` (24.4.0) and `cache: npm`, then `npm ci`, `npm run format:check`, `npm run lint` and `npm run ci-test`, which runs Jest with `NODE_OPTIONS=--experimental-vm-modules` for ESM. A second job, `test-action`, runs the built action from dist/ with a 2000 millisecond input. check-dist.yml has a pattern worth copying: it rebuilds dist/ and fails if `git diff` shows the committed output is stale. The agent uses that same idea for the badge.

It makes four changes to the workflow and one to the config. After `ci-test`, a step reads coverage/coverage-summary.json with a few lines of node and appends a table of lines, statements, functions and branches to `$GITHUB_STEP_SUMMARY`, so the number is visible on the run page without opening logs. A step uploads coverage/lcov.info with actions/upload-artifact at the major version already used in check-dist.yml, so a reviewer can open the per-line report. In jest.config.js it enables `coverageThreshold` with values taken from the sandbox run of `npm run ci-test`, rounded down to whole numbers so a one-line change does not fail the build, and states the measured figures in the pull request. Finally a `check-badge` step runs `npm run coverage` and fails if `git diff --exit-code badges/coverage.svg` shows a change, mirroring check-dist.yml, so the badge in the README can never lag the code.

It runs the whole sequence in the sandbox with Node 24.4.0 as .node-version says: `npm ci`, `npm run format:check`, `npm run lint`, `npm run ci-test`, the summary script, `npm run coverage` and the diff check. It also runs `npm run bundle` to confirm the threshold change in jest.config.js does not affect dist/, since check-dist.yml would catch a stale bundle, and runs actionlint on ci.yml. Prettier runs over the new node snippet because .prettierrc.yml and `format:check` cover the repository.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add coverage reporting to this TypeScript GitHub Action's CI. Read package.json, jest.config.js, .node-version, .github/workflows/ci.yml, .github/workflows/check-dist.yml, README.md, badges/ and the tests under __tests__ and __fixtures__ first. Coverage is already collected by Jest with json-summary, text and lcov reporters; do not add a coverage service or a third-party coverage action. In ci.yml after the ci-test step, add a step that reads coverage/coverage-summary.json and appends a lines, statements, functions and branches table to GITHUB_STEP_SUMMARY, a step that uploads coverage/lcov.info as an artifact at the upload-artifact major version check-dist.yml uses, and a step that runs npm run coverage and fails on git diff --exit-code badges/coverage.svg so the committed badge cannot be stale. In jest.config.js enable coverageThreshold using the numbers you measure in the sandbox, rounded down to whole percentages, and state the measured numbers in the pull request. Run npm ci, npm run format:check, npm run lint, npm run ci-test, npm run coverage, npm run bundle and actionlint, and open a pull request with the outputs.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch that edits .github/workflows/ci.yml and jest.config.js, and badges/coverage.svg if the measured number differs from the committed badge. No new dependency is added, because make-coverage-badge and the Jest reporters were already in package.json; dist/ is unchanged and the description says so, since check-dist.yml would otherwise fail.

The description quotes the coverage table from the sandbox run of `npm run ci-test`, the threshold values written into jest.config.js and the measured values they were rounded down from, and the results of `format:check`, `lint`, `bundle` and actionlint. It explains the badge check in one paragraph so a contributor who sees it fail knows to run `npm run coverage` and commit the SVG.

A reviewer checks that the thresholds sit below the measured numbers so the first run passes, opens the lcov artifact from the pull request's own workflow run to see which lines of src/main.ts are uncovered, and decides whether the branch threshold should be stricter than the others. Raising it later is a one-line change, and the step summary will show the effect on the next pull request.

## Run it on every action repository without a coverage check

An organisation with several actions built from the same template starts one run per repository: a `POST /o/{org}/sessions` with this prompt and that repository in `resources`, with a `request_id` per repository so a retry returns the run already started. Each run measures its own suite and writes its own thresholds, so an action with full branch coverage and one with none get numbers from their own tests.

Give the key a webhook URL and Rush posts `run.completed` or `run.failed` when each turn ends. The sandbox parks with its node_modules and coverage directory, so a follow-up such as `raise the branch threshold and add a test for the setFailed path` wakes it where it left off and pushes to the same pull request.

## Why run it on Rush?

Everything in this job is a number that must be read, not chosen: the measured coverage that the threshold is derived from, the contents of coverage-summary.json that the summary step parses, the badge that must match. Doing that on a laptop means an ESM Jest run under the experimental VM modules flag and a diff of an SVG; the agent does it in its own sandbox on the Node version .node-version names and keeps the outputs.

The record shows the derivation. The run's transcript has the coverage table, the threshold values beside it, the badge diff and the actionlint result, so a reviewer can see the thresholds were measured and rounded down rather than typed from memory. The pull request runs its own workflow, so the first green check on the branch is the proof the job asked for.

## Frequently asked questions

### Why not use Codecov or a coverage action?

Because the template already collects coverage with Jest and ships make-coverage-badge, so a summary table, an artifact and a badge check need no account, token or third-party action. If a team wants history and pull request comments, a Codecov upload is a follow-up with a secret the owner adds.

### Where do the threshold numbers come from?

From running the suite in the sandbox. The agent reads the lines, statements, functions and branches percentages Jest prints, rounds each down to a whole number, and writes those into coverageThreshold. The pull request quotes both the measured and the written values.

### What is the badge check for?

README.md embeds badges/coverage.svg from the repository, and the only thing that updates it is running npm run coverage by hand. The new step regenerates it in CI and fails on a diff, the same way check-dist.yml fails when dist/ is stale, so the badge always reflects the tests on main.

### Will this slow the workflow down?

Coverage was already being collected on every ci-test run because collectCoverage is true in jest.config.js. The added steps read a small JSON file, upload one lcov file and run the badge script, which takes seconds.

### Does it change dist/ or action.yml?

No. The threshold lives in jest.config.js and the rest in the workflow; nothing in src/ changes, so npm run bundle produces the same dist/ and check-dist.yml stays green. The agent runs the bundle in the sandbox to confirm that.

## More GitHub Actions jobs

- [Set Up Dependabot Auto-merge with GitHub Actions](https://getrush.ai/run/add-dependabot-auto-merge/github-actions/)
- [Add Dependency Review to Pull Requests with GitHub Actions](https://getrush.ai/run/add-dependency-review/github-actions/)
- [Add a Job Summary to a GitHub Action](https://getrush.ai/run/add-job-summary/github-actions/)

## The same job on other stacks

- [Add Test Coverage Reporting to Go CI](https://getrush.ai/run/add-coverage-to-ci/go/)
- [Add Test Coverage Reporting to CI for a Go CLI](https://getrush.ai/run/add-coverage-to-ci/go-cli/)
- [Add Test Coverage to CI for a Koa API](https://getrush.ai/run/add-coverage-to-ci/koa/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
