The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(release): stamp a build tree instead of committing a version bump
ethernet092be885a33c
diff --git a/scripts/releases/stamping.py b/scripts/releases/stamping.pynew file mode 100644index 00000000000..1ae6846af80--- /dev/null+++ b/scripts/releases/stamping.py@@ -0,0 +1,66 @@+"""Stamp a build tree with a release version. The checkout is never the target.++The regex shapes are the canonical ones ``scripts/release.py`` already uses to+keep every mirror in lockstep. This writer differs in one respect: it takes the+tree as an argument, so a build stamps a copy and the source tree stays at the+placeholder version.+"""+from __future__ import annotations++import re+from pathlib import Path+++def _rewrite(path: Path, pattern: str, replacement: str, *, count: int = 0, flags: int = 0) -> None:+ if not path.exists():+ return+ text = path.read_text(encoding="utf-8-sig")+ path.write_text(re.sub(pattern, replacement, text, count=count, flags=flags), encoding="utf-8")+++def stamp(tree: Path, version: str, release_date: str) -> list[Path]:+ """Rewrite every version mirror under ``tree``. Returns the paths written."""+ written: list[Path] = []++ def touch(path: Path) -> None:+ if path.exists():+ written.append(path)++ init = tree / "hermes_cli" / "__init__.py"+ _rewrite(init, r'__version__\s*=\s*"[^"]+"', f'__version__ = "{version}"')+ _rewrite(init, r'__release_date__\s*=\s*"[^"]+"', f'__release_date__ = "{release_date}"')+ touch(init)++ pyproject = tree / "pyproject.toml"+ _rewrite(pyproject, r'^version\s*=\s*"[^"]+"', f'version = "{version}"', count=1, flags=re.MULTILINE)+ touch(pyproject)++ desktop = tree / "apps" / "desktop" / "package.json"+ _rewrite(desktop, r'("version"\s*:\s*)"[^"]+"', rf'\g<1>"{version}"', count=1)+ touch(desktop)++ # The lockfile root version is the repo's own and stays put; only the+ # desktop workspace entry mirrors the release.+ lock = tree / "package-lock.json"+ _rewrite(lock, r'("apps/desktop"\s*:\s*\{\s*"name"\s*:\s*"[^"]+"\s*,\s*"version"\s*:\s*)"[^"]+"',+ rf'\g<1>"{version}"', count=1)+ touch(lock)++ uv_lock = tree / "uv.lock"+ _rewrite(uv_lock, r'(name = "hermes-agent"\nversion = )"[^"]+"', rf'\g<1>"{version}"', count=1)+ touch(uv_lock)++ installer = tree / "apps" / "bootstrap-installer"+ json_version = rf'\g<1>"{version}"'+ toml_version = f'version = "{version}"'+ for name, pattern, replacement, flags in (+ ("package.json", r'("version"\s*:\s*)"[^"]+"', json_version, 0),+ ("src-tauri/tauri.conf.json", r'("version"\s*:\s*)"[^"]+"', json_version, 0),+ ("src-tauri/Cargo.toml", r'^version\s*=\s*"[^"]+"', toml_version, re.MULTILINE),+ ("src-tauri/Cargo.lock", r'(name = "bootstrap-installer"\nversion = )"[^"]+"', json_version, 0),+ ):+ path = installer / name+ _rewrite(path, pattern, replacement, count=1, flags=flags)+ touch(path)++ return writtendiff --git a/tests/scripts/test_version_stamping.py b/tests/scripts/test_version_stamping.pynew file mode 100644index 00000000000..794a2b66efe--- /dev/null+++ b/tests/scripts/test_version_stamping.py@@ -0,0 +1,67 @@+"""Version stamping writes a build tree, never the checkout it was invoked from.++A release used to commit the bumped version back onto the branch. The version+now lives in the ref, so stamping is a build step: it rewrites a copy of the+tree and returns the paths it touched, and the caller's tree is unchanged.+"""+import json+from pathlib import Path++import pytest+++def _tree(root: Path) -> None:+ (root / "hermes_cli").mkdir()+ (root / "hermes_cli" / "__init__.py").write_text(+ '__version__ = "0.0.0"\n__release_date__ = "2026.1.1"\n', encoding="utf-8")+ (root / "pyproject.toml").write_text('version = "0.0.0"\n', encoding="utf-8")+ desktop = root / "apps" / "desktop"+ desktop.mkdir(parents=True)+ (desktop / "package.json").write_text('{"version": "0.0.0"}\n', encoding="utf-8")+ (root / "package-lock.json").write_text(+ '{"version": "0.0.0", "packages": {"apps/desktop": {"name": "hermes", "version": "0.0.0"}}}\n',+ encoding="utf-8")+ (root / "uv.lock").write_text(+ '[[package]]\nname = "hermes-agent"\nversion = "0.0.0"\n'+ '[[package]]\nname = "other"\nversion = "0.0.0"\n', encoding="utf-8")+ installer = root / "apps" / "bootstrap-installer" / "src-tauri"+ installer.mkdir(parents=True)+ (root / "apps" / "bootstrap-installer" / "package.json").write_text(+ '{"name": "x", "version": "0.0.0"}\n', encoding="utf-8")+ (installer / "tauri.conf.json").write_text(+ '{"productName": "Hermes", "version": "0.0.0"}\n', encoding="utf-8")+ (installer / "Cargo.toml").write_text('[package]\nversion = "0.0.0"\n', encoding="utf-8")+ (installer / "Cargo.lock").write_text(+ '[[package]]\nname = "bootstrap-installer"\nversion = "0.21.1"\n', encoding="utf-8")+++def test_stamping_writes_the_build_tree_and_leaves_the_source_tree(tmp_path):+ from scripts.releases.stamping import stamp++ source = tmp_path / "source"+ build = tmp_path / "build"+ source.mkdir()+ build.mkdir()+ _tree(source)+ _tree(build)+ before = (source / "pyproject.toml").read_text(encoding="utf-8")++ written = stamp(build, "0.21.5", "2026.9.22")++ assert (source / "pyproject.toml").read_text(encoding="utf-8") == before+ assert 'version = "0.21.5"' in (build / "pyproject.toml").read_text(encoding="utf-8")+ init = (build / "hermes_cli" / "__init__.py").read_text(encoding="utf-8")+ assert '__version__ = "0.21.5"' in init+ assert '__release_date__ = "2026.9.22"' in init+ assert json.loads((build / "apps" / "desktop" / "package.json").read_text())["version"] == "0.21.5"+ # The lockfile root stays; only the desktop workspace entry moves.+ lock = json.loads((build / "package-lock.json").read_text())+ assert lock["version"] == "0.0.0"+ assert lock["packages"]["apps/desktop"]["version"] == "0.21.5"+ # uv.lock records the root package once, and no other package moves with it.+ uv = (build / "uv.lock").read_text(encoding="utf-8")+ assert uv.count('version = "0.21.5"') == 1+ assert 'name = "hermes-agent"\nversion = "0.21.5"' in uv+ cargo_lock = (build / "apps" / "bootstrap-installer" / "src-tauri" / "Cargo.lock").read_text()+ assert 'version = "0.21.5"' in cargo_lock+ assert all(path.is_relative_to(build) for path in written)