Skip to content

The agent that grows with you

fix(release): build stable draft notes from commits, not generate-notes

ethernetc0bd183eef71
diff --git a/scripts/release.py b/scripts/release.py
index 8cd5231623e..b90b08436ae 100755
--- a/scripts/release.py
+++ b/scripts/release.py
@@ -2337,12 +2337,12 @@ def parse_coauthors(body: str) -> list:
return results
-def get_commits(since_tag=None):
- """Get commits since a tag (or all commits if None)."""
+def get_commits(since_tag=None, until="HEAD", cwd=None):
+ """Get commits in ``since_tag..until`` (or all of ``until`` if since_tag is None)."""
if since_tag:
- range_spec = f"{since_tag}..HEAD"
+ range_spec = f"{since_tag}..{until}"
else:
- range_spec = "HEAD"
+ range_spec = until
# Format: hash<US>author_name<US>author_email<US>subject\0body
# Using %x1f (unit separator) to avoid conflict with | in author names
@@ -2350,6 +2350,7 @@ def get_commits(since_tag=None):
"log", range_spec,
"--format=%H%x1f%an%x1f%ae%x1f%s%x00%b%x00",
"--no-merges",
+ cwd=cwd,
)
if not log:
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.py
index bbcc9ec539f..595608ec6fe 100644
--- a/scripts/releases/entrypoint.py
+++ b/scripts/releases/entrypoint.py
@@ -150,6 +150,29 @@ def _next_claim_epoch(repo: Path) -> int:
return max(int(time.time()), max(previous, default=0) + 1)
+def _changelog(repo: Path, repository: str, *, commit: str, tag: str, version: str,
+ published: tuple[str, str | None]) -> str:
+ """The commit changelog from the stable base to the cut commit.
+
+ GitHub's generate-notes lists merged pull requests since the last published
+ release, so it is empty on a repository that merges none (a fork).
+ """
+ from scripts import release as release_script
+
+ published_version, base = published
+ receipt = f"v{published_version}"
+ if base is None and subprocess.run(
+ ["git", "rev-parse", "--verify", "--quiet", f"refs/tags/{receipt}^{{commit}}"],
+ cwd=repo, capture_output=True).returncode == 0:
+ # Before the first publication the seed version's tag is the base.
+ base = receipt
+ commits = release_script.get_commits(since_tag=base, until=commit, cwd=repo)
+ return release_script.generate_changelog(
+ commits, tag, version, repo_url=f"https://github.com/{repository}",
+ prev_tag=receipt if base else None,
+ )
+
+
def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,
execute, autopublish: bool = False,
published: tuple[str, str | None] = (SEED, None)) -> dict:
@@ -199,12 +222,10 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,
_refresh_claims(repo, remote)
_outstanding_attempt(repo, remote)
try:
- 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.
+ notes = _changelog(repo, repository, commit=commit, tag=tag, version=version,
+ published=published)
+ # The body carries a warning at both ends, so it is built here and
+ # handed over as a file.
file = tempfile.NamedTemporaryFile(
"w", suffix=".md", delete=False, encoding="utf-8", newline="\n")
try:
diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.py
index 24c55ddea5a..e364227051c 100644
--- a/tests/scripts/test_release_entrypoint.py
+++ b/tests/scripts/test_release_entrypoint.py
@@ -107,15 +107,13 @@ def test_release_claims_the_first_attempt_creates_a_draft_and_dispatches(source)
"schema": 1,
"version": "0.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]
+ create = calls[0]
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:] == [
+ assert calls[1:] == [
["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",
@@ -274,15 +272,18 @@ def test_draft_body_is_fenced_at_top_and_bottom():
assert "rc.2-v0.21.5" in body
-def test_release_fetches_generated_notes_and_creates_the_fenced_draft(source):
[email protected]("published_by", ["identity", "seed_tag"])
+def test_release_draft_lists_the_commits_since_the_stable_base(source, published_by):
from scripts.releases.draft_warning import WARNING_CLOSE, WARNING_OPEN
- commit = git(source, "rev-parse", "HEAD")
+ shipped = _advance(source, "fix: shipped in the published release")
+ git(source, "tag", "-a", "v0.21.4", shipped, "-m", "published")
+ commit = _advance(source, "feat: new in this release (#123)")
+ published = ("0.21.4", shipped) if published_by == "identity" else ("0.21.4", None)
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"})
+ assert command[:3] != ["gh", "api", "repos/example/hermes-agent/releases/generate-notes"]
if command[:3] == ["gh", "release", "create"]:
notes_path = command[command.index("--notes-file") + 1]
with open(notes_path, encoding="utf-8") as file:
@@ -292,14 +293,19 @@ def test_release_fetches_generated_notes_and_creates_the_fenced_draft(source):
"headBranch": "rc.1-v0.21.5", "status": "queued"}])
return ""
- result = _release(source, commit, execute=execute)
+ result = _release(source, commit, execute=execute, published=published)
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
+ # The notes are this repository's commits from the stable base to the cut
+ # commit, not GitHub's merged-PR list, which a fork leaves empty.
+ assert "New in this release" in body
+ assert "https://github.com/example/hermes-agent/pull/123" in body
+ assert "hipped in the published release" not in body
+ assert "compare/v0.21.4...rc.1-v0.21.5" in body
+ # The stable workflow renders the download tables into this marker.
+ assert "<!-- HERMES_BUILDS_TABLE -->" 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