The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(release): warn in the draft body against publishing it by hand
ethernetfcd1fdd57b73
diff --git a/scripts/releases/draft_warning.py b/scripts/releases/draft_warning.pyindex 3abd99a2b96..a41daff6610 100644--- a/scripts/releases/draft_warning.py+++ b/scripts/releases/draft_warning.py@@ -23,8 +23,9 @@ _WARNING = """> [!CAUTION]def draft_body(*, version: str, attempt_ref: str, notes: str) -> str:- """The draft body: warning block, generated notes, warning block."""- block = _WARNING.format(version=version, attempt_ref=attempt_ref)+ """The draft body: fenced warning block, generated notes, fenced warning block."""+ block = "\n".join([WARNING_OPEN, _WARNING.format(version=version, attempt_ref=attempt_ref),+ WARNING_CLOSE])return "\n".join([block, notes, block])diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.pyindex 00bcdd44038..c2b8e297427 100644--- a/scripts/releases/entrypoint.py+++ b/scripts/releases/entrypoint.py@@ -11,9 +11,11 @@ import jsonimport osimport subprocessimport sys+import tempfileimport timefrom pathlib import Path+from scripts.releases.draft_warning import draft_bodyfrom scripts.releases.versioning import (SEED, attempt_ref, derive_next_version, marker_ref, next_attempt,outstanding_attempts, parse_attempt_ref, parse_marker_ref,@@ -198,10 +200,26 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,_outstanding_attempt(repo, remote)url = f"https://github.com/{repository}/releases/tag/{tag}"try:- execute([- "gh", "release", "create", tag, "--repo", repository,- "--verify-tag", "--draft", "--generate-notes", "--title", f"Hermes Agent v{version}",- ])+ notes = json.loads(execute([+ "gh", "api", f"repos/{repository}/releases/generate-notes",+ "-f", f"tag_name={tag}",+ ]) or "{}").get("body") or ""+ # --generate-notes cannot place a warning below the notes, so the body+ # is built here and handed over as a file.+ file = tempfile.NamedTemporaryFile(+ "w", suffix=".md", delete=False, encoding="utf-8", newline="\n")+ try:+ file.write(draft_body(version=version, attempt_ref=tag, notes=notes))+ finally:+ file.close()+ try:+ execute([+ "gh", "release", "create", tag, "--repo", repository,+ "--verify-tag", "--draft", "--notes-file", file.name,+ "--title", f"Hermes Agent v{version}",+ ])+ finally:+ os.unlink(file.name)execute(["gh", "workflow", "run", WORKFLOW, "--ref", tag, "--repo", repository,"--raw-field", f"tag={tag}",diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.pyindex f9eef172a06..43224264dd2 100644--- a/tests/scripts/test_release_entrypoint.py+++ b/tests/scripts/test_release_entrypoint.py@@ -104,9 +104,15 @@ def test_release_claims_the_first_attempt_creates_a_draft_and_dispatches(source)"schema": 1,"version": "0.21.5",}- assert calls == [- ["gh", "release", "create", "rc.1-v0.21.5", "--repo", "example/hermes-agent",- "--verify-tag", "--draft", "--generate-notes", "--title", "Hermes Agent v0.21.5"],+ assert calls[0] == ["gh", "api", "repos/example/hermes-agent/releases/generate-notes",+ "-f", "tag_name=rc.1-v0.21.5"]+ create = calls[1]+ assert create[:4] == ["gh", "release", "create", "rc.1-v0.21.5"]+ assert "--verify-tag" in create and "--draft" in create+ assert "--generate-notes" not in create+ assert "--notes-file" in create+ assert create[-2:] == ["--title", "Hermes Agent v0.21.5"]+ assert calls[2:] == [["gh", "workflow", "run", "stable-release.yml", "--ref", "rc.1-v0.21.5","--repo", "example/hermes-agent", "--raw-field", "tag=rc.1-v0.21.5"],["gh", "run", "list", "--repo", "example/hermes-agent", "--workflow", "stable-release.yml",@@ -247,6 +253,52 @@ def test_successive_attempts_reserve_increasing_native_epochs(source):assert second_epoch > first_epoch+def test_draft_body_is_fenced_at_top_and_bottom():+ from scripts.releases.draft_warning import (+ WARNING_CLOSE, WARNING_OPEN, draft_body,+ )++ body = draft_body(version="0.21.5", attempt_ref="rc.2-v0.21.5",+ notes="## What's changed\n- x")+ assert body.startswith(WARNING_OPEN) and body.rstrip().endswith(WARNING_CLOSE)+ assert body.count(WARNING_OPEN) == 2 and body.count(WARNING_CLOSE) == 2+ assert "python scripts/release.py publish --version 0.21.5" in body+ assert "python scripts/release.py abandon --version 0.21.5" in body+ assert "## What's changed\n- x" in body+ # The warning names the attempt and the version it would burn.+ assert "rc.2-v0.21.5" in body+++def test_release_fetches_generated_notes_and_creates_the_fenced_draft(source):+ from scripts.releases.draft_warning import WARNING_CLOSE, WARNING_OPEN++ commit = git(source, "rev-parse", "HEAD")+ seen = {}++ def execute(command):+ if command[1:3] == ["api", "repos/example/hermes-agent/releases/generate-notes"]:+ return json.dumps({"body": "## What's changed\n- x", "name": "release"})+ if command[:3] == ["gh", "release", "create"]:+ notes_path = command[command.index("--notes-file") + 1]+ with open(notes_path, encoding="utf-8") as file:+ seen["body"] = file.read()+ if command[:3] == ["gh", "run", "list"]:+ return json.dumps([{"databaseId": 7, "url": "https://github.com/example/hermes-agent/actions/runs/7",+ "headBranch": "rc.1-v0.21.5", "status": "queued"}])+ return ""++ result = _release(source, commit, execute=execute)++ assert result["tag"] == "rc.1-v0.21.5"+ # The notes are fetched from GitHub and the draft is created from a file,+ # because --generate-notes cannot place a warning below the notes.+ body = seen["body"]+ assert body.startswith(WARNING_OPEN) and body.rstrip().endswith(WARNING_CLOSE)+ assert "## What's changed\n- x" in body+ assert "python scripts/release.py publish --version 0.21.5" in body+ assert "python scripts/release.py abandon --version 0.21.5" in body++def test_a_dispatch_that_never_starts_is_an_error(source):from scripts.releases.entrypoint import ReleaseRefused