#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Build the Alkane Toolkit Pages site (served from this repo's gh-pages). build-pages.py --out site [--manual docs/manual] [--quality quality.json] [--bench bench-site/index.html] [--sha SHA] Pages: / overview and downloads /manual/ the user manual, one page per docs/manual/NN-name.md chapter /quality/ code-quality dashboard from the measured quality.json that main CI publishes next to the badges (ci/gen-badges.py) /bench/ the measured benchmark history (ci/bench_history.py render) Every value taken from CI data is HTML-escaped; the manual is Markdown written in this repository. """ import argparse import html import json import re import shutil from pathlib import Path import markdown REPO = "https://gitea.bluefla.re/blueflare/alkane-toolkit" RELEASES = REPO + "/releases" SECTIONS = (("", "Overview"), ("manual/", "Manual"), ("quality/", "Code quality"), ("bench/", "Benchmarks")) CSS = """ :root { --bg:#ffffff; --fg:#1f2328; --muted:#59636e; --line:#d1d9e0; --card:#f6f8fa; --accent:#d9822b; --link:#0969da; --good:#1a7f37; --warn:#9a6700; --bad:#cf222e; } @media (prefers-color-scheme: dark) { :root { --bg:#0d1117; --fg:#e6edf3; --muted:#9198a1; --line:#30363d; --card:#151b23; --link:#4493f8; --good:#3fb950; --warn:#d29922; --bad:#f85149; } } * { box-sizing: border-box; } body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,Ubuntu,sans-serif; } a { color:var(--link); text-decoration:none; } a:hover { text-decoration:underline; } header { border-bottom:1px solid var(--line); } header .bar, main { max-width:1040px; margin:0 auto; padding:0 16px; } header .bar { display:flex; align-items:center; gap:24px; height:56px; flex-wrap:wrap; } header .brand { font-weight:700; color:var(--fg); display:flex; gap:8px; align-items:center; } header .brand i { width:20px; height:20px; border-radius:5px; background:var(--accent); display:inline-block; } header nav { display:flex; gap:18px; flex-wrap:wrap; } header nav a { color:var(--muted); } header nav a.on { color:var(--fg); font-weight:600; } main { padding:28px 16px 64px; } h1 { font-size:1.9rem; margin:.2em 0 .4em; } h2 { margin-top:1.8em; border-bottom:1px solid var(--line); padding-bottom:.25em; } code { background:var(--card); border:1px solid var(--line); border-radius:5px; padding:.1em .35em; font-size:.92em; } pre { background:var(--card); border:1px solid var(--line); border-radius:8px; padding:12px; overflow:auto; } pre code { border:0; padding:0; } table { border-collapse:collapse; width:100%; margin:1em 0; display:block; overflow-x:auto; } th, td { border:1px solid var(--line); padding:6px 10px; text-align:left; vertical-align:top; } th { background:var(--card); } td.num, th.num { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; } .cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(180px,1fr)); gap:12px; margin:1.2em 0; } .card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:14px; } .card b { display:block; font-size:1.6rem; } .card span { color:var(--muted); font-size:.9rem; } .good { color:var(--good); } .warn { color:var(--warn); } .bad { color:var(--bad); } .bar-cell { min-width:120px; } .meter { height:8px; background:var(--line); border-radius:4px; overflow:hidden; } .meter i { display:block; height:100%; } .layout { display:grid; grid-template-columns:220px 1fr; gap:32px; } .layout aside ol { padding-left:1.2em; margin:0; } .layout aside li { margin:.3em 0; } .layout aside a.on { font-weight:600; color:var(--fg); } @media (max-width:760px) { .layout { grid-template-columns:1fr; } } .buttons a { display:inline-block; margin:4px 8px 4px 0; padding:8px 14px; border-radius:8px; border:1px solid var(--line); background:var(--card); color:var(--fg); } .buttons a.primary { background:var(--accent); border-color:var(--accent); color:#fff; } footer { color:var(--muted); font-size:.85rem; margin-top:48px; } """ def page(title: str, body: str, depth: int, current: str, sha: str) -> str: up = "../" * depth nav = "".join( f'{label}' for path, label in SECTIONS) built = f"Built from {html.escape(sha[:10])}. " if sha else "" return f"""
Start with " f'{html.escape(items[0][1])}.
No measurement has been published yet; " "the next main build will fill this page.
", 1, "quality/", sha)) return grade = str(quality.get("grade", "pending")) cov = quality.get("coverage_pct") bench_cov = quality.get("bench_coverage_pct") delta = quality.get("bench_delta_pct") def card(value: str, label: str, cls: str = "") -> str: return f'The grade is F if Clippy or rustfmt fails on main. Otherwise it is the " f"line-coverage band: {bands}, and F below that. The coverage badge uses the " f"same bands for its colour, so the two never disagree.
") crates = quality.get("coverage_by_crate", {}) loc = quality.get("loc_by_crate", {}) rows = [] for name in sorted(set(crates) | set(loc)): c = crates.get(name) if c and c["lines"]: pct = 100.0 * (c["lines"] - c["missed"]) / c["lines"] cov_cells = (f'| Crate | Line coverage | " " | Covered lines | Lines of Rust |
|---|
{e(r['file'])}| File (least covered first) | Coverage | " "Uncovered lines | Lines |
|---|
{e(measured)})" if measured else ""
body = f"""Measured by main CI on every build{of_build}: unit tests, line coverage (unit tests plus the headless UI self-test), Clippy with warnings as errors, and rustfmt. Windows builds run the same tests under Wine and on real Windows 11.
The dependency count is every package in Cargo.lock, direct and
transitive. Lines of Rust count every .rs line under crates/,
tests included.
No benchmark history yet.
", 1, "bench/", sha)) return rendered = bench.read_text(encoding="utf-8") # The history renderer emits a complete document; keep its body (and its # own styles) under the site's header. styles = "".join(re.findall(r"", rendered, re.S | re.I)) m = re.search(r"]*>(.*)", rendered, re.S | re.I) inner = m.group(1) if m else rendered text = page("Benchmarks", inner, 1, "bench/", sha) write(out, "bench/index.html", text.replace("", styles + "", 1)) def build_index(out: Path, quality: dict | None, sha: str) -> None: grade = html.escape(str((quality or {}).get("grade", "pending"))) body = f"""Desktop discovery and monitoring for ASIC miners on your network: find every miner in your IP ranges, see hashrate, power, temperatures, fans and hashboard health at a glance, and run the controls each firmware supports.
alkane-toolkit.exe.Every release is built, tested and signed by CI from the public source.
""" write(out, "index.html", page("Overview", body, 0, "", sha)) def main() -> None: ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) ap.add_argument("--out", required=True) ap.add_argument("--manual", default="docs/manual") ap.add_argument("--quality", default=None) ap.add_argument("--bench", default=None) ap.add_argument("--sha", default="") args = ap.parse_args() out = Path(args.out) if out.exists(): shutil.rmtree(out) out.mkdir(parents=True) quality = None if args.quality and Path(args.quality).is_file(): quality = json.loads(Path(args.quality).read_text()) if not isinstance(quality, dict) or quality.get("schema") != 1: raise SystemExit("unsupported quality.json") (out / "style.css").write_text(CSS.strip() + "\n", encoding="utf-8") build_index(out, quality, args.sha) build_manual(out, Path(args.manual), args.sha) build_quality(out, quality, args.sha) build_bench(out, Path(args.bench) if args.bench else None, args.sha) print(f"built {sum(1 for _ in out.rglob('*.html'))} pages in {out}") if __name__ == "__main__": main()