okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e39a52e33
main
1#!/usr/bin/env python3 2"""The release the current docs describe, kept in one place: docs/data/release.json 3 4python tools/release_manifest.py --check fail when a current page or a version source disagrees 5python 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 9files, 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) 12in 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 (): 60with open (MANIFEST ,encoding = "utf-8" )as f : 61return json .load (f ) 62 63 64def read (rel_path ): 65with open (os .path .join (ROOT ,rel_path ),encoding = "utf-8" ,newline = "" )as f : 66return f .read () 67 68 69def first (rel_path ,pattern ): 70m = re .search (pattern ,read (rel_path ),re .M ) 71return 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).""" 76cmake = first ("CMakeLists.txt" ,r"^project\(strata VERSION ([0-9.]+) " ) 77return { 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 ): 89return [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.""" 94def sub (m ): 95out ,last = [],m .start () 96for i ,key in enumerate (keys ,1 ): 97out .append (text [last :m .start (i )]) 98out .append (manifest [key ]) 99last = m .end (i ) 100out .append (text [last :m .end ()]) 101return "" .join (out ) 102 103return re .sub (regex ,sub ,text ,flags = re .M ) 104 105 106def write (manifest ): 107changed = [] 108for rel_path in doc_pages .current_pages (): 109text = read (rel_path ) 110new = INSTALLER_RE .sub (lambda m :m .group (0 ).replace (m .group (1 ),manifest ["product_version" ],1 ),text ) 111for page ,regex ,keys in LINES : 112if page == rel_path : 113new = rewrite (new ,regex ,keys ,manifest ) 114if new != text : 115with open (os .path .join (ROOT ,rel_path ),"w" ,encoding = "utf-8" ,newline = "" )as f : 116f .write (new ) 117changed .append (rel_path ) 118return changed 119 120 121def _vkey (version ): 122return tuple (int (p )for p in str (version ).split ("." )) 123 124 125def check (manifest ): 126problems = [] 127for key in ("tag" ,"product_version" ,"control_version" ,"engine_version" ,"assets" ): 128if key not in manifest : 129problems .append ("docs/data/release.json has no %r" % key ) 130if problems : 131return problems 132if manifest ["tag" ]!= "v" + manifest ["product_version" ]: 133problems .append ("tag %s does not match product_version %s" % (manifest ["tag" ],manifest ["product_version" ])) 134for where , (found ,key )in code_versions ().items (): 135want = manifest .get (key ,manifest ["product_version" ])if key == "terminal_version" else manifest [key ] 136if 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). 142carried = bool (manifest .get ("engines_from" ))and manifest ["engines_from" ]!= manifest ["tag" ] \ 143and _vkey (manifest ["control_version" ])> _vkey (want ) \ 144and any (a .startswith ("strata-engine-%s-" % want )for a in manifest ["assets" ]) 145if found != manifest ["control_version" ]or not (found == want or found .startswith (want + "." )or carried ): 146problems .append ("%s says %s, docs/data/release.json %s is %s (control_version %s)" % (where ,found ,key ,want ,manifest ["control_version" ])) 147elif found != want : 148problems .append ("%s says %s, docs/data/release.json %s is %s" % (where ,found ,key ,want )) 149assets = set (manifest ["assets" ]) 150for name in expand (manifest ): 151if name not in assets : 152problems .append ("docs/data/release.json: the asset list has no %s" % name ) 153for rel_path in doc_pages .current_pages (): 154text = read (rel_path ) 155for m in INSTALLER_RE .finditer (text ): 156line = text .count ("\n" ,0 ,m .start ())+ 1 157if m .group (1 )!= manifest ["product_version" ]: 158problems .append ("%s:%d names %s, the release is %s" % (rel_path ,line ,m .group (0 ),manifest ["product_version" ])) 159else : 160tail = re .match (r"[A-Za-z0-9_.-]*" ,text [m .start ():]).group (0 ).rstrip ("." ) 161if tail not in assets : 162problems .append ("%s:%d names %s, which is not in the release's asset list" % (rel_path ,line ,tail )) 163for page ,regex ,keys in LINES : 164text = read (page ) 165matches = list (re .finditer (regex ,text ,re .M )) 166if not matches : 167problems .append ("%s: the version-line rule /%s/ matches nothing (line reworded? update LINES in tools/release_manifest.py)" % (page ,regex [:50 ])) 168for m in matches : 169line = text .count ("\n" ,0 ,m .start ())+ 1 170for i ,key in enumerate (keys ,1 ): 171if m .group (i )!= manifest [key ]: 172problems .append ("%s:%d says %s, the release's %s is %s" % (page ,line ,m .group (i ),key ,manifest [key ])) 173return problems 174 175 176def main (argv = None ): 177ap = argparse .ArgumentParser (description = __doc__ .split ("\n" )[0 ]) 178g = ap .add_mutually_exclusive_group (required = True ) 179g .add_argument ("--check" ,action = "store_true" ) 180g .add_argument ("--write" ,action = "store_true" ) 181args = ap .parse_args (argv ) 182manifest = load () 183if args .write : 184changed = write (manifest ) 185"updated %d page(s)%s" % (len (changed ),"" .join ("\n " + c for c in changed ))) 186problems = check (manifest ) 187for p in problems : 188"FAIL " + p ) 189"release manifest: %s" % ("%d problem(s)" % len (problems )if problems else "ok (%s, engine %s)" % (manifest ["product_version" ],manifest ["engine_version" ]))) 190return 1 if problems else 0 191 192 193if __name__ == "__main__" : 194sys .exit (main ())