Skip to content

Other Commands

This page covers additional coverctl commands for badges, trends, and coverage analysis.

Post coverage reports as comments on GitHub, GitLab, or Bitbucket pull requests/merge requests.

Terminal window
coverctl pr-comment [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
--base-profileBase coverage profile for comparison
--providerGit provider: github, gitlab, bitbucket, autoauto
--prPR/MR numberauto-detected
--ownerRepository owner/namespaceauto-detected
--repoRepository nameauto-detected
--updateUpdate existing comment instead of creating newtrue
--dry-runGenerate comment without postingfalse

The provider is automatically detected from environment variables:

ProviderEnvironment Variables
GitHubGITHUB_TOKEN, GITHUB_REPOSITORY
GitLabGITLAB_TOKEN, CI_JOB_TOKEN, CI_MERGE_REQUEST_IID
BitbucketBITBUCKET_TOKEN, BITBUCKET_WORKSPACE, BITBUCKET_REPO_SLUG
Terminal window
# GitHub Actions (auto-detects everything)
coverctl pr-comment --pr ${{ github.event.pull_request.number }}
# GitLab CI (MR number auto-detected from CI_MERGE_REQUEST_IID)
coverctl pr-comment
# Bitbucket Pipelines (PR number auto-detected from BITBUCKET_PR_ID)
coverctl pr-comment
# With coverage comparison to base branch
coverctl pr-comment --pr 123 --base-profile main-coverage.out
# Explicit provider
coverctl pr-comment --provider gitlab --pr 42
# Preview comment without posting
coverctl pr-comment --pr 123 --dry-run

The generated comment includes:

  • Overall coverage percentage and change
  • Domain-level coverage breakdown with status indicators
  • List of changed files with coverage deltas (when base profile provided)
  • Pass/fail status based on configured thresholds

Compare coverage between two profiles to show improvements and regressions.

Terminal window
coverctl compare [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
--baseBase coverage profile (required)
--headHead coverage profile.cover/coverage.out
-o, --outputOutput format: text, jsontext
Terminal window
# Compare main branch to current
coverctl compare --base main-coverage.out --head coverage.out
# Compare two saved profiles
coverctl compare --base v1.0.out --head v2.0.out
# JSON output for CI parsing
coverctl compare --base main.out -o json
Coverage Comparison
───────────────────
Base: 78.5%
Head: 82.1%
Delta: +3.6%
Improved Files (5):
internal/core/validator.go 65.2% → 85.4% (+20.2%)
internal/api/handler.go 72.1% → 78.3% (+6.2%)
...
Regressed Files (1):
internal/cli/format.go 90.0% → 87.5% (-2.5%)

Generate an SVG coverage badge for your README.

Terminal window
coverctl badge [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
-o, --outputOutput file pathcoverage.svg
--labelBadge label textcoverage
--styleBadge style: flat, flat-squareflat
Terminal window
# Generate default badge
coverctl badge
# Custom style and label
coverctl badge --style flat-square --label "test coverage"
# Custom output path
coverctl badge -o docs/badge.svg

Show coverage trends over time using recorded history.

Terminal window
coverctl trend [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
--historyHistory file path.cover/history.json
-o, --outputOutput format: text, jsontext
Terminal window
# Show coverage trend
coverctl trend
# JSON output
coverctl trend -o json
Coverage Trend (last 10 entries)
────────────────────────────────
Date Commit Coverage Change
2024-12-23 abc1234 82.1% +0.5%
2024-12-22 def5678 81.6% +1.2%
2024-12-21 ghi9012 80.4% -0.3%
...

Record current coverage to history for trend analysis.

Terminal window
coverctl record [flags]

Note: Prefer profiles produced by coverctl run or coverctl check so the history reflects the same -coverpkg instrumentation that policy checks use. When using --run, pass test selection via --test-run (or --test-arg=-run=...) since --run is reserved to trigger coverage execution.

FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
--historyHistory file path.cover/history.json
--commitGit commit SHAauto-detected
--branchGit branch nameauto-detected
--runRun coverage before recording historyfalse
-l, --languageOverride language detectionauto
-d, --domainFilter to specific domain (repeatable)all domains
--tagsBuild tags (e.g., integration,e2e)
--raceEnable race detectorfalse
--shortSkip long-running testsfalse
-vVerbose test outputfalse
--test-runRun only tests matching pattern
--timeoutTest timeout (e.g., 10m, 1h)
--test-argAdditional go test argument (repeatable)
Terminal window
# Record with auto-detected git info
coverctl record
# Explicit commit and branch
coverctl record --commit abc1234 --branch main
# Run coverage before recording history
coverctl record --run --tags integration
.github/workflows/coverage.yml
- name: Record coverage
run: |
coverctl check
coverctl record --commit ${{ github.sha }} --branch ${{ github.ref_name }}

Suggest optimal coverage thresholds based on current coverage.

Terminal window
coverctl suggest [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
--strategyStrategy: current, aggressive, conservativecurrent
StrategyDescription
currentSet thresholds slightly below current coverage
aggressivePush for higher thresholds
conservativeLower thresholds for gradual improvement
Terminal window
# Get suggestions
coverctl suggest
# Aggressive strategy
coverctl suggest --strategy aggressive
Suggested Thresholds
────────────────────
Domain Current Suggested Reason
core 87.3% 85% Slightly below current (buffer for variance)
api 81.2% 80% Slightly below current
cli 76.4% 75% Slightly below current

Show coverage debt report identifying files that need more tests.

Terminal window
coverctl debt [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
-p, --profileCoverage profile path.cover/coverage.out
-o, --outputOutput format: text, jsontext
Terminal window
coverctl debt
Coverage Debt Report
────────────────────
File Current Required Shortfall
internal/core/validator.go 65.2% 85% -19.8%
internal/api/handler.go 72.1% 80% -7.9%
────────────────────
Total Debt: 27.7%
Health Score: 73/100

Show configured exclude patterns and ignored files.

Terminal window
coverctl ignore [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
Terminal window
coverctl ignore
Configured Excludes
───────────────────
- **/generated/**
- **/mocks/**
- internal/testdata/*
Ignored Files (matching excludes)
─────────────────────────────────
- internal/generated/proto/api.pb.go
- internal/mocks/service_mock.go

Auto-detect domains and write configuration.

Terminal window
coverctl detect [flags]
FlagDescriptionDefault
-c, --configConfig file path.coverctl.yaml
--dry-runPreview config without writingfalse
-f, --forceOverwrite existing configfalse
Terminal window
# Preview detected domains
coverctl detect --dry-run
# Write config
coverctl detect
# Overwrite existing
coverctl detect --force

Show version information.

Terminal window
coverctl version
coverctl v1.4.0 (abc1234) built 2024-12-23

Show help for any command.

Terminal window
coverctl help [command]
# Examples
coverctl help
coverctl help check
coverctl check --help