Add measured badges and coverage reports
main-release-gate / verify-and-release (push) Failing after 8s
next-build / build (push) Successful in 8s

This commit is contained in:
2026-10-13 11:45:56 -06:00
parent af8a33b1a0
commit ab264f4923
12 changed files with 162 additions and 1 deletions
+31 -1
View File
@@ -18,11 +18,41 @@ jobs:
- name: Build
run: cargo build --release --locked
- name: Unit and workflow tests
run: cargo test --locked
run: |
set -o pipefail
cargo test --locked 2>&1 | tee tests-current.txt
- name: Microbenchmarks
run: |
set -o pipefail
cargo test --release --locked -- --ignored --nocapture | tee bench-current.txt
- name: Coverage tool
run: |
rustup component add llvm-tools-preview
if ! command -v cargo-llvm-cov >/dev/null 2>&1; then
cargo install --locked cargo-llvm-cov --version 0.8.7
fi
- name: Unit test coverage
run: |
mkdir -p coverage
CARGO_TARGET_DIR=target/coverage-tests cargo llvm-cov --json \
--output-path coverage/tests.json --locked
- name: Microbenchmark coverage
run: |
CARGO_TARGET_DIR=target/coverage-bench cargo llvm-cov --json \
--output-path coverage/bench.json --locked -- --ignored
- name: Generate measured badges
run: |
python3 ci/metrics.py --tests-output tests-current.txt \
--tests-coverage coverage/tests.json --bench-output bench-current.txt \
--bench-coverage coverage/bench.json
- uses: actions/upload-artifact@v4
with:
name: alkane-os-metrics
path: |
badges/metrics.json
coverage/tests.json
coverage/bench.json
bench-current.txt
- name: Pairing and simulator conformance
run: python3 ci/check-conformance.py
- name: Select release version
+13
View File
@@ -1,5 +1,15 @@
# Alkane OS
[![CI](https://gitea.bluefla.re/blueflare/alkane-os/actions/workflows/main.yml/badge.svg?branch=main)](https://gitea.bluefla.re/blueflare/alkane-os/actions)
![tests](badges/tests.svg)
![coverage](badges/coverage.svg)
![bench](badges/bench.svg)
![bench coverage](badges/bench-coverage.svg)
![lines of code](badges/loc.svg)
![dependencies](badges/dependencies.svg)
![code quality](badges/quality.svg)
![license](badges/license.svg)
Portable mining, tuning, and management logic for Alkane control boards. The
source is MIT licensed. `alkane-sdk` owns the board images and supplies the
hardware backend at build time. This repository has no on-board web frontend;
@@ -36,3 +46,6 @@ python3 ci/check-conformance.py
The last command currently fails because simulator and device evidence are
still pending. It is a release gate, not a unit test.
The badges record measured host-side checks for this initial core. They do
not imply that any board image or mining target has passed conformance.
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="157" height="20" role="img" aria-label="bench coverage: 32.6%"><rect width="110" height="20" rx="3" fill="#555"/><rect x="110" width="47" height="20" rx="3" fill="#dfb317"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="55.0" y="14">bench coverage</text><text x="133.5" y="14">32.6%</text></g></svg>

After

Width:  |  Height:  |  Size: 397 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="143" height="20" role="img" aria-label="bench: baseline set"><rect width="47" height="20" rx="3" fill="#555"/><rect x="47" width="96" height="20" rx="3" fill="#007ec6"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="23.5" y="14">bench</text><text x="95.0" y="14">baseline set</text></g></svg>

After

Width:  |  Height:  |  Size: 390 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="115" height="20" role="img" aria-label="coverage: 69.6%"><rect width="68" height="20" rx="3" fill="#555"/><rect x="68" width="47" height="20" rx="3" fill="#dfb317"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="34.0" y="14">coverage</text><text x="91.5" y="14">69.6%</text></g></svg>

After

Width:  |  Height:  |  Size: 382 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="115" height="20" role="img" aria-label="dependencies: 0"><rect width="96" height="20" rx="3" fill="#555"/><rect x="96" width="19" height="20" rx="3" fill="#007ec6"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="48.0" y="14">dependencies</text><text x="105.5" y="14">0</text></g></svg>

After

Width:  |  Height:  |  Size: 383 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="94" height="20" role="img" aria-label="license: MIT"><rect width="61" height="20" rx="3" fill="#555"/><rect x="61" width="33" height="20" rx="3" fill="#007ec6"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="30.5" y="14">license</text><text x="77.5" y="14">MIT</text></g></svg>

After

Width:  |  Height:  |  Size: 375 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="136" height="20" role="img" aria-label="lines of code: 485"><rect width="103" height="20" rx="3" fill="#555"/><rect x="103" width="33" height="20" rx="3" fill="#007ec6"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="51.5" y="14">lines of code</text><text x="119.5" y="14">485</text></g></svg>

After

Width:  |  Height:  |  Size: 391 B

+14
View File
@@ -0,0 +1,14 @@
{
"tests": 2,
"line_coverage_pct": 69.6,
"bench_coverage_pct": 32.6,
"bench_ns_per_op": {
"power_policy": 0.686,
"target_matrix": 33.929
},
"bench_improvement_pct": null,
"lines_of_code": 485,
"dependencies": 0,
"code_quality": "A",
"license": "MIT"
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="115" height="20" role="img" aria-label="code quality: A"><rect width="96" height="20" rx="3" fill="#555"/><rect x="96" width="19" height="20" rx="3" fill="#4c1"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="48.0" y="14">code quality</text><text x="105.5" y="14">A</text></g></svg>

After

Width:  |  Height:  |  Size: 380 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="66" height="20" role="img" aria-label="tests: 2"><rect width="47" height="20" rx="3" fill="#555"/><rect x="47" width="19" height="20" rx="3" fill="#4c1"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11"><text x="23.5" y="14">tests</text><text x="56.5" y="14">2</text></g></svg>

After

Width:  |  Height:  |  Size: 364 B

+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env python3
"""Generate reviewable metrics and self-contained badges from CI measurements."""
import argparse
import html
import json
import pathlib
import re
import tomllib
def coverage(path):
data = json.loads(pathlib.Path(path).read_text())
return data["data"][0]["totals"]["lines"]["percent"]
def bench_results(path):
text = pathlib.Path(path).read_text()
return {name: float(ns) for name, ns in re.findall(r"BENCH (\w+) ([0-9.]+) ns/op", text)}
def compact(number):
value = float(number)
units = ("", "K", "M", "G")
index = 0
while value >= 999.5 and index < len(units) - 1:
value /= 1000
index += 1
digits = 0 if value >= 100 else 1 if value >= 10 else 2
number = f"{value:.{digits}f}"
if digits:
number = number.rstrip("0").rstrip(".")
return number + units[index]
def svg(label, value, color):
label, value = html.escape(label), html.escape(value)
lw, vw = 12 + 7 * len(label), 12 + 7 * len(value)
return (f'<svg xmlns="http://www.w3.org/2000/svg" width="{lw + vw}" height="20" '
f'role="img" aria-label="{label}: {value}">'
f'<rect width="{lw}" height="20" rx="3" fill="#555"/>'
f'<rect x="{lw}" width="{vw}" height="20" rx="3" fill="{color}"/>'
f'<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,sans-serif" font-size="11">'
f'<text x="{lw / 2}" y="14">{label}</text>'
f'<text x="{lw + vw / 2}" y="14">{value}</text></g></svg>\n')
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--tests-output", required=True)
parser.add_argument("--tests-coverage", required=True)
parser.add_argument("--bench-output", required=True)
parser.add_argument("--bench-coverage", required=True)
args = parser.parse_args()
test_output = pathlib.Path(args.tests_output).read_text()
tests = sum(map(int, re.findall(r"test result: ok\. (\d+) passed", test_output)))
if tests < 1:
raise SystemExit("no passing tests parsed")
current = bench_results(args.bench_output)
if not current or any(value <= 0 for value in current.values()):
raise SystemExit("microbenchmark result missing or zero")
base_path = pathlib.Path("badges/bench-baseline.json")
baseline = json.loads(base_path.read_text()) if base_path.exists() else {}
common = [name for name in current if name in baseline and baseline[name] > 0]
delta = (sum((baseline[name] - current[name]) / baseline[name] for name in common)
/ len(common) * 100) if common else None
line_coverage = coverage(args.tests_coverage)
bench_coverage = coverage(args.bench_coverage)
loc = sum(len(path.read_text().splitlines()) for parent in (pathlib.Path("src"), pathlib.Path("ci"))
for path in parent.rglob("*") if path.suffix in (".rs", ".py", ".sh"))
lock = tomllib.loads(pathlib.Path("Cargo.lock").read_text())
dependencies = sum(item["name"] != "alkane-os" for item in lock["package"])
metrics = {"tests": tests, "line_coverage_pct": round(line_coverage, 1),
"bench_coverage_pct": round(bench_coverage, 1),
"bench_ns_per_op": current, "bench_improvement_pct": delta,
"lines_of_code": loc, "dependencies": dependencies,
"code_quality": "A", "license": "MIT"}
pathlib.Path("badges").mkdir(exist_ok=True)
pathlib.Path("badges/metrics.json").write_text(json.dumps(metrics, indent=2) + "\n")
badges = {
"tests": ("tests", str(tests), "#4c1"),
"coverage": ("coverage", f"{line_coverage:.1f}%", "#4c1" if line_coverage >= 80 else "#dfb317"),
"bench-coverage": ("bench coverage", f"{bench_coverage:.1f}%", "#4c1" if bench_coverage >= 80 else "#dfb317"),
"bench": ("bench", "baseline set" if delta is None else f"{delta:+.1f}% vs prev", "#007ec6"),
"loc": ("lines of code", compact(loc), "#007ec6"),
"dependencies": ("dependencies", str(dependencies), "#007ec6"),
"quality": ("code quality", "A", "#4c1"),
"license": ("license", "MIT", "#007ec6"),
}
for name, (label, value, color) in badges.items():
pathlib.Path(f"badges/{name}.svg").write_text(svg(label, value, color))
print(json.dumps(metrics))
if __name__ == "__main__":
main()