Reported + Go Collector
Enforce Reported using data collected by Go Collector. Automatically check testing and quality standards on every PR.
How Go Collector Powers This Guardrail
The Go Collector gathers metadata from your languages, build systems. This data flows into Lunar's Component JSON, where the Reported guardrail evaluates it against your standards.
When enabled, this check runs automatically on every PR and in AI coding workflows, providing real-time enforcement with actionable feedback.
Quick Start Configuration
Add both the collector and policy to your lunar-config.yml to enable this guardrail.
# Step 1: Enable the Go Collector
collectors:
- uses: github://earthly/lunar-lib/collectors/golang@v1.0.0
# with: ...
# Step 2: Enable the Coverage Guardrails
policies:
- uses: github://earthly/lunar-lib/policies/coverage@v1.0.0
include: [reported]
# with: ...
What Go Collector Collects
This collector gathers the following data that the Reported guardrail evaluates.
cicd
Records every Go command executed in CI pipelines along with the Go version. Writes command strings and version info to .lang.go.cicd for audit trails and build reproducibility analysis.
test-scope
Determines whether go test runs recursively (./...) or targets specific packages. Writes scope to .lang.go.tests.scope as "recursive" or "package" to verify comprehensive test execution in CI.
test-coverage
Extracts coverage percentage from go test -coverprofile output after tests complete. Parses the coverage profile file, runs go tool cover -func to calculate total percentage, and writes results to .lang.go.tests.coverage including the raw profile.
project
Analyzes Go project structure by detecting go.mod, go.sum, vendor directory, and goreleaser configuration. Extracts the module path and Go version from go.mod using go list. Writes project metadata to .lang.go with build system info.
Example Data Flow
Here's an example of the data that Go Collector writes to the Component JSON, which Reported then evaluates.
{
"lang": {
"go": {
"module": "github.com/acme/myproject",
"version": "1.21",
"build_systems": ["go"],
"native": {
"go_mod": { "exists": true, "version": "1.21" },
"go_sum": { "exists": true },
"vendor": { "exists": false },
"goreleaser": { "exists": true },
"golangci_lint": {
"passed": false,
"config_exists": true,
"exit_code": 1,
"output": "main.go:42:5: unused variable 'x' (unused)"
}
},
"source": { "tool": "go", "integration": "code" },
"cicd": {
"cmds": [{ "cmd": "go test ./...", "version": "1.21.5" }],
"source": { "tool": "go", "integration": "ci" }
},
"tests": {
"scope": "recursive",
"coverage": {
"percentage": 78.5,
"profile_path": "coverage.out",
"source": { "tool": "go cover", "integration": "ci" }
}
},
"dependencies": {
"direct": [
{ "path": "github.com/stretchr/testify", "version": "v1.8.4", "indirect": false }
],
"transitive": [
{ "path": "github.com/davecgh/go-spew", "version": "v1.1.1", "indirect": true }
],
"source": { "tool": "go mod", "integration": "code" }
},
"lint": {
"warnings": [
{ "file": "main.go", "line": 42, "column": 5, "message": "unused variable 'x'", "linter": "unused" }
],
"linters": ["golangci-lint"],
"source": { "tool": "golangci-lint", "integration": "code" }
}
}
}
}
Configuration Options
Go Collector Inputs
| Input | Required | Default | Description |
|---|---|---|---|
lint_timeout |
Optional |
10m
|
Timeout for golangci-lint (e.g., 5m, 10m) |
Coverage Guardrails Inputs
| Input | Required | Default | Description |
|---|---|---|---|
min_coverage |
Optional |
80
|
Minimum required coverage percentage |
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.