okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Version 0.2.15 / Control 0.1.61: app and Terminal 0.2.15, Control 0.1.61; every engine package stays 0.1.60 (the v0.2.14 files, carried by absolute url)e39a52e33

main
10.3 KiB194 linesraw
1#!/usr/bin/env python3
2"""The release the current docs describe, kept in one place:  docs/data/release.json
3
4    python tools/release_manifest.py --check     fail when a current page or a version source disagrees
5    python tools/release_manifest.py --write     write the manifest's versions into the current pages
6
7What it covers (standard library only, no network):
8  * the manifest against the code: app/Terminal version (strata_cli/__init__.py, apps/host and apps/desktop package
9    files, Cargo.toml) and Control/engine version (the CMake project version);
10  * the three installer file names in the manifest's asset list;
11  * every installer file name (Strata-<version>-windows-x64-setup.exe, ...-linux-x86_64.AppImage, ...-macos-arm64.dmg)
12    in a current page: the version must be the manifest's, and the file must be in the release's asset list;
13  * the version lines of the pages listed in LINES below.
14Release notes, measurement logs and history/ keep the versions they were written with; tools/doc_pages.py says which
15pages are archived.  To bump a release: change the version sources, edit docs/data/release.json, run --write, run --check.
16"""
17import argparse
18import json
19import os
20import re
21import sys
22
23sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
24import doc_pages  # noqa: E402
25
26ROOT = doc_pages.ROOT
27MANIFEST = os.path.join(ROOT, "docs", "data", "release.json")
28
29INSTALLER_NAMES = ("Strata-{v}-windows-x64-setup.exe", "Strata-{v}-linux-x86_64.AppImage", "Strata-{v}-macos-arm64.dmg")
30# Any installer-looking file name in a current page.  Group 1 is the version.
31INSTALLER_RE = re.compile(r"Strata-(\d+\.\d+(?:\.\d+)*)-(?:windows-x64-setup\.exe|linux-x86_64\.AppImage|macos-arm64\.dmg)")
32
33V = r"(\d+\.\d+(?:\.\d+)*)"
34# (page, regex, manifest keys): the regex has one group per key, each holding a version.  A rule that matches nothing is
35# an error, so rewording a line cannot quietly switch its check off.
36LINES = [
37    ("docs/README.md", r"This documentation is for version " + V + r"\.", ["product_version"]),
38    ("docs/INSTALL.md", r"\(version " + V + r"\)", ["product_version"]),
39    ("docs/AI_SETUP.md", r"install Strata \(version " + V + r"\)", ["product_version"]),
40    ("docs/SOURCE_INSTALL.md", r"use Strata \(version " + V + r"\)", ["product_version"]),
41    ("AGENTS.md", r"^Version " + V + r", engine " + V + r"\.", ["product_version", "engine_version"]),
42    ("docs/AI_REFERENCE.md", r"against the " + V + r" release tree \(app and Terminal " + V + r"; Control " + V + r", engines " + V + r"\)",
43     ["product_version", "product_version", "control_version", "engine_version"]),
44    ("packaging/UPDATES.md", r"one per OS \(" + V + r"\)", ["product_version"]),
45    ("packaging/UPDATES.md", r'"app": \{[^\n]*\n\s*"version": "' + V + '"', ["product_version"]),
46    ("packaging/UPDATES.md", r"--target [a-z0-9_-]+ +--version " + V, ["product_version"]),
47    ("packaging/UPDATES.md", r'"control": \{"version": "' + V + '"', ["control_version"]),
48    ("packaging/UPDATES.md", r"pack-control <control folder> --version " + V, ["control_version"]),
49    ("packaging/UPDATES.md", r"VERSION file\s*\n\s*# \(" + V + r"\)", ["control_version"]),
50    ("packaging/UPDATES.md", r'"version": "' + V + r'", "platform": "linux-x86_64", "backend": "cuda"', ["engine_version"]),
51    ("packaging/UPDATES.md", r"engine/strata-engine-" + V + r"-linux-x86_64-cuda-cuda13", ["engine_version"]),
52    ("docs/MEDIA_KIT.md", r"for Strata " + V + r"\.", ["product_version"]),
53    ("packaging/README.md", r"\(app and Terminal " + V + r", Control " + V + r", engines " + V + r"\)", ["product_version", "control_version", "engine_version"]),
54    ("packaging/ENGINE-COMPONENT.md", r'"name": "strata-engine", "version": "' + V + '"', ["engine_version"]),
55    ("packaging/ENGINE-COMPONENT.md", r"package_engine.py --src <build folder> --backend cuda --version " + V, ["engine_version"]),
56]
57
58
59def load():
60    with open(MANIFEST, encoding="utf-8") as f:
61        return json.load(f)
62
63
64def read(rel_path):
65    with open(os.path.join(ROOT, rel_path), encoding="utf-8", newline="") as f:
66        return f.read()
67
68
69def first(rel_path, pattern):
70    m = re.search(pattern, read(rel_path), re.M)
71    return m.group(1) if m else None
72
73
74def code_versions():
75    """Where the versions come from in the source tree: name -> (value found, manifest key)."""
76    cmake = first("CMakeLists.txt", r"^project\(strata VERSION ([0-9.]+) ")
77    return {
78        # the Terminal says the product version, or (a Control-only hotfix such as 0.2.13.1) the manifest's optional terminal_version
79        "strata_cli/__init__.py": (first("strata_cli/__init__.py", r'^PRODUCT_VERSION = "([^"]+)"'), "terminal_version"),
80        "apps/host/package.json": (json.loads(read("apps/host/package.json")).get("version"), "product_version"),
81        "apps/desktop/package.json": (json.loads(read("apps/desktop/package.json")).get("version"), "product_version"),
82        "apps/desktop/src-tauri/Cargo.toml": (first("apps/desktop/src-tauri/Cargo.toml", r'^version = "([^"]+)"'), "product_version"),
83        "CMakeLists.txt (engine)": (cmake, "engine_version"),
84        "CMakeLists.txt (Control)": (cmake, "control_version"),
85    }
86
87
88def expand(manifest):
89    return [n.format(v=manifest["product_version"]) for n in INSTALLER_NAMES]
90
91
92def rewrite(text, regex, keys, manifest):
93    """Replace each version group of every match of `regex` with the manifest's value."""
94    def sub(m):
95        out, last = [], m.start()
96        for i, key in enumerate(keys, 1):
97            out.append(text[last:m.start(i)])
98            out.append(manifest[key])
99            last = m.end(i)
100        out.append(text[last:m.end()])
101        return "".join(out)
102
103    return re.sub(regex, sub, text, flags=re.M)
104
105
106def write(manifest):
107    changed = []
108    for rel_path in doc_pages.current_pages():
109        text = read(rel_path)
110        new = INSTALLER_RE.sub(lambda m: m.group(0).replace(m.group(1), manifest["product_version"], 1), text)
111        for page, regex, keys in LINES:
112            if page == rel_path:
113                new = rewrite(new, regex, keys, manifest)
114        if new != text:
115            with open(os.path.join(ROOT, rel_path), "w", encoding="utf-8", newline="") as f:
116                f.write(new)
117            changed.append(rel_path)
118    return changed
119
120
121def _vkey(version):
122    return tuple(int(p) for p in str(version).split("."))
123
124
125def check(manifest):
126    problems = []
127    for key in ("tag", "product_version", "control_version", "engine_version", "assets"):
128        if key not in manifest:
129            problems.append("docs/data/release.json has no %r" % key)
130    if problems:
131        return problems
132    if manifest["tag"] != "v" + manifest["product_version"]:
133        problems.append("tag %s does not match product_version %s" % (manifest["tag"], manifest["product_version"]))
134    for where, (found, key) in code_versions().items():
135        want = manifest.get(key, manifest["product_version"]) if key == "terminal_version" else manifest[key]
136        if where == "CMakeLists.txt (engine)":
137            # the CMake project version is Control's. The engine packages carry it, except after a Control-only hotfix (Control 0.1.59.1,
138            # engines still 0.1.59): then Control is the engine version plus one hotfix part.
139            # A release that builds no engine (0.2.15: Control 0.1.61, the 0.1.60 engines of v0.2.14 carried by absolute url) names the release
140            # it takes them from in "engines_from"; then Control may be ahead of the engines, and the engine packages at engine_version must be
141            # in the asset list (the packages the feed offers).
142            carried = bool(manifest.get("engines_from")) and manifest["engines_from"] != manifest["tag"] \
143                and _vkey(manifest["control_version"]) > _vkey(want) \
144                and any(a.startswith("strata-engine-%s-" % want) for a in manifest["assets"])
145            if found != manifest["control_version"] or not (found == want or found.startswith(want + ".") or carried):
146                problems.append("%s says %s, docs/data/release.json %s is %s (control_version %s)" % (where, found, key, want, manifest["control_version"]))
147        elif found != want:
148            problems.append("%s says %s, docs/data/release.json %s is %s" % (where, found, key, want))
149    assets = set(manifest["assets"])
150    for name in expand(manifest):
151        if name not in assets:
152            problems.append("docs/data/release.json: the asset list has no %s" % name)
153    for rel_path in doc_pages.current_pages():
154        text = read(rel_path)
155        for m in INSTALLER_RE.finditer(text):
156            line = text.count("\n", 0, m.start()) + 1
157            if m.group(1) != manifest["product_version"]:
158                problems.append("%s:%d names %s, the release is %s" % (rel_path, line, m.group(0), manifest["product_version"]))
159            else:
160                tail = re.match(r"[A-Za-z0-9_.-]*", text[m.start():]).group(0).rstrip(".")
161                if tail not in assets:
162                    problems.append("%s:%d names %s, which is not in the release's asset list" % (rel_path, line, tail))
163    for page, regex, keys in LINES:
164        text = read(page)
165        matches = list(re.finditer(regex, text, re.M))
166        if not matches:
167            problems.append("%s: the version-line rule /%s/ matches nothing (line reworded? update LINES in tools/release_manifest.py)" % (page, regex[:50]))
168        for m in matches:
169            line = text.count("\n", 0, m.start()) + 1
170            for i, key in enumerate(keys, 1):
171                if m.group(i) != manifest[key]:
172                    problems.append("%s:%d says %s, the release's %s is %s" % (page, line, m.group(i), key, manifest[key]))
173    return problems
174
175
176def main(argv=None):
177    ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
178    g = ap.add_mutually_exclusive_group(required=True)
179    g.add_argument("--check", action="store_true")
180    g.add_argument("--write", action="store_true")
181    args = ap.parse_args(argv)
182    manifest = load()
183    if args.write:
184        changed = write(manifest)
185        print("updated %d page(s)%s" % (len(changed), "".join("\n  " + c for c in changed)))
186    problems = check(manifest)
187    for p in problems:
188        print("FAIL " + p)
189    print("release manifest: %s" % ("%d problem(s)" % len(problems) if problems else "ok (%s, engine %s)" % (manifest["product_version"], manifest["engine_version"])))
190    return 1 if problems else 0
191
192
193if __name__ == "__main__":
194    sys.exit(main())