skycov
skycov
Section titled “skycov”A coverage reporter for Starlark code that generates reports in multiple formats including text, JSON, Cobertura XML, and LCOV. Integrates with CI systems and code coverage platforms.
Installation
Section titled “Installation”go install github.com/albertocavalcante/sky/cmd/skycov@latest# Display text coverage reportskycov coverage.json
# Generate Cobertura XML for CIskycov -format=cobertura -o coverage.xml coverage.json
# Generate LCOV for IDE integrationskycov -format=lcov -o coverage.lcov coverage.json
# Fail if coverage is below thresholdskycov -min=80 coverage.json
# Verbose output with line detailsskycov -v coverage.json
# Demo mode (no input file)skycov| Flag | Description |
|---|---|
-format | Output format: text, json, cobertura, lcov (default: text) |
-o | Output file (default: stdout) |
-min | Minimum coverage percentage (fail if below) |
-source | Source directory for relative paths in reports |
-v | Verbose output |
-version | Print version and exit |
Coverage Workflow
Section titled “Coverage Workflow”1. Collect Coverage Data
Section titled “1. Collect Coverage Data”Run tests with coverage enabled (requires starlark-go-x):
# Generate coverage data during testsskytest -coverage -coverprofile=coverage.json .2. Generate Reports
Section titled “2. Generate Reports”Process coverage data with skycov:
# Human-readable summaryskycov coverage.json
# CI-friendly formatsskycov -format=cobertura -o coverage.xml coverage.jsonskycov -format=lcov -o coverage.lcov coverage.json3. Enforce Coverage Thresholds
Section titled “3. Enforce Coverage Thresholds”# Fail build if coverage drops below 80%skycov -min=80 coverage.jsonOutput Formats
Section titled “Output Formats”Text Format (Default)
Section titled “Text Format (Default)”Human-readable summary:
$ skycov coverage.jsonCoverage Report===============
File Lines Covered Percentage---- ----- ------- ----------src/math.star 20 20 100.0%src/utils.star 10 7 70.0%src/legacy.star 15 2 13.3%---- ----- ------- ----------Total 45 29 64.4%With -v flag, shows uncovered lines:
$ skycov -v coverage.jsonsrc/utils.star: 70.0% (7/10 lines) Missing lines: 8, 9, 10
src/legacy.star: 13.3% (2/15 lines) Missing lines: 3-15JSON Format
Section titled “JSON Format”Machine-readable JSON for tooling:
$ skycov -format=json coverage.json{ "files": { "src/math.star": { "lines": { "1": 5, "2": 5, "3": 10 } }, "src/utils.star": { "lines": { "1": 3, "2": 3, "8": 0, "9": 0 } } }, "total_lines": 45, "covered_lines": 29, "percentage": 64.44}Cobertura XML Format
Section titled “Cobertura XML Format”For Jenkins, GitLab, and other CI systems:
$ skycov -format=cobertura -o coverage.xml coverage.json<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd"><coverage line-rate="0.644" branch-rate="0" version="1.0" timestamp="1234567890"> <packages> <package name="src" line-rate="0.644"> <classes> <class name="math.star" filename="src/math.star" line-rate="1.0"> <lines> <line number="1" hits="5"/> <line number="2" hits="5"/> </lines> </class> </classes> </package> </packages></coverage>LCOV Format
Section titled “LCOV Format”For genhtml and IDE integration:
$ skycov -format=lcov -o coverage.lcov coverage.jsonTN:SF:src/math.starDA:1,5DA:2,5DA:3,10LF:20LH:20end_of_recordSF:src/utils.starDA:1,3DA:2,3DA:8,0DA:9,0LF:10LH:7end_of_recordGenerate HTML report with genhtml:
skycov -format=lcov -o coverage.lcov coverage.jsongenhtml coverage.lcov -o coverage-html/open coverage-html/index.htmlCI Integration
Section titled “CI Integration”GitHub Actions
Section titled “GitHub Actions”- name: Run tests with coverage run: | skytest -coverage -coverprofile=coverage.json -r .
- name: Generate coverage report run: | skycov -format=cobertura -o coverage.xml coverage.json
- name: Check coverage threshold run: | skycov -min=80 coverage.json
- name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: files: coverage.xmlGitLab CI
Section titled “GitLab CI”test: script: - skytest -coverage -coverprofile=coverage.json -r . - skycov -format=cobertura -o coverage.xml coverage.json artifacts: reports: coverage_report: coverage_format: cobertura path: coverage.xml coverage: '/Total.*(\d+\.\d+)%/'Jenkins
Section titled “Jenkins”stage('Test') { steps { sh 'skytest -coverage -coverprofile=coverage.json -r .' sh 'skycov -format=cobertura -o coverage.xml coverage.json' } post { always { cobertura coberturaReportFile: 'coverage.xml' } }}Coverage Data Format
Section titled “Coverage Data Format”skycov reads coverage data in JSON format generated by skytest:
{ "files": { "path/to/file.star": { "lines": { "1": 5, "2": 3, "10": 0 } } }, "total_lines": 100, "covered_lines": 75, "percentage": 75.0}The lines object maps line numbers (as strings) to hit counts:
> 0: Line was executed that many times0: Line is executable but was not executed
Exit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
| 0 | Success (coverage meets minimum if specified) |
| 1 | Coverage below minimum threshold |
| 2 | Error (file not found, parse error, etc.) |
Examples
Section titled “Examples”Combine with skytest
Section titled “Combine with skytest”# Run tests and generate all report formatsskytest -coverage -coverprofile=coverage.json -r .skycov coverage.json # Terminal summaryskycov -format=json -o coverage-report.json coverage.json # JSONskycov -format=cobertura -o coverage.xml coverage.json # CIskycov -format=lcov -o coverage.lcov coverage.json # HTML genEnforce Coverage in CI
Section titled “Enforce Coverage in CI”#!/bin/bashMIN_COVERAGE=80
skytest -coverage -coverprofile=coverage.json -r .
# Generate reportsskycov -format=cobertura -o coverage.xml coverage.json
# Check thresholdif ! skycov -min=${MIN_COVERAGE} coverage.json; then echo "Coverage is below ${MIN_COVERAGE}%" exit 1fiLocal Development Workflow
Section titled “Local Development Workflow”# Quick coverage check during developmentskytest -coverage . && skycov coverage.json
# Detailed view of uncovered linesskycov -v coverage.json | grep "Missing"
# Generate HTML report for detailed analysisskycov -format=lcov -o cov.lcov coverage.jsongenhtml cov.lcov -o coverage-htmlopen coverage-html/index.htmlCompare Coverage Between Runs
Section titled “Compare Coverage Between Runs”# Save baseline coverageskycov -format=json coverage.json | jq '.percentage' > baseline.txt
# After changes, compareskycov -format=json coverage.json | jq '.percentage' > current.txtbaseline=$(cat baseline.txt)current=$(cat current.txt)
if (( $(echo "$current < $baseline" | bc -l) )); then echo "Warning: Coverage decreased from $baseline% to $current%"fiFuture: starlark-go-x Integration
Section titled “Future: starlark-go-x Integration”Once starlark-go-x supports coverage instrumentation, the workflow will be:
// In your Go code using starlark-go-xthread := &starlark.Thread{Name: "test"}collector := coverage.NewCollector()thread.SetCoverageCollector(collector)
// Execute Starlark code...
// Get coverage reportreport := collector.Report()The collector hooks required in starlark-go-x:
BeforeExec(filename, line)- Called before each statementEnterFunction(filename, name, line)- Called when entering a functionThread.SetCoverageCollector(c)- Set the collector for a thread
See the starlark-go-x repository for instrumentation progress.