Skip to content

The agent that grows with you

feat(release): abandon writes an immutable marker ref

ethernet949ec52a51fe
diff --git a/scripts/release.py b/scripts/release.py
index 51e7b1b743a..7528c11e48a 100755
--- a/scripts/release.py
+++ b/scripts/release.py
@@ -2743,7 +2743,7 @@ def main():
publish_cmd.add_argument("--version", required=True)
publish_cmd.add_argument("--remote", type=str)
abandon_cmd = subcommands.add_parser(
- "abandon", help="Delete a stable draft while retaining its spent claim")
+ "abandon", help="Clear the outstanding attempt, keeping its attempt ref and writing an abandon marker")
abandon_cmd.add_argument("--version", required=True)
abandon_cmd.add_argument("--remote", type=str)
from scripts.releases.channel_build import add_arguments, validate_arguments, cmd_channel
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.py
index 5003658eac8..9698cc332c1 100644
--- a/scripts/releases/entrypoint.py
+++ b/scripts/releases/entrypoint.py
@@ -15,7 +15,8 @@ import time
from pathlib import Path
from scripts.releases.versioning import (
- SEED, attempt_ref, derive_next_version, next_attempt, parse_attempt_ref, parse_marker_ref,
+ SEED, attempt_ref, derive_next_version, marker_ref, next_attempt, parse_attempt_ref,
+ parse_marker_ref,
)
WORKFLOW = "stable-release.yml"
@@ -282,17 +283,34 @@ def publish(version: str, *, repository: str, dispatch, inspect=None, head_versi
return {"requested": tag, "version": version, "repository": repository}
-def abandon(version: str, *, repo: Path, repository: str, delete, inspect=None) -> dict:
- """Delete the draft. The claim tag stays, so the version is spent."""
- tag = f"v{version}-rc"
+def abandon(version: str, *, repo: Path, remote: str, repository: str, delete, inspect=None) -> dict:
+ """Clear the outstanding attempt of ``version``. The attempt ref stays; the marker is the record.
+
+ The draft goes first: a cleared attempt with a live draft could still be
+ published by hand, while a draftless outstanding attempt is just abandoned
+ again. This reads every outstanding attempt, not the one-attempt view, so
+ it still clears one when a concurrent cut left two.
+ """
+ _refresh_claims(repo, remote)
+ matching = [found for found in _outstanding_attempts(repo, remote) if found[0] == version]
+ if len(matching) != 1:
+ raise ReleaseRefused(f"stable {version} has no outstanding attempt to abandon")
+ _version, attempt, tag = matching[0]
if inspect is not None:
- rows = [row for candidate in (f"v{version}", tag)
- if (row := _release_view(candidate, repository, inspect)) is not None]
- if len(rows) != 1 or rows[0].get("isDraft") is not True:
- raise ReleaseRefused(f"stable {version} has no single release draft to abandon")
- tag = rows[0]["tagName"]
- delete(["gh", "release", "delete", tag, "--repo", repository, "--yes"])
- return {"burned": version, "tag": tag, "repository": repository}
+ draft = _release_view(tag, repository, inspect)
+ if draft is not None:
+ if draft.get("isDraft") is not True:
+ raise ReleaseRefused(f"{tag} is published and cannot be abandoned")
+ delete(["gh", "release", "delete", tag, "--repo", repository, "--yes"])
+ marker = marker_ref(version, attempt)
+ message = json.dumps({"schema": 1, "version": version, "attempt": attempt, "attemptRef": tag},
+ sort_keys=True, separators=(",", ":"))
+ _git(repo, "tag", "-a", marker, f"{tag}^{{commit}}", "-m", message)
+ try:
+ _git(repo, "push", remote, f"refs/tags/{marker}")
+ except subprocess.CalledProcessError as error:
+ raise _claim_collision(repo, remote, marker, error) from error
+ return {"version": version, "tag": tag, "marker": marker, "repository": repository}
def next_steps(result: dict) -> str:
@@ -340,7 +358,7 @@ def cmd_release(args) -> None:
print(next_steps(result))
-def _command_repository(args) -> tuple[Path, str]:
+def _command_repository(args) -> tuple[Path, str, str]:
from scripts import release as release_script
repo = release_script.REPO_ROOT
@@ -348,7 +366,7 @@ def _command_repository(args) -> tuple[Path, str]:
repository = release_script.remote_github_repo(remote)
if not repository:
raise SystemExit(f"release: remote {remote!r} does not point at a GitHub repository")
- return repo, repository
+ return repo, remote, repository
def _execute(repo: Path, command: list[str]) -> None:
@@ -377,17 +395,17 @@ def publish_steps(result: dict) -> str:
def abandon_steps(result: dict) -> str:
- """Say that the draft is gone and the version cannot be reused."""
- version = result["burned"]
+ """Say which attempt is cleared and which attempt the next cut takes."""
+ version, tag = result["version"], result["tag"]
+ _version, attempt = parse_attempt_ref(tag)
return "\n".join([
- f"Deleted the draft for v{version}.",
- f"The claim tag {result['tag']} stays, so v{version} is spent.",
- "The next release takes the next version. This one cannot be reused.",
+ f"Cleared {tag}. The marker {result['marker']} records it.",
+ f"v{version} is not spent. The next cut is rc.{attempt + 1}-v{version}.",
])
def cmd_publish(args) -> None:
- repo, repository = _command_repository(args)
+ repo, _remote, repository = _command_repository(args)
from scripts.releases.versioning import published_stable_version
result = publish(args.version, repository=repository,
dispatch=lambda command: _execute(repo, command),
@@ -401,8 +419,8 @@ def cmd_publish(args) -> None:
def cmd_abandon(args) -> None:
- repo, repository = _command_repository(args)
- result = abandon(args.version, repo=repo, repository=repository,
+ repo, remote, repository = _command_repository(args)
+ result = abandon(args.version, repo=repo, remote=remote, repository=repository,
delete=lambda command: _execute(repo, command),
inspect=lambda command: _inspect(repo, command))
print(abandon_steps(result))
diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.py
index 3a37cb83711..da54ae315ca 100644
--- a/tests/scripts/test_release_entrypoint.py
+++ b/tests/scripts/test_release_entrypoint.py
@@ -269,17 +269,17 @@ def test_publish_and_abandon_output_name_the_result():
assert "Workflow: https://github.com/example/hermes-agent/actions/runs/9" in published
assert "moves the stable channel" in published
- abandoned = abandon_steps({"burned": "0.21.5", "tag": "v0.21.5-rc"})
- assert "Deleted the draft for v0.21.5." in abandoned
- assert "v0.21.5-rc" in abandoned
- assert "cannot be reused" in abandoned
+ abandoned = abandon_steps({"version": "0.21.5", "tag": "rc.1-v0.21.5",
+ "marker": "abandoned-rc.1-v0.21.5"})
+ assert "Cleared rc.1-v0.21.5." in abandoned
+ assert "abandoned-rc.1-v0.21.5" in abandoned
+ assert "The next cut is rc.2-v0.21.5." in abandoned
+ assert "cannot be reused" not in abandoned
-def test_publish_dispatches_the_sequencer_and_abandon_keeps_the_claim(source):
- from scripts.releases.entrypoint import ReleaseRefused, abandon, publish
+def test_publish_dispatches_the_sequencer():
+ from scripts.releases.entrypoint import ReleaseRefused, publish
- commit = git(source, "rev-parse", "HEAD")
- _claim(source, "0.21.5", commit)
calls = []
published = publish("0.21.5", repository="example/hermes-agent", dispatch=calls.append)
assert published["requested"] == "v0.21.5"
@@ -290,18 +290,6 @@ def test_publish_dispatches_the_sequencer_and_abandon_keeps_the_claim(source):
"--repo", "example/hermes-agent", "--raw-field", "version=0.21.5",
]]
- def inspect(command):
- if "v0.21.5" in command:
- return json.dumps({"tagName": "v0.21.5", "isDraft": True, "isPrerelease": False})
- raise ReleaseRefused("not found")
-
- abandoned = abandon("0.21.5", repo=source, repository="example/hermes-agent",
- delete=calls.append, inspect=inspect)
- assert abandoned["burned"] == "0.21.5"
- assert abandoned["tag"] == "v0.21.5"
- assert calls[-1] == ["gh", "release", "delete", "v0.21.5", "--repo", "example/hermes-agent", "--yes"]
- assert "rc.1-v0.21.5" in git(source, "tag", "--list")
-
with pytest.raises(ReleaseRefused, match="burned or superseded by 0\\.21\\.6"):
publish(
"0.21.5", repository="example/hermes-agent",
@@ -311,6 +299,80 @@ def test_publish_dispatches_the_sequencer_and_abandon_keeps_the_claim(source):
)
+def _abandon(repo, version, *, draft=None, calls=None):
+ from scripts.releases.entrypoint import ReleaseRefused, abandon
+
+ def inspect(command):
+ if draft is None or command[3] != draft["tagName"]:
+ raise ReleaseRefused("release not found")
+ return json.dumps(draft)
+
+ return abandon(version, repo=repo, remote="origin", repository="example/hermes-agent",
+ delete=(calls if calls is not None else []).append, inspect=inspect)
+
+
+def test_abandon_of_a_draft_deletes_it_writes_the_marker_and_frees_the_version(source):
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ calls = []
+
+ result = _abandon(source, "0.21.5", calls=calls,
+ draft={"tagName": "rc.1-v0.21.5", "isDraft": True, "isPrerelease": False})
+
+ assert result == {"version": "0.21.5", "tag": "rc.1-v0.21.5",
+ "marker": "abandoned-rc.1-v0.21.5", "repository": "example/hermes-agent"}
+ assert calls == [["gh", "release", "delete", "rc.1-v0.21.5", "--repo", "example/hermes-agent", "--yes"]]
+ remote = git(source, "ls-remote", "origin", "refs/tags/*")
+ assert "refs/tags/abandoned-rc.1-v0.21.5" in remote
+ assert "refs/tags/rc.1-v0.21.5" in remote
+ marker = json.loads(git(source, "tag", "-l", "abandoned-rc.1-v0.21.5", "--format=%(contents)"))
+ assert marker == {"attempt": 1, "attemptRef": "rc.1-v0.21.5", "schema": 1, "version": "0.21.5"}
+ assert git(source, "rev-parse", "abandoned-rc.1-v0.21.5^{commit}") == git(
+ source, "rev-parse", "rc.1-v0.21.5^{commit}")
+ assert _release(source, _advance(source, "fix"))["tag"] == "rc.2-v0.21.5"
+
+
+def test_abandon_of_a_draftless_burned_attempt_writes_the_marker(source):
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ calls = []
+
+ assert _abandon(source, "0.21.5", calls=calls)["marker"] == "abandoned-rc.1-v0.21.5"
+ assert calls == []
+
+
[email protected]("version", ["0.21.5", "0.22.0"])
+def test_abandon_refuses_without_an_outstanding_attempt_of_that_version(source, version):
+ from scripts.releases.entrypoint import ReleaseRefused
+
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ if version == "0.21.5":
+ _mark(source, "0.21.5")
+
+ with pytest.raises(ReleaseRefused, match="no outstanding attempt to abandon"):
+ _abandon(source, version)
+
+
+def test_abandon_refuses_a_release_that_was_published(source):
+ from scripts.releases.entrypoint import ReleaseRefused
+
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ with pytest.raises(ReleaseRefused, match="published and cannot be abandoned"):
+ _abandon(source, "0.21.5",
+ draft={"tagName": "rc.1-v0.21.5", "isDraft": False, "isPrerelease": False})
+ assert "abandoned-rc" not in git(source, "ls-remote", "origin", "refs/tags/*")
+
+
+def test_abandon_clears_one_of_two_attempts_a_concurrent_cut_left(source):
+ from scripts.releases.entrypoint import ReleaseRefused
+
+ commit = git(source, "rev-parse", "HEAD")
+ _claim(source, "0.21.5", commit)
+ _claim(source, "0.22.0", commit)
+
+ assert _abandon(source, "0.22.0")["marker"] == "abandoned-rc.1-v0.22.0"
+ with pytest.raises(ReleaseRefused, match="rc.1-v0.21.5 is outstanding"):
+ _release(source, _advance(source, "later"), execute=_must_not_execute)
+
+
def _clones(source, tmp_path):
origin = git(source, "remote", "get-url", "origin")
clones = []