From faae4ee1453ffac791807c1cb0d1e3e65cefd794 Mon Sep 17 00:00:00 2001 From: noah Date: Fri, 16 Oct 2026 07:19:42 -0600 Subject: [PATCH] Publish Toolkit benchmarks to public Pages site --- .gitea/workflows/release.yml | 7 ++- README.md | 2 + ci/publish-bench-pages.py | 111 +++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 ci/publish-bench-pages.py diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index a847959f..0ef06c4f 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -49,7 +49,7 @@ jobs: run: | apt-get update -qq apt-get install -y -qq --no-install-recommends \ - libssl-dev pkg-config ca-certificates >/dev/null + libssl-dev pkg-config ca-certificates openssh-client >/dev/null echo "libssl-dev + pkg-config installed (openssl-sys needs them)" - name: Cache vendored wxWidgets build @@ -112,6 +112,11 @@ jobs: with: name: alkane-toolkit-benchmark-site-preview path: bench-site/index.html + - name: Publish public benchmark page + env: + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + BENCH_PAGES_DEPLOY_KEY: ${{ secrets.BENCH_PAGES_DEPLOY_KEY }} + run: python3 ci/publish-bench-pages.py toolkit - name: Headless UI self-test run: | diff --git a/README.md b/README.md index 7f0b994f..242ab583 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ publishes qualifying releases; `next` builds `-rc` candidates. Badges report host tests and benchmarks, not installation support. Benchmark comparisons require the same CPU class. The code quality letter reports the Clippy gate; the separate coverage badge reports exercised lines. +The [benchmark history](https://blueflare.gitea.bluefla.re/alkane-benchmarks/toolkit/) +is readable without a Gitea login. ## Firmware safety diff --git a/ci/publish-bench-pages.py b/ci/publish-bench-pages.py new file mode 100644 index 00000000..1819f5ac --- /dev/null +++ b/ci/publish-bench-pages.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: MIT +"""Publish a measured benchmark page to the public, data-only Pages repo.""" + +import argparse +import json +import os +from pathlib import Path +import shlex +import subprocess +import tempfile +from urllib.request import Request, urlopen + +PAGES_REPO = "ssh://git@gitea.bluefla.re:2222/blueflare/alkane-benchmarks.git" +PAGES_HOST = "gitea.bluefla.re" +PAGES_HOST_FINGERPRINT = "SHA256:lqB5cmC9E5HNeg/lkzdOwQ++I8A70Wx7lnNs6liN24g" + + +def run(*args: str, env: dict[str, str] | None = None, + cwd: Path | None = None) -> subprocess.CompletedProcess[str]: + return subprocess.run(args, env=env, cwd=cwd, text=True, + capture_output=True, check=True) + + +def current_main_sha() -> str: + api = os.environ["GITHUB_API_URL"].rstrip("/") + repo = os.environ["GITHUB_REPOSITORY"] + token = os.environ["GITEA_TOKEN"] + request = Request(f"{api}/repos/{repo}/branches/main", + headers={"Authorization": f"token {token}"}) + with urlopen(request, timeout=20) as response: + branch = json.load(response) + return branch["commit"]["id"] + + +def publish(site: str) -> None: + if os.environ.get("GITHUB_REF") != "refs/heads/main": + raise ValueError("benchmark Pages publication requires main") + sha = os.environ["GITHUB_SHA"] + if current_main_sha() != sha: + print("Skipping benchmark page from a superseded main commit") + return + page = Path("bench-site/index.html").read_bytes() + if not page.startswith(b"") or len(page) > 1_048_576: + raise ValueError("invalid benchmark page") + key = os.environ["BENCH_PAGES_DEPLOY_KEY"] + if not key.startswith("-----BEGIN OPENSSH PRIVATE KEY-----"): + raise ValueError("missing benchmark Pages deploy key") + + with tempfile.TemporaryDirectory(prefix="alkane-pages-") as directory: + temporary = Path(directory) + key_path = temporary / "deploy_key" + key_path.write_text(key.rstrip("\n") + "\n") + key_path.chmod(0o600) + scanned = run("ssh-keyscan", "-p", "2222", "-t", "ed25519", PAGES_HOST) + known_hosts = temporary / "known_hosts" + known_hosts.write_text(scanned.stdout) + fingerprint = run("ssh-keygen", "-lf", str(known_hosts)).stdout.split()[1] + if fingerprint != PAGES_HOST_FINGERPRINT: + raise ValueError("benchmark Pages SSH host key changed") + git_env = os.environ.copy() + ssh_command = (f"ssh -i {shlex.quote(str(key_path))} -o IdentitiesOnly=yes " + f"-o UserKnownHostsFile={shlex.quote(str(known_hosts))} " + "-o StrictHostKeyChecking=yes") + git_env["GIT_SSH_COMMAND"] = ssh_command + git_env["GIT_TERMINAL_PROMPT"] = "0" + checkout = temporary / "site" + run("git", "clone", "--quiet", "--single-branch", "--branch", "gh-pages", + PAGES_REPO, str(checkout), env=git_env) + run("git", "config", "user.name", "Alkane CI", cwd=checkout) + run("git", "config", "user.email", "ci@bluefla.re", cwd=checkout) + for attempt in range(3): + if current_main_sha() != sha: + print("Skipping benchmark page from a superseded main commit") + return + run("git", "fetch", "--quiet", "origin", "gh-pages", env=git_env, + cwd=checkout) + run("git", "checkout", "-q", "-B", "bench-publish", "origin/gh-pages", + cwd=checkout) + destination = checkout / site / "index.html" + destination.parent.mkdir(exist_ok=True) + destination.write_bytes(page) + run("git", "add", f"{site}/index.html", cwd=checkout) + changed = subprocess.run(("git", "diff", "--cached", "--quiet"), + cwd=checkout, check=False) + if changed.returncode == 0: + print(f"{site} benchmark page is already current") + return + if changed.returncode != 1: + raise RuntimeError("cannot compare benchmark page") + run("git", "commit", "-q", "-m", + f"Update {site} benchmarks for {sha[:10]} [skip ci]", cwd=checkout) + pushed = subprocess.run(("git", "push", "--quiet", "origin", + "HEAD:gh-pages"), env=git_env, cwd=checkout, + text=True, capture_output=True, check=False) + if pushed.returncode == 0: + print(f"Published {site} benchmark page for {sha[:10]}") + return + if attempt == 2: + raise RuntimeError(f"benchmark Pages push failed: {pushed.stderr.strip()}") + raise RuntimeError("benchmark Pages publication did not complete") + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("site", choices=("sdk", "os", "toolkit")) + publish(parser.parse_args().site) + + +if __name__ == "__main__": + main()