https://blueflare.gitea.bluefla.re/alkane-toolkit/ is built from this repo (gh-pages) after every main run: overview, manual, a quality dashboard and the benchmark history, which no longer goes to alkane-benchmarks. The quality grade is now Clippy/rustfmt plus the line-coverage band (the coverage badge's own colour bands), not only the Clippy result, and main CI publishes the full measurement (per-crate and per-file coverage, LOC per crate) as quality.json for the dashboard. README badges link to their pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
294 lines
15 KiB
Python
Executable File
294 lines
15 KiB
Python
Executable File
#!/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'<a href="{up}{path}"{" class=on" if path == current else ""}>{label}</a>'
|
|
for path, label in SECTIONS)
|
|
built = f"Built from {html.escape(sha[:10])}. " if sha else ""
|
|
return f"""<!doctype html>
|
|
<html lang="en"><head><meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{html.escape(title)} - Alkane Toolkit</title>
|
|
<link rel="stylesheet" href="{up}style.css"></head>
|
|
<body><header><div class="bar"><a class="brand" href="{up}"><i></i>Alkane Toolkit</a>
|
|
<nav>{nav}<a href="{RELEASES}">Downloads</a><a href="{REPO}">Source</a></nav></div></header>
|
|
<main>{body}
|
|
<footer>{built}Alkane Toolkit is MIT licensed.</footer></main></body></html>
|
|
"""
|
|
|
|
|
|
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'<li><a href="{slug}.html"{" class=on" if slug == current else ""}>'
|
|
f"{html.escape(title)}</a></li>" for slug, title, _ in items)
|
|
return f"<aside><ol>{links}</ol></aside>"
|
|
|
|
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'<div class="layout">{toc(slug)}<article>{body_html}</article></div>',
|
|
1, "manual/", sha))
|
|
first = items[0][0]
|
|
listing = "".join(f'<li><a href="{s}.html">{html.escape(t)}</a></li>' for s, t, _ in items)
|
|
write(out, "manual/index.html",
|
|
page("Manual", f"<h1>Manual</h1><p>Start with "
|
|
f'<a href="{first}.html">{html.escape(items[0][1])}</a>.</p><ol>{listing}</ol>',
|
|
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'<div class="meter"><i style="width:{max(0.0, min(pct, 100.0)):.1f}%;background:{colour}"></i></div>'
|
|
|
|
|
|
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", "<h1>Code quality</h1><p>No measurement has been published yet; "
|
|
"the next main build will fill this page.</p>", 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'<div class="card"><b class="{cls}">{value}</b><span>{label}</span></div>'
|
|
|
|
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"<p>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.</p>")
|
|
|
|
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'<td class="num {pct_class(pct)}">{pct:.1f}%</td>'
|
|
f'<td class="bar-cell">{meter(pct)}</td>'
|
|
f'<td class="num">{c["lines"] - c["missed"]:,} / {c["lines"]:,}</td>')
|
|
else:
|
|
cov_cells = '<td class="num">-</td><td></td><td class="num">-</td>'
|
|
rows.append(f"<tr><td>{e(name)}</td>{cov_cells}<td class='num'>{loc.get(name, 0):,}</td></tr>")
|
|
crate_table = ("<table><tr><th>Crate</th><th class=num>Line coverage</th><th></th>"
|
|
"<th class=num>Covered lines</th><th class=num>Lines of Rust</th></tr>"
|
|
+ "".join(rows) + "</table>")
|
|
|
|
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"<tr><td><code>{e(r['file'])}</code></td>"
|
|
f"<td class='num {pct_class(100.0 * (r['lines'] - r['missed']) / r['lines'])}'>"
|
|
f"{100.0 * (r['lines'] - r['missed']) / r['lines']:.1f}%</td>"
|
|
f"<td class='num'>{r['missed']:,}</td><td class='num'>{r['lines']:,}</td></tr>"
|
|
for r in files if r["lines"])
|
|
file_table = ("<table><tr><th>File (least covered first)</th><th class=num>Coverage</th>"
|
|
"<th class=num>Uncovered lines</th><th class=num>Lines</th></tr>"
|
|
+ file_rows + "</table>") if file_rows else ""
|
|
|
|
measured = str(quality.get("sha", ""))[:10]
|
|
of_build = f" (this page: <code>{e(measured)}</code>)" if measured else ""
|
|
body = f"""<h1>Code quality</h1>
|
|
<p>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.</p>
|
|
<div class="cards">{cards}</div>
|
|
<h2 id="grade">How the grade is set</h2>{grade_rule}
|
|
<h2 id="coverage">Coverage by crate</h2>{crate_table}
|
|
<h2 id="files">Coverage by file</h2>{file_table}
|
|
<p>The dependency count is every package in <code>Cargo.lock</code>, direct and
|
|
transitive. Lines of Rust count every <code>.rs</code> line under <code>crates/</code>,
|
|
tests included.</p>"""
|
|
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", "<h1>Benchmarks</h1><p>No benchmark history yet.</p>", 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"<style[^>]*>.*?</style>", rendered, re.S | re.I))
|
|
m = re.search(r"<body[^>]*>(.*)</body>", 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("</head>", styles + "</head>", 1))
|
|
|
|
|
|
def build_index(out: Path, quality: dict | None, sha: str) -> None:
|
|
grade = html.escape(str((quality or {}).get("grade", "pending")))
|
|
body = f"""<h1>Alkane Toolkit</h1>
|
|
<p>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.</p>
|
|
<div class="buttons"><a class="primary" href="{RELEASES}">Download for Windows or Linux</a>
|
|
<a href="manual/">Read the manual</a><a href="quality/">Code quality: {grade}</a>
|
|
<a href="bench/">Benchmarks</a></div>
|
|
<h2>Platforms</h2>
|
|
<ul><li><b>Windows 10 and 11</b> (x86_64): one signed, self-contained <code>alkane-toolkit.exe</code>.</li>
|
|
<li><b>Linux</b> (x86_64, GTK 3): one binary.</li></ul>
|
|
<p>Every release is built, tested and signed by CI from the public source.</p>"""
|
|
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()
|