Hamburger Cross Icon
Codecov Collector - Lunar Collector

Codecov Collector

Collector Stable Testing

Automatically detect Codecov runs in CI and fetch coverage percentage and file-level details. Track test coverage trends across your organization.

Add codecov to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/codecov@v1.0.0

What This Integration Collects

This integration includes 2 collectors that gather metadata from your systems.

Collector ci-after-command

ran

Records that Codecov ran in CI by writing source metadata to .testing.coverage. The presence of this object signals that codecov was executed. Also captures the Codecov CLI version when available via the codecov --version command.

Pattern: codecov(cli)?|bash.*codecov
codecov coverage detection ci integration
Book a demo
Collector ci-after-command

results

Fetches coverage percentage and file-level details from the Codecov API after upload commands complete. Detects upload commands (-t, -f flags or upload subcommands), calls the Codecov API with the commit SHA, and writes coverage percentage to .testing.coverage.percentage with full API response in .testing.coverage.native.codecov.

Pattern: codecov(cli)?|bash.*codecov
code coverage coverage percentage codecov api test coverage
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "testing": {
    "coverage": {
      "source": {
        "tool": "codecov",
        "integration": "ci",
        "version": "0.7.2"
      },
      "percentage": 85.5,
      "native": {
        "codecov": {
          "totals": {
            "files": 3,
            "lines": 1250,
            "hits": 1068,
            "misses": 182,
            "partials": 0,
            "coverage": 85.5
          },
          "files": [
            {
              "name": "src/main.py",
              "totals": {
                "lines": 500,
                "hits": 450,
                "misses": 50,
                "coverage": 90.0
              }
            }
          ]
        }
      }
    }
  }
}

Configuration

Configure this collector in your lunar-config.yml.

Inputs

Input Required Default Description
use_env_token Optional false Use CODECOV_TOKEN from environment instead of Lunar secret

Secrets

This collector requires the following secrets to be configured in Lunar:

Secret Description
CODECOV_API_TOKEN Codecov API token for fetching coverage results (required for results collector)

Documentation

View on GitHub

Codecov Collector

Detects Codecov usage and fetches coverage results from the Codecov API.

Overview

This collector detects when Codecov runs in CI and fetches coverage results from the Codecov API. It triggers on codecov commands via the ci-after-command hook. The presence of the .testing.coverage object signals that codecov ran, and the presence of .testing.coverage.percentage signals that coverage data was successfully fetched.

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.testing.coverage.source object Source metadata (tool, integration)
.testing.coverage.percentage number Coverage percentage from Codecov API
.testing.coverage.native.codecov object Full raw API response from Codecov

Note: Object presence is the signal—no explicit boolean fields are used:

  • .testing.coverage exists → codecov ran
  • .testing.coverage.percentage exists → upload succeeded and coverage was fetched

Collectors

This plugin provides the following collectors (use include to select a subset):

Collector Description
ran Records that codecov ran (writes source metadata)
results Fetches coverage results from Codecov API

Both collectors use hook type ci-after-command with pattern codecov(cli)?|bash.*codecov.

The results collector:

  1. Detects upload commands (upload, do-upload, upload-process, or commands with -t/-f flags)
  2. Fetches coverage from the Codecov API
  3. Writes .testing.coverage.percentage (normalized) and .testing.coverage.native.codecov (full API response)

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/codecov@main
    on: [backend]
    # include: [ran]  # Only record that codecov ran (no API call needed)
    # with:
    #   use_env_token: "true"  # Use CODECOV_TOKEN from CI environment

To fetch coverage results, configure the CODECOV_API_TOKEN secret. If use_env_token is enabled, the collector checks CODECOV_TOKEN from the environment first, then falls back to the Lunar secret.

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Ready to Automate Your Standards?

See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Book a Demo
See it work with your own use cases
See How It Works