Codecov Collector
Automatically detect Codecov runs in CI and fetch coverage percentage and file-level details. Track test coverage trends across your organization.
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.
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.
codecov(cli)?|bash.*codecov
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.
codecov(cli)?|bash.*codecov
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 →Example Collected Data
This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:
{
"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 GitHubCodecov 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.coverageexists → codecov ran.testing.coverage.percentageexists → 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:
- Detects upload commands (
upload,do-upload,upload-process, or commands with-t/-fflags) - Fetches coverage from the Codecov API
- 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.
Common Use Cases
Explore guardrails that use data from Codecov Collector.
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.