Skip to content

The agent that grows with you

feat(release): offer to abandon a blocking attempt from an interactive terminal

ethernet74d788fcc908
diff --git a/scripts/releases/entrypoint.py b/scripts/releases/entrypoint.py
index 590cbee8308..49e4dea8440 100644
--- a/scripts/releases/entrypoint.py
+++ b/scripts/releases/entrypoint.py
@@ -13,6 +13,7 @@ import subprocess
import sys
import tempfile
import time
+from collections.abc import Callable
from pathlib import Path
from scripts.releases import optional_platforms
@@ -197,7 +198,8 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,
skip_bundles: bool = False, skip_tests: bool = False,
include_macos_intel: bool = False, include_termux: bool = False,
published: tuple[str, str | None] = (SEED, None),
- run_wait: float = 0, sleep=time.sleep) -> dict:
+ run_wait: float = 0, sleep=time.sleep,
+ confirm_abandon: Callable[[str], bool] | None = None, inspect=None) -> dict:
"""Claim the next attempt of the derived version, cut its draft, and start the gate.
``published`` is the stable channel's ``(version, commit)``; the commit is
@@ -207,13 +209,21 @@ def release(commit: str, *, bump: str, repo: Path, remote: str, repository: str,
not built unless their include flag is set.
``run_wait`` is how many seconds to keep looking for the dispatched run;
GitHub lists it a moment after the dispatch returns.
+ ``confirm_abandon`` is asked about an outstanding attempt's ref; only a
+ caller with a person at the terminal passes one. A yes abandons the attempt
+ through ``abandon`` (so it needs ``inspect``, which cancels runs and deletes
+ the draft) and the cut goes on; no confirmer, or a no, is the refusal.
"""
_refresh_claims(repo, remote)
_require_remote_main(repo, commit)
outstanding = _outstanding_attempt(repo, remote)
if outstanding is not None:
- raise _refuse_outstanding(outstanding, repo=repo, remote=remote,
- repository=repository, execute=execute)
+ refusal = _refuse_outstanding(outstanding, repo=repo, remote=remote,
+ repository=repository, execute=execute)
+ if confirm_abandon is None or not confirm_abandon(outstanding[2]):
+ raise refusal
+ print(abandon_steps(abandon(outstanding[0], repo=repo, remote=remote, repository=repository,
+ execute=execute, inspect=inspect)), file=sys.stderr)
published_version, published_commit = published
_require_ancestry(repo, commit, published_commit)
version = derive_next_version(published=published_version, bump=bump)
@@ -497,6 +507,25 @@ def next_steps(result: dict, *, bold: bool = False) -> str:
return "\n".join(lines)
+def _abandon_prompt() -> Callable[[str], bool] | None:
+ """A y/N prompt, N by default, when a person can answer it; None otherwise.
+
+ ``input`` writes its prompt to stdout when either stream is redirected, so
+ both must be terminals for the question to reach a person.
+ """
+ if not (sys.stdin.isatty() and sys.stdout.isatty()):
+ return None
+
+ def confirm(ref: str) -> bool:
+ try:
+ answer = input(f"Abandon {ref} and cut a new attempt? [y/N] ")
+ except EOFError:
+ return False
+ return answer.strip().lower() in {"y", "yes"}
+
+ return confirm
+
+
def cmd_release(args) -> None:
"""The ``release`` subcommand: claim, draft, dispatch."""
from scripts import release as release_script
@@ -521,6 +550,7 @@ def cmd_release(args) -> None:
skip_bundles=args.skip_bundles, skip_tests=args.skip_tests,
include_macos_intel=args.include_macos_intel, include_termux=args.include_termux,
published=published_stable_identity(repository), run_wait=RUN_WAIT_SECONDS,
+ confirm_abandon=_abandon_prompt(), inspect=lambda command: _inspect(repo, command),
)
print(next_steps(result, bold=sys.stdout.isatty() and "NO_COLOR" not in os.environ))
diff --git a/tests/scripts/test_release_entrypoint.py b/tests/scripts/test_release_entrypoint.py
index a8643f6d35b..f453f648c6f 100644
--- a/tests/scripts/test_release_entrypoint.py
+++ b/tests/scripts/test_release_entrypoint.py
@@ -212,6 +212,60 @@ def test_a_final_tag_for_the_next_version_refuses_the_cut(source):
assert "rc." not in git(source, "ls-remote", "origin", "refs/tags/*")
+def test_a_confirmed_abandon_clears_the_blocking_attempt_and_cuts_the_next(source):
+ from scripts.releases.entrypoint import ReleaseRefused
+
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+ asked, calls = [], []
+
+ def inspect(command):
+ if command[1] == "run":
+ return "[]"
+ raise ReleaseRefused("release not found")
+
+ result = _release(source, _advance(source, "fix"), execute=calls.append, inspect=inspect,
+ confirm_abandon=lambda ref: asked.append(ref) or True)
+
+ assert asked == ["rc.1-v0.21.5"]
+ assert result["tag"] == "rc.2-v0.21.5"
+ assert "refs/tags/abandoned-rc.1-v0.21.5" in git(source, "ls-remote", "origin", "refs/tags/*")
+
+
[email protected]("confirm_abandon", [None, lambda ref: False])
+def test_an_unconfirmed_abandon_refuses_as_before(source, confirm_abandon):
+ from scripts.releases.entrypoint import ReleaseRefused
+
+ _claim(source, "0.21.5", git(source, "rev-parse", "HEAD"))
+
+ with pytest.raises(ReleaseRefused, match="publish or abandon it first"):
+ _release(source, _advance(source, "later"), execute=_must_not_execute,
+ confirm_abandon=confirm_abandon)
+ assert git(source, "tag", "--list", "*rc.*") == "rc.1-v0.21.5"
+
+
[email protected](("tty", "answer", "expected"), [
+ (True, "y", True), (True, "YES", True), (True, "", False), (True, "n", False),
+ (True, EOFError, False), (False, "y", None),
+])
+def test_the_abandon_prompt_exists_only_on_a_terminal_and_defaults_to_no(monkeypatch, tty, answer, expected):
+ import sys
+
+ from scripts.releases.entrypoint import _abandon_prompt
+
+ monkeypatch.setattr(sys.stdin, "isatty", lambda: tty)
+ monkeypatch.setattr(sys.stdout, "isatty", lambda: tty)
+
+ def fake_input(_prompt):
+ if answer is EOFError:
+ raise EOFError
+ return answer
+
+ monkeypatch.setattr("builtins.input", fake_input)
+
+ confirm = _abandon_prompt()
+ assert (confirm is None) if expected is None else (confirm("rc.1-v0.21.5") is expected)
+
+
def test_second_cut_after_abandon_is_attempt_two_of_the_same_version(source):
first = git(source, "rev-parse", "HEAD")
_claim(source, "0.21.5", first)
diff --git a/website/docs/developer-guide/stable-releases.md b/website/docs/developer-guide/stable-releases.md
index c1860ece647..d58a7181a36 100644
--- a/website/docs/developer-guide/stable-releases.md
+++ b/website/docs/developer-guide/stable-releases.md
@@ -76,7 +76,10 @@ intentional. The selected commit must descend from the newest published
accepted. An abandoned attempt puts no constraint on the next cut; it was often
abandoned because its commit is bad. `release` also refuses while any attempt,
of any version, is outstanding. The refusal prints the attempt's workflow run
-URL, the `abandon` command, and the rerun command before it raises.
+URL, the `abandon` command, and the rerun command before it raises. In an
+interactive terminal it then asks `Abandon <ref> and cut a new attempt? [y/N]`;
+`y` abandons the attempt and cuts the next one, and the default is no. Anywhere
+stdin or stdout is not a terminal it raises without asking.
The attempt ref is a public lock, not a SemVer prerelease. It reads
`rc.1-v0.21.5`, not `v0.21.5-rc.1`. The package version stays plain `0.21.5`.