Use the badge package for rendering badges
mainbadge package is a specialized component within the octocov ecosystem designed for rendering badges. It is used to generate visual status indicators based on coverage or other metrics.repository·main·Indexed 19 days ago
https://github.com/k1low/octocovA toolkit for collecting and managing code metrics including code coverage, code-to-test ratio, and test execution time. It functions as a CLI tool for local development and a CI tool for GitHub Actions (k1LoW/octocov-action@v1), providing automated reporting, threshold enforcement, and SVG badge generation. It supports various datastores for report storage and comparison, including GitHub, S3, GCS, BigQuery, and local paths, and features a central mode for aggregating metrics across multiple repositories.
badge package is a specialized component within the octocov ecosystem designed for rendering badges. It is used to generate visual status indicators based on coverage or other metrics.octocov datasource uses a BigQuery schema to store code metric reports. The primary data structure is the reports table, which holds the metrics sent from octocov. The schema is designed to support relational queries across different metric reports.In addition to standard metrics (Code Coverage, Code to Test Ratio, and Test Execution Time), octocov accepts custom metrics via JSON files.
To use them, specify the path to the JSON file using an environment variable prefixed with OCTOCOV_CUSTOM_METRICS_ (e.g., OCTOCOV_CUSTOM_METRICS_PERF). If you have multiple files, use a separate environment variable for each.
You can enforce quality gates using the acceptables array within your custom metrics JSON. This allows you to compare current values against thresholds or previous values.
Available variables in acceptables expressions:
current.{metric_key}: The current metric value.prev.{metric_key}: The previous metric value (retrieved from diff.datastores:).diff.{metric_key}: The difference between current and previous (current.{metric_key} - prev.{metric_key}).If a condition fails, octocov will exit with an error message indicating which condition was not met.
{
"key": "performance_metrics",
"name": "Performance Metrics",
"metrics": [
{
"key": "response_time",
"name": "Response Time",
"value": 250.0,
"unit": "ms"
}
],
"acceptables": [
"current.response_time < 300",
"current.response_time <= prev.response_time"
]
}octocov identifies the pull request number using the following priority order:
GITHUB_PULL_REQUEST_NUMBER or OCTOCOV_GITHUB_PULL_REQUEST_NUMBER environment variables.GITHUB_REF environment variable (e.g., refs/pull/1/merge).GITHUB_REF (e.g., refs/heads/branch/name), which octocov then resolves using the GitHub API.You can override any environment variable used by octocov by prefixing it with OCTOCOV_. For example, setting OCTOCOV_GITHUB_REF will cause octocov to use the value of GITHUB_REF.
Central mode allows a single repository to act as a hub for collecting coverage reports from multiple other repositories. When enabled, other functions (like standard reporting) are automatically turned off.
Key Configuration Keys:
central.root: (String) Root directory or index file for collected reports. Default is ..central.reports.datastores: (List) Datastores where reports are collected from. Default is local://reports.central.badges.datastores: (List) Datastores where badges are generated. Default is local://badges.central.push: (Boolean/Config) Configuration for pushing the index file and badges.central.reReport.datastores: (List) Additional datastores to re-store collected reports.central.if: (Expression) Condition for running central mode.Usage Patterns:
artifact:// in the sub-repos and perform badge generation via on.schedule in the central repo.github:// in sub-repos and perform badge generation via on.push in the central repo.on.schedule in the central repo.You can use octocov as a local code metrics viewer. After generating a coverage report (e.g., go test ./... -coverprofile=coverage.out), use the following commands:
octocov ls-files: Lists files logged in the code coverage report.octocov view [FILE...]: Views the coverage report for specific files (alias: octocov cat).octocov diff [REPORT_A] [REPORT_B]: Compares two reports.$ go test ./... -coverprofile=coverage.out
$ octocov ls-files
$ octocov view path/to/file.goChoose the installation method that matches your environment.
export OCTOCOV_VERSION=X.X.X
curl -o octocov.deb -L https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.deb
dpkg -i octocov.debexport OCTOCOV_VERSION=X.X.X
yum install https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.rpmexport OCTOCOV_VERSION=X.X.X
curl -o octocov.apk -L https://github.com/k1LoW/octocov/releases/download/v$OCTOCOV_VERSION/octocov_$OCTOCOV_VERSION-1_amd64.apk
apk add octocov.apkbrew install k1LoW/tap/octocovaqua g -i k1LoW/octocovgo install github.com/k1LoW/octocov@latestdocker pull ghcr.io/k1low/octocov:latestTo use octocov in your CI pipeline, follow these steps:
-coverprofile=coverage.out).octocov init to generate a .octocov.yml file in your repository.k1LoW/octocov-action@v1.Note: octocov can only comment on pull requests originating from the same repository due to GitHub token permissions. However, reporting to GitHub Actions Job Summaries is always permitted.
# .github/workflows/ci.yml
name: Test
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v3
-
uses: actions/setup-go@v4
with:
go-version-file: go.mod
-
name: Run tests with coverage report output
run: go test ./... -coverprofile=coverage.out
-
uses: k1LoW/octocov-action@v1If you use test sharding (e.g., a matrix strategy in GitHub Actions), you can aggregate the results into a single report.
octocov-1, octocov-2).actions/download-artifact with a pattern to download all shards..octocov.yml, list the artifact names under coverage.paths.This allows octocov to combine coverage from multiple environments or shards into one unified metric.
# .octocov.yml for aggregation
coverage:
paths:
- "octocov-1"
- "octocov-2"
- "octocov-3"When running in a CI environment (CI=true), octocov can perform several automated tasks based on your .octocov.yml configuration:
acceptable thresholds defined in the config.You can automatically generate SVG badges for your metrics and save them to a path. You can also use the push: key to automatically git push these badges.
Supported metrics for badges:
coverage.badge.pathcodeToTestRatio.badge.pathtestExecutionTime.badge.pathcoverage:
badge:
path: docs/coverage.svg
codeToTestRatio:
badge:
path: docs/ratio.svg
testExecutionTime:
badge:
path: docs/time.svg
push:Use testExecutionTime to monitor how long tests take to run.
testExecutionTime.steps: (List) Names of the steps to measure. If omitted, the step that generates the coverage report is used.testExecutionTime.acceptable: (Expression) Condition for acceptable time (e.g., 1min or current <= 1min && diff <= 1sec).testExecutionTime.badge.path: (String) Path to generate the time badge.testExecutionTime.if: (Expression) Condition for measuring time.testExecutionTime:
steps:
- Run test
- Run slow test
acceptable: 1min
badge:
path: docs/time.svg