diff --git a/tests/test_roadmap.py b/tests/test_roadmap.py index 3b8e15b45..641d4e11b 100644 --- a/tests/test_roadmap.py +++ b/tests/test_roadmap.py @@ -1,5 +1,6 @@ import copy import datetime +import json import tomllib import unittest from unittest import mock @@ -77,9 +78,15 @@ class RepositoryRoadmap(unittest.TestCase): def test_the_roadmap_keeps_its_rules(self): self.assertEqual(roadmap.validate(roadmap.load()), []) - def test_roadmap_md_is_generated_from_the_toml(self): - self.assertEqual(roadmap.OUTPUT.read_text(), roadmap.render(roadmap.load()), - "ROADMAP.md is out of date: run `python3 tools/roadmap.py build`") + def test_generated_files_match_the_toml(self): + for path, text in roadmap.outputs(roadmap.load()).items(): + self.assertEqual(path.read_text(), text, f"{path.name} is out of date: run `python3 tools/roadmap.py build`") + + def test_site_data_has_every_item_in_one_line_text(self): + data = json.loads(roadmap.site_data(tomllib.loads(SAMPLE))) + self.assertEqual([item["id"] for item in data["items"]], ["fast", "faster", "fastest", "old"]) + self.assertEqual(data["items"][0]["dev"], "Multiply, not divide (#10).") + self.assertEqual(data["areas"], [{"id": "performance", "name": "Performance"}]) class Rules(unittest.TestCase): diff --git a/tools/roadmap.py b/tools/roadmap.py index d80c9692c..1a4f58136 100644 --- a/tools/roadmap.py +++ b/tools/roadmap.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """Horizon's roadmap: roadmap/roadmap.toml is the source, ROADMAP.md is generated from it. - python3 tools/roadmap.py build write ROADMAP.md - python3 tools/roadmap.py build --check fail when ROADMAP.md is out of date (CI) + python3 tools/roadmap.py build write ROADMAP.md and website/data/roadmap.json + python3 tools/roadmap.py build --check fail when either is out of date (CI) python3 tools/roadmap.py check --offline the file's own rules (CI) python3 tools/roadmap.py check the same, then GitHub: links resolve, no stale Now item python3 tools/roadmap.py sync [--dry-run] items whose pull requests all merged become shipped, @@ -28,6 +28,8 @@ from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SOURCE = ROOT / "roadmap" / "roadmap.toml" OUTPUT = ROOT / "ROADMAP.md" +# What the website's hub reads (website/build.mjs), and serves at /hub/roadmap.json for Kira and others. +SITE_DATA = ROOT / "website" / "data" / "roadmap.json" REPO = "ludovic111/horizon" SITE = "https://playhorizon.dev/hub" @@ -227,6 +229,27 @@ def render(data): return "\n".join(out) + "\n" +def site_data(data): + """website/data/roadmap.json: the items as the hub and Kira read them, in the file's order.""" + keys = ("id", "title", "status", "area", "plain", "dev", "links", "focus", "ongoing", "shipped_in", "post") + out = { + "format": "horizon-roadmap", + "version": 1, + "source": "roadmap/roadmap.toml", + "overview": {key: " ".join(value.split()) for key, value in data["overview"].items()}, + "statuses": [{"id": key, "name": name} for key, name in STATUSES.items()], + "areas": [{"id": key, "name": name} for key, name in areas_in_order(data)], + "items": [{key: (" ".join(item[key].split()) if isinstance(item[key], str) else item[key]) + for key in keys if key in item} for item in data.get("item", [])], + } + return json.dumps(out, indent=1, ensure_ascii=False) + "\n" + + +def outputs(data): + """Every generated file and its content.""" + return {OUTPUT: render(data), SITE_DATA: site_data(data)} + + # --- GitHub --------------------------------------------------------------------------------------------------- def token(): @@ -466,13 +489,15 @@ def command_build(args): problems = validate(data) if problems: return report(problems) - markdown = render(data) + files = outputs(data) if args.check: - if not OUTPUT.exists() or OUTPUT.read_text() != markdown: - return report(["ROADMAP.md is out of date: run `python3 tools/roadmap.py build`"]) - return 0 - OUTPUT.write_text(markdown) - print(f"roadmap: wrote {OUTPUT.relative_to(ROOT)}") + stale = [path for path, text in files.items() if not path.exists() or path.read_text() != text] + return report([f"{path.relative_to(ROOT)} is out of date: run `python3 tools/roadmap.py build`" + for path in stale]) + for path, text in files.items(): + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(text) + print(f"roadmap: wrote {path.relative_to(ROOT)}") return 0 @@ -505,8 +530,9 @@ def command_sync(args): if len(new.get("item", [])) != len(data.get("item", [])) or validate(new): return report(["sync produced an invalid file; nothing written"] + validate(new)) SOURCE.write_text(text) - OUTPUT.write_text(render(new)) - print("roadmap: wrote roadmap/roadmap.toml and ROADMAP.md") + for path, content in outputs(new).items(): + path.write_text(content) + print("roadmap: wrote roadmap/roadmap.toml, ROADMAP.md and website/data/roadmap.json") return 0 diff --git a/website/Caddyfile b/website/Caddyfile index 1571566ad..50ba44381 100644 --- a/website/Caddyfile +++ b/website/Caddyfile @@ -33,9 +33,12 @@ rewrite /privacy /privacy.html rewrite /releases /releases.html rewrite /benchmarks /benchmarks.html + rewrite /hub /hub.html + # The roadmap is the hub's Roadmap tab. + redir /roadmap /hub#roadmap permanent @doc path_regexp doc ^/docs/([a-z-]+)$ rewrite @doc /docs/{re.doc.1}.html - @pages path / /index.html /404.html /privacy.html /releases /releases.html /benchmarks /benchmarks.html /benchmarks.json /docs /docs/* /sitemap.xml + @pages path / /index.html /404.html /privacy.html /releases /releases.html /benchmarks /benchmarks.html /benchmarks.json /hub /hub.html /hub/* /docs /docs/* /sitemap.xml header @pages Cache-Control "no-cache" @legal path /LEGAL.md /fonts/*.txt header @legal Content-Type "text/plain; charset=utf-8" diff --git a/website/README.md b/website/README.md index 9d1f8dc8d..c73683c73 100644 --- a/website/README.md +++ b/website/README.md @@ -25,6 +25,7 @@ src/404.html the not-found page src/privacy.html what the launcher can send when players allow it, retention, deletion (/privacy) src/releases.html every release, newest first, with what it adds and fixes, its notes and downloads (/releases) src/benchmarks.html Horizon against vanilla 26.3 on our machines, the hardware picker, players' results (/benchmarks) +src/hub.html the hub (/hub, /roadmap redirects to its Roadmap tab): Overview, Roadmap, Contribute, a Simple / Technical switch src/docs.html the template of every documentation page (/docs/...), with its left navigation src/tokens.css the design tokens, generated from crates/horizon-theme (do not edit) src/style.css every style, on top of the tokens @@ -39,6 +40,9 @@ src/estimate.js estimates for unmeasured hardware from the nearest measured m src/markdown.js a small Markdown renderer (escapes everything), shared by build and page src/releases.js the home page's "Recently added" and the Releases page's markup, shared by build and page src/contributors.js the contributors' filtering and markup, shared by build and page +src/hub.js the hub's markup from data/roadmap.json and GitHub's issue states, shared by build and page +src/hub-page.js the hub page: tabs by #hash, the Simple / Technical switch (localStorage), the area filter, live states +data/roadmap.json the roadmap, generated by tools/roadmap.py from roadmap/roadmap.toml (do not edit); served at /hub/roadmap.json public/ fonts, screenshots, icons, og.png, robots.txt, benchmarks.json: copied as is (sitemap.xml is written by the build) data/benchmarks/ our raw benchmark reports (tools/perf_bench.py) and fleet.json, the list scripts/benchmarks.mjs reads scripts/benchmarks.mjs benchmark reports -> public/benchmarks.json (ours, and players' groups of 3+ installs) diff --git a/website/build.mjs b/website/build.mjs index 8b0954054..b36e0e103 100644 --- a/website/build.mjs +++ b/website/build.mjs @@ -16,6 +16,7 @@ import { machinesHtml, playersHtml } from "./src/bench.js"; import { CPUS, GPUS, singleThread } from "./src/hardware.js"; import { isGame, isLauncher, launcherVersion, newestFirst } from "./src/versions.js"; import { contributorsFrom, contributorsHtml } from "./src/contributors.js"; +import { areaFilterHtml, helpWantedHtml, overviewHtml, roadmapHtml, slimIssue } from "./src/hub.js"; const site = dirname(fileURLToPath(import.meta.url)); const dist = join(site, "dist"); @@ -77,6 +78,45 @@ try { console.warn(`contributors: ${e.message}; the page will load them itself`); } +// The hub's roadmap (data/roadmap.json, generated from roadmap/roadmap.toml by tools/roadmap.py) and the live state +// of the issues and pull requests its items link: the open ones and those closed lately, then (with a token) the +// older ones in one GraphQL request. Without GitHub the hub shows the links without their state. +const roadmap = JSON.parse(await readFile(join(site, "data", "roadmap.json"), "utf8")); +const linked = new Set(roadmap.items.flatMap((i) => (i.links || []).map((l) => Number((l.match(/^#(\d+)$/) || [])[1])).filter(Boolean))); +let hubLive = []; +try { + const urls = [1, 2, 3].map((p) => `https://api.github.com/repos/${REPO}/issues?state=open&per_page=100&page=${p}`); + urls.push(`https://api.github.com/repos/${REPO}/issues?state=closed&sort=updated&direction=desc&per_page=100`); + for (const url of urls) { + const res = await fetch(url, { headers: githubHeaders, signal: AbortSignal.timeout(15000) }); + if (!res.ok) throw new Error(`${res.status} from GitHub`); + hubLive.push(...(await res.json()).map(slimIssue)); + } + const missing = [...linked].filter((n) => !hubLive.some((i) => i.n === n)); + if (missing.length && process.env.GITHUB_TOKEN) { + const fields = missing.map((n) => `n${n}: issueOrPullRequest(number: ${n}) { ... on Issue { number title state stateReason url } ... on PullRequest { number title state isDraft mergedAt url } }`).join(" "); + const res = await fetch("https://api.github.com/graphql", { + method: "POST", + headers: githubHeaders, + body: JSON.stringify({ query: `query { repository(owner: "ludovic111", name: "horizon") { ${fields} } }` }), + signal: AbortSignal.timeout(15000), + }); + const nodes = Object.values((await res.json()).data?.repository || {}).filter(Boolean); + hubLive.push( + ...nodes.map((x) => + slimIssue({ + number: x.number, title: x.title, html_url: x.url, draft: x.isDraft, + state: x.state === "OPEN" ? "open" : "closed", state_reason: x.stateReason === "NOT_PLANNED" ? "not_planned" : null, + pull_request: "isDraft" in x ? { merged_at: x.mergedAt } : undefined, + }), + ), + ); + } +} catch (e) { + console.warn(`hub: ${e.message}; the page will load the states itself`); +} +const hubLinked = new Map(hubLive.filter((i) => linked.has(i.n)).map((i) => [i.n, i])); + // --- The parity table ------------------------------------------------------------------ const status = section(readme, "Project status") ?? ""; @@ -170,7 +210,7 @@ await writeFile(join(dist, "favicon.ico"), Buffer.concat([ico, png32])); const names = {}; const rewrite = (code) => code.replace(/"\.\/(\w+\.js)"/g, (all, file) => (names[file] ? `"./${names[file]}"` : all)); // Dependencies before what imports them. -const modules = ["markdown.js", "versions.js", "chrome.js", "hardware.js", "estimate.js", "releases.js", "contributors.js", "bench.js", "main.js", "releases-page.js", "benchmarks-page.js", "docs-page.js"]; +const modules = ["markdown.js", "versions.js", "chrome.js", "hardware.js", "estimate.js", "releases.js", "contributors.js", "bench.js", "hub.js", "main.js", "releases-page.js", "benchmarks-page.js", "docs-page.js", "hub-page.js"]; for (const file of modules) { const code = rewrite(await readFile(join(site, "src", file), "utf8")); names[file] = `${file.replace(".js", "")}.${fingerprint(code)}.js`; @@ -203,7 +243,7 @@ const unavailable = `

The release notes could not be loaded here. // One top bar and phone menu for Home, Releases, Benchmarks and every Docs page. const navSections = [["/#about", "About"], ["/#screenshots", "In game"], ["/#parity", "Parity"], ["/#launcher", "Launcher"], ["/#recent", "New", "Recently added"], ["/#community", "Community"]]; -const navPages = [["/releases", "Releases"], ["/benchmarks", "Benchmarks"], ["/docs/", "Docs", "Documentation"]]; +const navPages = [["/hub", "Hub"], ["/releases", "Releases"], ["/benchmarks", "Benchmarks"], ["/docs/", "Docs", "Documentation"]]; const navLink = ([href, label, menuLabel], current, menu = false) => `${menu && menuLabel ? menuLabel : label}`; const siteNav = (current) => `