Cut a patch release of only the commits named with deploy-release --cut-patch

This commit is contained in:
Lilleman
2026-11-24 14:09:56 +01:00
parent 80de753b9e
commit 9c2587b5ca
6 changed files with 389 additions and 24 deletions
+30 -11
View File
@@ -16,12 +16,15 @@ from failure import Failure
from plan_store.todo_md import FilePlan
from record_store.stores import FileStore
from forge.commands import forge_of, runner
from plan.release import newest_tag, Release, UNRELEASED_HEADING, version
from plan.release import newest_tag, Release, tagged, UNRELEASED_HEADING, version
from forge import pulls
from deploy_release import release_pull
from project_config import templates
CUT_BODY = "Rename ## Unreleased in CHANGELOG.md to the version."
def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str | Failure:
"""What the cut did, as the tool prints it; a Failure with git's, the forge's or the tool's reason where a step stopped."""
if isinstance(same := same_origin(clone, checkout), Failure):
@@ -37,10 +40,13 @@ def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str
if isinstance(release, Failure):
return release
named = version(release)
title, tag = f"Cut release {named}", f"v{named}"
if isinstance(patched := patch_refusal(clone, ref, release), Failure):
return patched
title, tag, branch = f"Cut release {named}", f"v{named}", f"release-{named}"
merged = commit_titled(title, ref, clone)
if merged is None:
landed = land(clone, ref, named, title, sleep)
build = lambda replacing: push_cut_commit(clone, ref, branch, named, title, replacing)
landed = land(clone, ref, branch, title, CUT_BODY, build, sleep)
if isinstance(landed, Failure):
return landed
if isinstance(fetched := git("fetch", "--quiet", "origin", cwd=clone), Failure):
@@ -58,13 +64,24 @@ def cut(clone: str, checkout: str, sleep: typing.Callable[[float], None]) -> str
git("tag", "--delete", tag, cwd=clone)
return pushed
said(f"pushed the tag {tag}")
delete_release_branch(clone, f"release-{named}")
delete_release_branch(clone, branch)
moved = deploy(checkout)
if isinstance(moved, Failure):
return Failure(f"cut and pushed {tag}, but moving {checkout} stopped: {moved.reason}. Fix that, then run a bare deploy-release.")
return f"{moved}\n\nDone: {tag} is cut and pushed, and {checkout} is on it."
def patch_refusal(clone: str, ref: str, release: Release) -> Failure | None:
"""A Failure where release is a patch of the newest tag ref holds: a cut of all of ref would ship its other work under a patch number."""
tag = newest_tag(clone, merged_into=ref)
if isinstance(tag, Failure):
return tag
cut_release = tagged(tag)
if cut_release is not None and release[:2] == cut_release[:2]:
return Failure(f"{version(release)} is a patch of {tag}: cut it with --cut-patch <commits>, so it holds only the fix and not all of {ref}")
return None
def said(step: str) -> None:
"""Say on stderr that step finished, so the human sees how far the cut got before the changelog fills the screen."""
print(f"deploy-release: {step}", file=sys.stderr)
@@ -116,8 +133,8 @@ def clone_plan(clone: str) -> FilePlan:
return FilePlan(pathlib.Path(clone, "todo.md"), "todo.md", goals, decisions, history, DEFAULT_FLOOR)
def ready_release(clone: str, ref: str) -> Release | Failure:
"""The next release, as chunk-preflight works it out, where it is ready to cut: it holds no item in todo.md, its release review has landed and changes are unreleased."""
def ready_release(clone: str, ref: str, review: bool = True) -> Release | Failure:
"""The next release, as chunk-preflight works it out, where it is ready to cut: it holds no item in todo.md, its release review has landed, unless review is False, and changes are unreleased."""
# No project's config names the clone, so its changelog is read at the fixed path, on ref like the plan, and its titles as they stand.
plan = default_plan(clone, ref, clone_plan(clone), FileStore(pathlib.Path(clone, "CHANGELOG.md"), "CHANGELOG.md"), templates.BARE)
if isinstance(plan.plan, Failure):
@@ -129,6 +146,8 @@ def ready_release(clone: str, ref: str) -> Release | Failure:
return Failure("todo.md names no release after the last one cut")
case Next(release=release) if release is not None:
return Failure(f"release {version(release)} still holds items in todo.md")
case ReviewDue(release=release) if not review and release is not None:
return release
case ReviewDue(release=release):
return Failure(f"the release review of {version(release) if release else 'the next release'} hasn't landed")
case Unplanned():
@@ -150,12 +169,12 @@ def commit_titled(title: str, ref: str, clone: str) -> str | None | Failure:
return next((line.split(" ", 1)[0] for line in log.splitlines() if line.split(" ", 1)[1:] == [title]), None)
def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[float], None]) -> Failure | None:
"""Push the branch release-<named> with the cut commit and open its pull request, where an earlier run hasn't; then wait for its checks and merge it."""
def land(clone: str, ref: str, branch: str, title: str, body: str, build: typing.Callable[[str | None], Failure | None], sleep: typing.Callable[[float], None]) -> Failure | None:
"""Push branch with build and open its pull request, titled title with body, where an earlier run hasn't; then wait for its checks and merge it. build pushes the branch's commit on ref: a new branch, or in place of the commit it names, origin's branch's head."""
url = git("config", "--get", "remote.origin.url", cwd=clone)
if isinstance(url, Failure):
return url
on, run, branch, base = forge_of(url), runner(clone), f"release-{named}", ref.removeprefix("origin/")
on, run, base = forge_of(url), runner(clone), ref.removeprefix("origin/")
head = branch_head(branch, clone)
if isinstance(head, Failure):
return head
@@ -164,7 +183,7 @@ def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[f
return behind
if head is None or behind:
# Where main moved on, such as to fix a failed check, the branch could no longer merge fast-forward, so it is rebuilt on main.
if isinstance(pushed := push_cut_commit(clone, ref, branch, named, title, head), Failure):
if isinstance(pushed := build(head), Failure):
return pushed
said(f"pushed the branch {branch}")
head = branch_head(branch, clone) or Failure(f"pushed {branch}, but origin holds no such branch")
@@ -172,7 +191,7 @@ def land(clone: str, ref: str, named: str, title: str, sleep: typing.Callable[[f
return head
number = pulls.open_pull(on, branch, head, run)
if number is None:
if isinstance(created := release_pull.create_pull(on, branch, base, title, run), Failure):
if isinstance(created := release_pull.create_pull(on, branch, base, title, body, run), Failure):
return created
number = pulls.open_pull(on, branch, head, run) or Failure(f"opened a pull request for {branch}, but the forge lists none from origin at {head[:12]}")
if isinstance(number, str):