The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(release): claim a version and dispatch the gate from one command
ethernet7e63cd3a7178
diff --git a/scripts/release.py b/scripts/release.pyindex 09bda2796d7..9f9385ccfd5 100755--- a/scripts/release.py+++ b/scripts/release.py@@ -2961,11 +2961,24 @@ def main():help="Write changelog to file instead of stdout")parser.add_argument("--no-changelog", action="store_true",help="Skip changelog")+ subcommands = parser.add_subparsers(dest="command")+ release_cmd = subcommands.add_parser(+ "release", help="Claim a version, cut a draft, and dispatch the gate")+ release_cmd.add_argument("--commit", required=True, metavar="SHA",+ help="The main commit to release")+ release_cmd.add_argument("--bump", required=True, choices=["major", "minor", "patch"])+ release_cmd.add_argument("--autopublish", action="store_true",+ help="Publish on green instead of leaving a draft")+ release_cmd.add_argument("--remote", type=str)from scripts.releases.channel_build import add_arguments, validate_arguments, cmd_channeladd_arguments(parser)args = parser.parse_args()+ if args.command == "release":+ from scripts.releases.entrypoint import cmd_release+ cmd_release(args)+ returnif validate_arguments(parser, args):cmd_channel(args)returndiff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.pynew file mode 100644index 00000000000..2e852e77aae--- /dev/null+++ b/scripts/releases/entrypoint.py@@ -0,0 +1,114 @@+"""The thin release entrypoint: claim a version, cut the draft, dispatch the gate.++Nothing here builds. The claim is an annotated ``-rc`` tag pushed as exactly+that ref, and a dispatch that never starts is an error — the claim stays,+because a burned version is never retried under the same number.+"""+from __future__ import annotations++import subprocess+from pathlib import Path++from scripts.releases.versioning import derive_next_version++WORKFLOW = "stable-release.yml"+++class ReleaseRefused(RuntimeError):+ """The release cannot proceed, and nothing was silently skipped."""+++def _git(repo: Path, *args: str) -> str:+ return subprocess.check_output(["git", *args], cwd=repo, text=True, encoding="utf-8").strip()+++def _claims(repo: Path) -> list[str]:+ listed = _git(repo, "tag", "--list", "v*-rc")+ return [tag for tag in listed.splitlines() if tag]+++def _claim_commit(repo: Path, tag: str) -> str:+ return _git(repo, "rev-parse", f"{tag}^{{commit}}")+++def _highest_claim(repo: Path) -> tuple[str, str] | None:+ """The highest-version outstanding claim, as (version, commit)."""+ from scripts.releases.versioning import version_from_tag++ best: tuple[list[int], str, str] | None = None+ for tag in _claims(repo):+ version = version_from_tag(tag[:-3]) if tag.endswith("-rc") else None+ if version is None:+ continue+ key = [int(part) for part in version.split(".")]+ if best is None or key > best[0]:+ best = (key, version, _claim_commit(repo, tag))+ return None if best is None else (best[1], best[2])+++def _require_ancestry(repo: Path, commit: str) -> None:+ """A claim's commit must descend from the highest outstanding claim's."""+ highest = _highest_claim(repo)+ if highest is None:+ return+ version, claimed = highest+ if commit == claimed:+ return+ ancestor = subprocess.run(+ ["git", "merge-base", "--is-ancestor", claimed, commit], cwd=repo, capture_output=True)+ if ancestor.returncode != 0:+ raise ReleaseRefused(+ f"{version} already claimed at {claimed} — publish or abandon it first")+++def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,+ dispatch, autopublish: bool = False) -> dict:+ """Claim the derived version, cut its draft, and start the gate."""+ _require_ancestry(repo, commit)+ version = derive_next_version(published=None, claims=_claims(repo), bump=bump)+ tag = f"v{version}-rc"+ _git(repo, "tag", "-a", tag, commit, "-m", f"claim v{version}")+ _git(repo, "push", remote, f"refs/tags/{tag}")+ url = f"https://github.com/{repository}/releases/tag/{tag}"+ try:+ dispatch(["gh", "workflow", "run", WORKFLOW, "--ref", tag, "--repo", repository])+ except Exception as exc:+ raise ReleaseRefused(f"release {tag} never started: {exc}") from exc+ return {"version": version, "tag": tag, "commit": commit, "url": url,+ "autopublish": autopublish}+++def publish(version: str, *, repo: Path, repository: str, green, edit) -> dict:+ """Flip a green waiting draft. The flip is the publish; nothing rebuilds."""+ tag = f"v{version}"+ if not green(tag):+ raise ReleaseRefused(f"{version} is not green — refusing to publish")+ edit(["gh", "release", "edit", tag, "--repo", repository, "--draft=false"])+ return {"flipped": tag}+++def abandon(version: str, *, repo: Path, repository: str, delete) -> dict:+ """Delete the draft. The claim tag stays, so the version is spent."""+ delete(["gh", "release", "delete", f"v{version}-rc", "--repo", repository, "--yes"])+ return {"burned": version}+++def cmd_release(args) -> None:+ """The ``release`` subcommand: claim, draft, dispatch."""+ from scripts import release as release_script++ repo = release_script.REPO_ROOT+ remote = release_script.resolve_push_remote(args.remote)+ repository = release_script.remote_github_repo(remote)+ if not repository:+ raise SystemExit(f"release: remote {remote!r} does not point at a GitHub repository")+ commit = _git(repo, "rev-parse", "--verify", f"{args.commit}^{{commit}}")++ def dispatch(command: list[str]) -> None:+ completed = subprocess.run(command, cwd=repo, capture_output=True, text=True, encoding="utf-8")+ if completed.returncode != 0:+ raise RuntimeError(completed.stderr.strip() or "workflow dispatch failed")++ result = release(commit, bump=args.bump, repo=repo, remote=remote, repository=repository,+ dispatch=dispatch, autopublish=args.autopublish)+ print(result["url"])diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.pynew file mode 100644index 00000000000..8ef87b0a3b6--- /dev/null+++ b/tests/scripts/test_release_entrypoint.py@@ -0,0 +1,100 @@+"""The release entrypoint claims a version, cuts a draft, and dispatches the gate.++The claim is the tag push, and it pushes exactly the claim ref. A release that+never starts is an error, not a warning the operator has to notice.+"""+import subprocess++import pytest+++def git(repo, *args):+ return subprocess.check_output(["git", *args], cwd=repo, text=True, encoding="utf-8").strip()+++def source(tmp_path):+ origin = tmp_path / "origin.git"+ repo = tmp_path / "source"+ origin.mkdir()+ repo.mkdir()+ git(origin, "init", "--bare", "--quiet")+ git(repo, "init", "--initial-branch=main", "--quiet")+ git(repo, "config", "user.name", "Test")+ git(repo, "config", "user.email", "[email protected]")+ (repo / "pyproject.toml").write_text('[project]\nname="fixture"\nversion="0.0.0"\n', encoding="utf-8")+ git(repo, "add", "pyproject.toml")+ git(repo, "commit", "--quiet", "-m", "Initial")+ git(repo, "remote", "add", "origin", str(origin))+ git(repo, "push", "--quiet", "-u", "origin", "main")+ return repo+++def _claim(repo, version, commit, actor="release-bot", when="2026-09-22T00:14:00Z"):+ git(repo, "tag", "-a", f"v{version}-rc", commit, "-m",+ f"claim v{version}\n\nactor: {actor}\nwhen: {when}")+ git(repo, "push", "--quiet", "origin", f"refs/tags/v{version}-rc")+++def test_release_claims_the_derived_version_and_dispatches(source):+ from scripts.releases.entrypoint import release++ commit = git(source, "rev-parse", "HEAD")+ calls = []+ result = release(commit, bump="patch", repo=source, remote="origin",+ repository="example/hermes-agent", dispatch=calls.append)++ assert result["version"] == "0.21.5"+ assert result["tag"] == "v0.21.5-rc"+ assert result["commit"] == commit+ assert result["url"] == "https://github.com/example/hermes-agent/releases/tag/v0.21.5-rc"+ assert git(source, "rev-parse", "v0.21.5-rc^{commit}") == commit+ assert calls == [["gh", "workflow", "run", "stable-release.yml",+ "--ref", "v0.21.5-rc", "--repo", "example/hermes-agent"]]+ # The claim push names the claim ref and nothing else.+ pushed = git(source, "ls-remote", "origin", "refs/tags/v0.21.5-rc")+ assert pushed.startswith(git(source, "rev-parse", "v0.21.5-rc"))+++def test_a_commit_behind_an_outstanding_claim_is_refused(source):+ from scripts.releases.entrypoint import ReleaseRefused, release++ earlier = git(source, "rev-parse", "HEAD")+ git(source, "commit", "--allow-empty", "--quiet", "-m", "later")+ git(source, "push", "--quiet", "origin", "main")+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))++ with pytest.raises(ReleaseRefused, match="0\\.21\\.5 already claimed"):+ release(earlier, bump="patch", repo=source, remote="origin",+ repository="example/hermes-agent", dispatch=lambda _cmd: pytest.fail("must not dispatch"))+ assert "v0.21.6-rc" not in git(source, "tag", "--list")+++def test_a_dispatch_that_never_starts_is_an_error(source):+ from scripts.releases.entrypoint import ReleaseRefused, release++ def refuse(_cmd):+ raise RuntimeError("workflow dispatch rejected")++ with pytest.raises(ReleaseRefused, match="never started"):+ release(git(source, "rev-parse", "HEAD"), bump="patch", repo=source, remote="origin",+ repository="example/hermes-agent", dispatch=refuse)+ # The claim stands: a failed start burns the version rather than retrying it.+ assert "v0.21.5-rc" in git(source, "tag", "--list")+++def test_publish_flips_a_green_draft_and_abandon_keeps_the_claim(source):+ from scripts.releases.entrypoint import abandon, publish++ commit = git(source, "rev-parse", "HEAD")+ _claim(source, "0.21.5", commit)+ calls = []+ published = publish("0.21.5", repo=source, repository="example/hermes-agent",+ green=lambda tag: tag == "v0.21.5", edit=calls.append)+ assert published["flipped"] == "v0.21.5"+ assert calls == [["gh", "release", "edit", "v0.21.5", "--repo", "example/hermes-agent", "--draft=false"]]++ abandoned = abandon("0.21.5", repo=source, repository="example/hermes-agent", delete=calls.append)+ assert abandoned["burned"] == "0.21.5"+ assert calls[-1] == ["gh", "release", "delete", "v0.21.5-rc", "--repo", "example/hermes-agent", "--yes"]+ assert "v0.21.5-rc" in git(source, "tag", "--list")