How to Publish Coverage to Codecov with GitHub Actions
codecov/codecov-action takes the coverage file your tests produce and uploads it to Codecov for PR annotations.
Run your tests with coverage to emit a report (for example coverage/lcov.info or coverage.xml), then call codecov/codecov-action with a CODECOV_TOKEN secret so the upload is authenticated and not rate-limited.
Steps
- Run tests with
--coverageto produce a report file. - Add
codecov/codecov-action, passingfilesand thetoken. - Store the upload token as the
CODECOV_TOKENrepository secret.
Workflow
.github/workflows/ci.yml
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npx jest --coverage
- uses: codecov/codecov-action@v5
with:
files: ./coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: trueGotchas
- Without a token, uploads can fail with "Token required" or hit rate limits on private repos.
- Point
filesat the report your runner actually wrote, or Codecov reports no coverage found.
Related guides
How to Enforce a Code Coverage Threshold with GitHub ActionsFail a GitHub Actions build when coverage drops below a target by setting coverageThreshold in Jest, so a reg…
How to Split a Test Suite into Parallel Jobs with GitHub ActionsSpeed up CI by splitting a test suite into independent GitHub Actions jobs (unit, integration, e2e) that run…