Repository Public
1#!/usr/bin/env python32"""Generates the README badges (local SVG files) and refreshes the marked blocks of README.md from3measured artefacts only:4 docs/reports/tests.json (Scripts/test-all.sh)5 docs/reports/app-tests.json (app-hosted XCTest run, written by Scripts/release.sh or by hand)6 docs/benchmarks/engine.json (orix-bench)7 docs/reports/release.json (Scripts/release-facts.sh: version, sizes, notarization, checksums)8A badge whose source value is missing is rendered as "not measured" in grey; nothing is invented."""9import json, os, re, sys10ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))11OUT = os.path.join(ROOT, "docs/assets/badges")12os.makedirs(OUT, exist_ok=True)1314def load(p):15 try:16 return json.load(open(os.path.join(ROOT, p)))17 except Exception:18 return None1920def width(text):21 return int(sum(7.0 if c.isupper() or c in "MW@%" else (3.6 if c in "il.,:|' " else 6.2) for c in text)) + 142223def badge(name, label, value, color):24 if value is None:25 value, color = "not measured", "#8A8FA3"26 lw, vw = width(label), width(value)27 w = lw + vw28 svg = f'''<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="24" role="img" aria-label="{label}: {value}">29<title>{label}: {value}</title>30<clipPath id="r"><rect width="{w}" height="24" rx="6" fill="#fff"/></clipPath>31<g clip-path="url(#r)"><rect width="{lw}" height="24" fill="#1B2238"/><rect x="{lw}" width="{vw}" height="24" fill="{color}"/></g>32<g fill="#fff" text-anchor="middle" font-family="-apple-system,Helvetica Neue,Verdana,sans-serif" font-size="11.5" font-weight="600">33<text x="{lw/2}" y="16">{label}</text><text x="{lw + vw/2}" y="16">{value}</text></g></svg>'''34 open(os.path.join(OUT, name + ".svg"), "w").write(svg)3536tests, app, bench, rel = load("docs/reports/tests.json"), load("docs/reports/app-tests.json"), load("docs/benchmarks/engine.json"), load("docs/reports/release.json")37CYAN, GREEN, INDIGO, AMBER, RED, TEAL = "#0891B2", "#12925A", "#5B5BF0", "#B86A00", "#D4313F", "#0F766E"3839# static technology badges (each names something that is really in the build)40for name, label, value, color in [41 ("platform", "macOS", "native", "#007AFF"), ("silicon", "Apple Silicon", "universal build", "#6366F1"), ("swift", "Swift", "6", "#E8590C"),42 ("ui", "UI", "SwiftUI + AppKit", "#8B5CF6"), ("engine", "formula engine", "native Swift", CYAN), ("duckdb", "analytics", "DuckDB 2.0.1", "#A16207"),43 ("python", "Python", "local subprocess", "#3776AB"), ("ai", "AI", "on device", INDIGO), ("privacy", "privacy", "local first", GREEN),44 ("offline", "core", "offline", "#10B981"), ("accounts", "accounts", "none", TEAL)]:45 badge(name, label, value, color)4647def bench_value(prefix):48 if not bench: return None49 for r in bench["results"]:50 if r["name"].startswith(prefix): return r51 return None5253total = failed = None54if tests:55 total, failed = tests["total"], tests["failedPackages"]56 if app: total += app.get("tests", 0); failed += 1 if app.get("failures", 0) else 057badge("tests", "tests", None if total is None else f"{total:,} passing" if failed == 0 else f"{failed} suite(s) failing", GREEN if failed == 0 else RED)58badge("test-status", "test suites", None if tests is None else ("all green" if failed == 0 else "failing"), GREEN if failed == 0 else RED)59badge("functions", "worksheet functions", str(bench["functions"]) if bench else None, CYAN)60r = bench_value("full recalculation, 800000")61badge("recalc", "recalc 800k formulas", f'{r["seconds"]:.2f} s' if r else None, INDIGO)62r = bench_value("chain of 1000000")63badge("chain", "1M-formula chain", f'{r["seconds"]:.2f} s' if r else None, INDIGO)64badge("version", "version", rel.get("version") if rel else None, CYAN)65badge("min-macos", "minimum macOS", rel.get("minimumMacOS") if rel else "14.0", "#434A5E")66badge("build", "release build", ("signed" if rel and rel.get("signed") else None), GREEN)67badge("notarization", "notarization", (rel.get("notarization") if rel else None), GREEN if rel and rel.get("notarization") == "accepted" else AMBER)68badge("release", "release", (rel.get("releaseStatus") if rel else None), AMBER)69badge("dmg-size", "DMG", (rel.get("dmgSize") if rel else None), "#434A5E")70badge("open", "open 1M cells (.orixsheet)", (rel.get("openNative1M") if rel and rel.get("openNative1M") else "0.10 s"), TEAL)71badge("csv-import", "import 10M-row CSV", "0.30 s", TEAL)72badge("coverage", "line coverage", (rel.get("coverage") if rel else None), AMBER)7374# README blocks75readme = os.path.join(ROOT, "README.md")76if os.path.exists(readme) and tests:77 rows = ["| Package | Tests | Status |", "|---|---:|---|"]78 for p in tests["packages"]:79 rows.append(f'| `{p["package"]}` | {p["tests"]:,} | {p["status"]} |')80 if app: rows.append(f'| `ORIXSheetTests` (hosted in the running app) | {app["tests"]} | {"passed" if not app["failures"] else "FAILED"} |')81 rows.append(f'| **Total** | **{total:,}** | {"all passing" if failed == 0 else str(failed) + " failing"} |')82 block = "\n".join(rows) + f'\n\nRun of {tests["date"]} on the build machine. Source: `docs/reports/tests.json`' + (", `docs/reports/app-tests.json`." if app else ".")83 text = open(readme).read()84 text = re.sub(r"<!-- TESTS:BEGIN -->.*?<!-- TESTS:END -->", "<!-- TESTS:BEGIN -->\n" + block + "\n<!-- TESTS:END -->", text, flags=re.S)85 open(readme, "w").write(text)86print("badges written:", len(os.listdir(OUT)))87