#!/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""" {html.escape(title)} - Alkane Toolkit
Alkane Toolkit
{body}
""" def write(out: Path, rel: str, text: str) -> None: path = out / rel path.parent.mkdir(parents=True, exist_ok=True) path.write_text(text, encoding="utf-8") # ---- manual ----------------------------------------------------------------- def chapters(manual: Path) -> list[tuple[str, str, str]]: """(slug, title, markdown) for docs/manual/NN-slug.md, in file-name order.""" out = [] for path in sorted(manual.glob("[0-9][0-9]-*.md")): text = path.read_text(encoding="utf-8") m = re.search(r"^# (.+)$", text, re.M) title = m.group(1).strip() if m else path.stem out.append((path.stem[3:], title, text)) return out def build_manual(out: Path, manual: Path, sha: str) -> None: items = chapters(manual) if not items: raise SystemExit(f"no manual chapters in {manual}") def toc(current: str) -> str: links = "".join( f'
  • ' f"{html.escape(title)}
  • " for slug, title, _ in items) return f"" for slug, title, text in items: # Chapters link to each other as NN-name.md in the repo; on the site # they are name.html. text = re.sub(r"\]\((?:\./)?[0-9][0-9]-([a-z0-9-]+)\.md(#[^)]*)?\)", r"](\1.html\2)", text) body_html = markdown.markdown(text, extensions=["tables", "fenced_code", "toc"]) write(out, f"manual/{slug}.html", page(title, f'
    {toc(slug)}
    {body_html}
    ', 1, "manual/", sha)) first = items[0][0] listing = "".join(f'
  • {html.escape(t)}
  • ' for s, t, _ in items) write(out, "manual/index.html", page("Manual", f"

    Manual

    Start with " f'{html.escape(items[0][1])}.

      {listing}
    ', 1, "manual/", sha)) # ---- quality dashboard --------------------------------------------------------- def pct_class(pct: float | None) -> str: if pct is None: return "" return "good" if pct >= 80 else "warn" if pct >= 40 else "bad" def meter(pct: float) -> str: colour = {"good": "var(--good)", "warn": "var(--warn)", "bad": "var(--bad)"}[pct_class(pct)] return f'
    ' def build_quality(out: Path, quality: dict | None, sha: str) -> None: e = html.escape if not quality: write(out, "quality/index.html", page( "Code quality", "

    Code quality

    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'
    {value}{label}
    ' cards = "".join([ card(e(grade), "Quality grade", {"A": "good", "B": "good", "C": "warn"}.get(grade, "bad")), card(e(str(quality.get("tests_passed", "-"))), "Tests passing", "good"), card(f"{cov:.1f}%" if cov is not None else "-", "Line coverage", pct_class(cov)), card(f"{bench_cov:.1f}%" if bench_cov is not None else "-", "Benchmark coverage", pct_class(bench_cov)), card(e(str(quality.get("clippy") or "-")), "Clippy (warnings are errors)", "good" if quality.get("clippy") == "clean" else "bad"), card(e(str(quality.get("rustfmt") or "-")), "rustfmt", "good" if quality.get("rustfmt") == "clean" else ""), card(f"{quality.get('loc', 0):,}", "Lines of Rust"), card(e(str(quality.get("dependencies", "-"))), "Crates in Cargo.lock"), card((f"{'+' if delta > 0 else ''}{delta:.1f}%" if delta is not None else "-"), "Benchmarks vs previous" + (" (same inputs)" if quality.get("bench_same_inputs") else ""), "" if delta is None else "good" if delta >= 2 else "" if delta > -2 else "warn"), ]) bands = ", ".join(f"{e(str(letter))} at {floor:.0f}% or more" for floor, letter in quality.get("grade_bands", [])) grade_rule = (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'{pct:.1f}%' f'{meter(pct)}' f'{c["lines"] - c["missed"]:,} / {c["lines"]:,}') else: cov_cells = '--' rows.append(f"{e(name)}{cov_cells}{loc.get(name, 0):,}") crate_table = ("" "" + "".join(rows) + "
    CrateLine coverageCovered linesLines of Rust
    ") files = sorted(quality.get("coverage_by_file", []), key=lambda r: (r["lines"] - r["missed"]) / r["lines"] if r["lines"] else 1) file_rows = "".join( f"{e(r['file'])}" f"" f"{100.0 * (r['lines'] - r['missed']) / r['lines']:.1f}%" f"{r['missed']:,}{r['lines']:,}" for r in files if r["lines"]) file_table = ("" "" + file_rows + "
    File (least covered first)CoverageUncovered linesLines
    ") if file_rows else "" measured = str(quality.get("sha", ""))[:10] of_build = f" (this page: {e(measured)})" if measured else "" body = f"""

    Code quality

    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.

    {cards}

    How the grade is set

    {grade_rule}

    Coverage by crate

    {crate_table}

    Coverage by file

    {file_table}

    The dependency count is every package in Cargo.lock, direct and transitive. Lines of Rust count every .rs line under crates/, tests included.

    """ write(out, "quality/index.html", page("Code quality", body, 1, "quality/", sha)) # ---- benchmarks + overview ------------------------------------------------------- def build_bench(out: Path, bench: Path | None, sha: str) -> None: if bench is None or not bench.is_file(): write(out, "bench/index.html", page( "Benchmarks", "

    Benchmarks

    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"""

    Alkane Toolkit

    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.

    Platforms

    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()