From db32e4ef59b5fb9c1a570e7a3b426f4665255d90 Mon Sep 17 00:00:00 2001 From: Lilleman Date: Tue, 24 Nov 2026 15:12:17 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=205=20=F0=9F=9F=A1=20(0=20misread);=20share=20the?= =?UTF-8?q?=20scratch=20worktree,=20check=20a=20reused=20tag=20and=20main'?= =?UTF-8?q?s=20merge-back,=20refuse=20GitHub,=20split=20the=20looped=20tes?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- bin/deploy_release/cut.py | 38 +++-- bin/deploy_release/main.py | 42 ++--- bin/deploy_release/patch.py | 182 +++++++++++++--------- bin/deploy_release/test_deploy_release.py | 70 +++++++-- bin/release_plan/release_standing.py | 5 +- bin/release_plan/test_release_standing.py | 18 +++ docs/decisions.md | 4 +- todo.md | 10 +- 9 files changed, 249 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index c3ecb654..cc7f636d 100644 --- a/README.md +++ b/README.md @@ -198,13 +198,13 @@ bin/deploy-release --cut It renames `## Unreleased` in `CHANGELOG.md` to the version and merges that through a pull request, since nobody can push to `main`. Then it tags the merged commit `v`, pushes the tag, and moves this machine's `~/.claude` to it. Where a step fails it stops with the reason, and a rerun continues where it stopped. `deploy-release --help` lists the steps. Each other machine takes the release with Update. -A fix that must ship before `main`'s other unreleased work goes out as a patch release, such as 0.15.2 after v0.15.1. File its item under that release, merge its chunk, then cut it with the commits the chunk merged, as a range or one commit: +A fix that must ship before `main`'s other unreleased work goes out as a patch release, such as 0.15.2 after v0.15.1. File its item under that release, merge its chunk, then cut it at once with the commits the chunk merged, as a range or one commit. A range leaves out its first commit, as git's `..` does, so start it at the commit before the chunk's first: ```sh bin/deploy-release --cut-patch 794ce37..1aa2367 ``` -It applies only those commits on the newest tag, tests them with `ci.sh`, tags and pushes the release, then merges the tag back into `main` through a pull request and moves `~/.claude` to it. A patch skips the release review. `deploy-release --help` lists the steps. +It applies only those commits on the newest tag, tests them with `ci.sh`, tags and pushes the release, then merges the tag back into `main` through a pull request and moves `~/.claude` to it. A patch skips the release review. Until it is cut, `chunk-preflight` calls the patch's release review due, and loop-claude would run it. `deploy-release --help` lists the steps. ## Tools diff --git a/bin/deploy_release/cut.py b/bin/deploy_release/cut.py index 04330f08..b6f795af 100644 --- a/bin/deploy_release/cut.py +++ b/bin/deploy_release/cut.py @@ -2,6 +2,7 @@ Each step first checks whether an earlier run did it, so a rerun continues where the last run stopped. """ +import contextlib import pathlib import shutil import sys @@ -117,13 +118,13 @@ def drop_unpushed_cut_tags(clone: str) -> Failure | None: def same_origin(clone: str, checkout: str) -> Failure | None: - """A Failure unless clone is a clone of the origin checkout takes its releases from, so --cut never cuts another project.""" + """A Failure unless clone is a clone of the origin checkout takes its releases from, so a cut never cuts another project.""" urls = [git("ls-remote", "--get-url", "origin", cwd=where) for where in (clone, checkout)] failed = next((url for url in urls if isinstance(url, Failure)), None) if failed is not None: return failed if urls[0] != urls[1]: - return Failure(f"run --cut in a clone of {checkout}'s origin, {str(urls[1]).strip()}; this directory's origin is {str(urls[0]).strip()}") + return Failure(f"run deploy-release in a clone of {checkout}'s origin, {str(urls[1]).strip()}; this directory's origin is {str(urls[0]).strip()}") return None @@ -170,7 +171,9 @@ def commit_titled(title: str, ref: str, clone: str) -> str | None | Failure: 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.""" + """Push branch 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 branch's commit, made on ref. It takes the commit origin's branch points at, which the push replaces, or None where origin has no such branch yet.""" url = git("config", "--get", "remote.origin.url", cwd=clone) if isinstance(url, Failure): return url @@ -225,11 +228,10 @@ def behind_main(branch: str, head: str, ref: str, clone: str) -> bool | Failure: def push_cut_commit(clone: str, ref: str, branch: str, named: str, title: str, replacing: str | None) -> Failure | None: - """Commit ref's CHANGELOG.md with ## Unreleased renamed to named, in a worktree of its own so the clone's checkout stays as it is, and push it as branch: a new one, or in place of replacing, the commit origin's branch points at.""" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "cut" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), ref, cwd=clone), Failure): - return added + """Commit ref's CHANGELOG.md with ## Unreleased renamed to named, in a worktree of its own, and push it as branch, replacing the commit origin's branch points at, where there is one.""" + with scratch_worktree(clone, ref) as worktree: + if isinstance(worktree, Failure): + return worktree changelog = worktree / "CHANGELOG.md" renamed, count = UNRELEASED_HEADING.subn(f"## {named}", changelog.read_text() if changelog.exists() else "", count=1) if not count: @@ -237,9 +239,23 @@ def push_cut_commit(clone: str, ref: str, branch: str, named: str, title: str, r changelog.write_text(renamed) if isinstance(committed := git("commit", "--quiet", "-am", title, cwd=str(worktree)), Failure): return committed - lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] - pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) - return pushed if isinstance(pushed, Failure) else None + return push_branch(worktree, branch, replacing) + + +@contextlib.contextmanager +def scratch_worktree(clone: str, at: str) -> typing.Iterator[pathlib.Path | Failure]: + """A worktree of clone, detached at at, in a folder of its own that is removed afterwards, so the clone's checkout stays as it is; a Failure where git can't add it.""" + worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "worktree" + try: + added = git("worktree", "add", "--quiet", "--detach", str(worktree), at, cwd=clone) + yield added if isinstance(added, Failure) else worktree finally: git("worktree", "remove", "--force", str(worktree), cwd=clone) shutil.rmtree(worktree.parent, ignore_errors=True) + + +def push_branch(worktree: pathlib.Path, branch: str, replacing: str | None) -> Failure | None: + """Push worktree's HEAD to origin as branch: a new one, or in place of replacing, only while origin's branch still points at it.""" + lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] + pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) + return pushed if isinstance(pushed, Failure) else None diff --git a/bin/deploy_release/main.py b/bin/deploy_release/main.py index d8ce8935..ff665415 100644 --- a/bin/deploy_release/main.py +++ b/bin/deploy_release/main.py @@ -18,7 +18,9 @@ memory, stay as they are. --cut runs in the development clone, and refuses where that clone's origin isn't 's. It cuts the next release, as chunk-preflight works it out, and refuses without changing anything, unless that release holds no item in todo.md, its release review has -landed and changes are unreleased. The release names the version; the tool doesn't choose one. +landed and changes are unreleased. The release names the version; the tool doesn't choose one. It also refuses a +release that is a patch of the newest tag, such as 0.15.2 after v0.15.1, since it would ship all of main: cut that +with --cut-patch. 1. On a fresh origin/main, it renames ## Unreleased in CHANGELOG.md to the version, commits that titled `Cut release `, and pushes it as the branch release-. The clone's own checkout stays as it is. Where main has moved past the branch, it rebuilds the branch on main. @@ -34,25 +36,29 @@ It says on stderr as each step finishes, and ends stdout, after the changelog, w Where a step fails it stops, exit 1, with git's or the forge's reason, and leaves the pull request and the branch as they are. A rerun continues: it takes the branch's open pull request and a cut commit already merged, and drops a cut tag an earlier run made but never pushed. Once the tag is pushed, the release is cut: where only the -move stopped, fix what it names and run a bare deploy-release. --cut refuses a release that is a patch of the newest tag, -such as 0.15.2 after v0.15.1, since it would ship all of main: cut that with --cut-patch. +move stopped, fix what it names and run a bare deploy-release. --cut-patch runs in the development clone too, for a fix that must ship before main's other unreleased work. It -cuts the newest tag's next patch release, such as 0.15.2 after v0.15.1, holding only on top of the tag. -is one revision as git log reads it: a range such as 794ce37..1aa2367, which leaves out 794ce37 as git's `..` does, or one -commit. Each must be on origin's main and not in the tag; merge commits are left out. Name the commit that finished the -fix's item too: its entries under ## Unreleased in CHANGELOG.md become the release's. todo.md must name the release and file -no item under it; a patch skips the release review. It refuses without changing anything where any of that doesn't hold. -1. In a worktree of its own at the tag, it applies each commit's changes, except to todo.md, CHANGELOG.md and the records - every chunk appends to, heads CHANGELOG.md with the release's section, and commits that titled `Cut release `. - Where a commit doesn't apply, it stops and names it: cut that patch by hand. -2. It runs ci.sh on that commit, and stops where it fails, before anything is tagged. -3. It tags the commit v, annotated `Cut release `, and pushes only the tag. -4. On a fresh origin/main it merges the tag keeping main's files, moves the release's entries from ## Unreleased to a - ## section, commits that titled `Merge release into main`, and lands it through the branch - release- and a pull request as --cut does, so the tag is in main's history. -5. It moves to the tag as above, and ends stdout as --cut does. -A rerun skips a tag origin holds already and a merge main holds already. +cuts the newest tag's next patch release, holding only on top of the tag. is a range as git log reads +it, such as 794ce37..1aa2367, which leaves out 794ce37 as git's `..` does, or one commit, which it reads as that commit +alone. Name the commits the fix's chunk merged, including the one that finished its item: the entries that commit added +under ## Unreleased in CHANGELOG.md become the release's. Each commit must be on origin's main and not in the tag. Merge +commits are left out, and so are the commits a merge of main brought into the range. todo.md must name the release and +file no item under it; a patch skips the release review. Cut it as soon as the fix merges: until then chunk-preflight calls +the patch's release review due, and loop-claude would run it. It refuses without changing anything where any of that +doesn't hold, and on a GitHub origin, whose rebase merge would drop the tag from main's history. +1. It says on stderr which commits the release ships. +2. In a worktree of its own at the tag, it applies each commit's changes, except to CHANGELOG.md, todo.md, + docs/comprehension-history.md and docs/reading-cost.md, heads CHANGELOG.md with the release's section, and commits that + titled `Cut release `. Where a commit doesn't apply, it stops, names it, and says how to cut the patch by hand. +3. It runs ci.sh on that commit, and stops where it fails, before anything is tagged. +4. It tags the commit v, annotated `Cut release `, and pushes only the tag. +5. On a fresh origin/main it merges the tag keeping main's files, moves the release's entries from ## Unreleased to a + ## section below it, commits that titled `Merge release into main`, and lands it through the branch + release- and a pull request as --cut does. Then it checks main holds the tag. +6. It moves to the tag as above, and ends stdout as --cut does. +A rerun takes a tag origin holds already, once it checks the tag lists the same changelog entries, and the merge-back's open +pull request. Once the merge-back has merged, the release is cut: where only the move stopped, run a bare deploy-release. """ import os import pathlib diff --git a/bin/deploy_release/patch.py b/bin/deploy_release/patch.py index bb74dd86..5e31b394 100644 --- a/bin/deploy_release/patch.py +++ b/bin/deploy_release/patch.py @@ -1,30 +1,79 @@ """`deploy-release --cut-patch `: cut the newest tag's next patch release holding only the commits named, test it with ci.sh, tag it, merge the tag back into main through a pull request, then move ~/.claude to it. -Each step first checks whether an earlier run did it, so a rerun continues where the last run stopped. +A rerun takes the tag an earlier run pushed, once it checks the tag lists the same changelog entries, and the merge-back's open pull request. """ +import dataclasses import pathlib import re -import shutil import subprocess -import tempfile import typing from git_cli.git_repo import default_ref, git -from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, ready_release, said, same_origin +from deploy_release.cut import delete_release_branch, drop_unpushed_cut_tags, land, push_branch, ready_release, said, same_origin, scratch_worktree from deploy_release.deploy import deploy from failure import Failure -from plan.release import newest_tag, Release, tagged, UNRELEASED_TITLE, version +from forge.commands import forge_of +from plan.release import newest_tag, tagged, UNRELEASED_TITLE, version from text_files.markdown_text import section -# The files a patch leaves as the tag holds them: the plan, the changelog the cut writes itself, and the records every chunk appends to, which seldom apply on an older tag. -LEFT_AS_TAGGED = ("todo.md", "CHANGELOG.md", "docs/reading-cost.md", "docs/comprehension-history.md") +# The files a patch leaves as the tag holds them: the changelog, whose section the cut writes itself; the plan; and the records each chunk appends to, which seldom apply on an older tag. +LEFT_AS_TAGGED = ("CHANGELOG.md", "docs/comprehension-history.md", "docs/reading-cost.md", "todo.md") MERGE_BACK_BODY = "Merge the patch release's tag into main, keeping main's files, and list its changelog entries under its version." +@dataclasses.dataclass(frozen=True) +class Patch: + """A patch release ready to cut.""" + # origin's default branch, as default_ref names it. + ref: str + # The newest tag ref holds, which the patch goes on top of. + base: str + # The patch's version, the base's next patch. + named: str + # The commits the patch ships, oldest first. + commits: list[str] + # The CHANGELOG.md entries the commits added under ref's ## Unreleased, in ref's order. + entries: list[str] + + def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[float], None]) -> str | Failure: - """What the patch cut did, as the tool prints it; a Failure with git's, the forge's, ci.sh's or the tool's reason where a step stopped. commits is one revision as git log reads it, or one commit.""" + """What the patch cut did, as the tool prints it; a Failure with git's, the forge's, ci.sh's or the tool's reason where a step stopped. commits is a range as git log reads it, or one commit.""" + patch = planned(clone, checkout, commits) + if isinstance(patch, Failure): + return patch + for commit in patch.commits: + subject = git("log", "-1", "--format=%h %s", commit, cwd=clone) + said(f"ships {'' if isinstance(subject, Failure) else subject.strip()}") + tag, branch = f"v{patch.named}", f"release-{patch.named}" + pushed = git("ls-remote", "--tags", "--refs", "origin", f"refs/tags/{tag}", cwd=clone) + if isinstance(pushed, Failure): + return pushed + made = tagged_entries(clone, patch) if pushed.strip() else tag_patch(clone, patch) + if isinstance(made, Failure): + return made + build = lambda replacing: push_merge_back(clone, patch, replacing) + if isinstance(landed := land(clone, patch.ref, branch, f"Merge release {patch.named} into main", MERGE_BACK_BODY, build, sleep), Failure): + return landed + if isinstance(fetched := git("fetch", "--quiet", "origin", cwd=clone), Failure): + return fetched + if isinstance(git("merge-base", "--is-ancestor", tag, patch.ref, cwd=clone), Failure): + return Failure(f"the merge-back merged, but {patch.ref} doesn't hold {tag}, so the next cut can't read it as cut") + 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 planned(clone: str, checkout: str, commits: str) -> Patch | Failure: + """The patch commits names, once the clone, the plan and the commits allow it; a Failure saying why not, before anything changes on origin.""" if isinstance(same := same_origin(clone, checkout), Failure): return same + url = git("config", "--get", "remote.origin.url", cwd=clone) + if isinstance(url, Failure): + return url + if forge_of(url) == "gh": + return Failure("--cut-patch merges the tag back fast-forward, which GitHub can't, since its rebase merge drops the merge commit: cut the patch by hand there") if isinstance(fetched := git("fetch", "--quiet", "--tags", "origin", cwd=clone), Failure): return fetched if isinstance(dropped := drop_unpushed_cut_tags(clone), Failure): @@ -35,10 +84,10 @@ def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[f base = newest_tag(clone, merged_into=ref) if isinstance(base, Failure): return base - cut_release = tagged(base) - if base is None or cut_release is None: - return Failure(f"{ref} holds no v* tag to cut a patch of") - named = version((cut_release[0], cut_release[1], cut_release[2] + 1)) + cut = tagged(base) + if base is None or cut is None: + return Failure(f"{ref}'s newest tag, {base}, names no release x.y.z to cut a patch of" if base else f"{ref} holds no v* tag to cut a patch of") + named = version((cut[0], cut[1], cut[2] + 1)) # A patch holds only fixes, and the release review reads the whole project, so a patch is cut without one. release = ready_release(clone, ref, review=False) if isinstance(release, Failure): @@ -49,35 +98,17 @@ def cut_patch(clone: str, checkout: str, commits: str, sleep: typing.Callable[[f if isinstance(picked, Failure): return picked entries = changelog_entries(clone, ref, picked) - if isinstance(entries, Failure): - return entries - title, tag = f"Cut release {named}", f"v{named}" - pushed = git("ls-remote", "--tags", "--refs", "origin", f"refs/tags/{tag}", cwd=clone) - if isinstance(pushed, Failure): - return pushed - if not pushed.strip(): - if isinstance(made := tag_patch(clone, base, picked, entries, named, title), Failure): - return made - if isinstance(git("merge-base", "--is-ancestor", tag, ref, cwd=clone), Failure): - branch = f"release-{named}" - build = lambda replacing: push_merge_back(clone, ref, branch, tag, named, entries, replacing) - if isinstance(landed := land(clone, ref, branch, f"Merge release {named} into main", MERGE_BACK_BODY, build, sleep), Failure): - return landed - 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." + return entries if isinstance(entries, Failure) else Patch(ref, base, named, picked, entries) def patch_commits(clone: str, ref: str, base: str, commits: str) -> list[str] | Failure: - """The commits commits names, oldest first, merge commits left out; a Failure where one is missing from ref or the tag base already holds it.""" - listed = git("rev-list", "--reverse", "--no-merges", commits if ".." in commits else f"{commits}^!", "--", cwd=clone) + """The commits commits names, oldest first: merge commits, and the commits a merge brought into a range, are left out. A Failure where one is missing from ref or the tag base already holds it.""" + listed = git("rev-list", "--reverse", "--no-merges", "--first-parent", commits if ".." in commits else f"{commits}^!", "--", cwd=clone) if isinstance(listed, Failure): return listed picked = listed.split() if not picked: - return Failure(f"{commits} names no commit but merges") + return Failure(f"{commits} names no commit that isn't a merge: write a range as ..") for commit in picked: if isinstance(git("merge-base", "--is-ancestor", commit, ref, cwd=clone), Failure): return Failure(f"{commit[:12]} isn't on {ref}: merge it there first") @@ -101,22 +132,32 @@ def changelog_entries(clone: str, ref: str, commits: list[str]) -> list[str] | F return entries or Failure(f"the commits add no entry under ## Unreleased in CHANGELOG.md on {ref}: name the commit that finished the fix's item too") -def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], named: str, title: str) -> Failure | None: - """In a worktree at the tag base, apply commits but for LEFT_AS_TAGGED, head CHANGELOG.md with entries under ## named, commit that titled title, test it with ci.sh, then tag it v and push the tag.""" - tag = f"v{named}" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "patch" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), base, cwd=clone), Failure): - return added - for commit in commits: - if isinstance(applied := apply_commit(clone, worktree, commit, base), Failure): +def tagged_entries(clone: str, patch: Patch) -> Failure | None: + """A Failure unless the tag an earlier run pushed lists patch's entries under its version, so a rerun with other commits doesn't merge back entries the tag doesn't ship.""" + changelog = git("show", f"v{patch.named}:CHANGELOG.md", cwd=clone) + if isinstance(changelog, Failure): + return changelog + listed = [line for line in section(changelog, re.escape(patch.named)) or [] if line.strip()] + if listed != patch.entries: + return Failure(f"origin's v{patch.named} lists other changelog entries than the commits named: name the commits it was cut from") + return None + + +def tag_patch(clone: str, patch: Patch) -> Failure | None: + """In a worktree at the base tag, apply patch's commits but for LEFT_AS_TAGGED, head CHANGELOG.md with its section, commit that titled `Cut release `, test it with ci.sh, then tag it and push the tag.""" + title, tag = f"Cut release {patch.named}", f"v{patch.named}" + with scratch_worktree(clone, patch.base) as worktree: + if isinstance(worktree, Failure): + return worktree + for commit in patch.commits: + if isinstance(applied := apply_commit(clone, worktree, commit, patch), Failure): return applied changelog = worktree / "CHANGELOG.md" - changelog.write_text(headed(changelog.read_text() if changelog.exists() else "# Changelog\n", entries, named)) + changelog.write_text(headed(changelog.read_text() if changelog.exists() else "# Changelog\n", patch.entries, patch.named)) if isinstance(committed := git("commit", "--quiet", "--all", "--message", title, cwd=str(worktree)), Failure): return committed - said(f"applied {len(commits)} commit(s) on {base}; testing them with ci.sh") - if isinstance(tested := run_ci(worktree), Failure): + said(f"applied the commits on {patch.base}; testing them with ci.sh") + if isinstance(tested := run_ci(worktree, patch.ref), Failure): return tested said("ci.sh passed") if isinstance(made := git("tag", "--annotate", "--message", title, tag, "HEAD", cwd=str(worktree)), Failure): @@ -127,9 +168,6 @@ def tag_patch(clone: str, base: str, commits: list[str], entries: list[str], nam return pushed said(f"pushed the tag {tag}") return None - finally: - git("worktree", "remove", "--force", str(worktree), cwd=clone) - shutil.rmtree(worktree.parent, ignore_errors=True) def headed(changelog: str, entries: list[str], named: str) -> str: @@ -141,22 +179,26 @@ def headed(changelog: str, entries: list[str], named: str) -> str: return changelog[:first.start()] + added + "\n" + changelog[first.start():] -def apply_commit(clone: str, worktree: pathlib.Path, commit: str, base: str) -> Failure | None: - """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the tag base's files differ from commit's parent.""" +def apply_commit(clone: str, worktree: pathlib.Path, commit: str, patch: Patch) -> Failure | None: + """Apply commit's change, but for LEFT_AS_TAGGED, to worktree's index and files, merging three ways where the base tag's files differ from commit's parent.""" diff = git("diff", "--binary", f"{commit}^", commit, "--", ".", *(f":(exclude){path}" for path in LEFT_AS_TAGGED), cwd=clone) if isinstance(diff, Failure): return diff if not diff: return None - patch = worktree.parent / "commit.patch" - patch.write_text(diff) - if isinstance(applied := git("apply", "--3way", "--index", str(patch), cwd=str(worktree)), Failure): + patch_file = worktree.parent / "commit.patch" + patch_file.write_text(diff) + if isinstance(applied := git("apply", "--3way", "--index", str(patch_file), cwd=str(worktree)), Failure): subject = git("log", "-1", "--format=%s", commit, cwd=clone) - return Failure(f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {base}: {applied.reason}. Cut this patch by hand.") + return Failure( + f"{commit[:12]} ({'' if isinstance(subject, Failure) else subject.strip()}) doesn't apply on {patch.base}: {applied.reason}. " + f"Cut the patch by hand: on {patch.base}, apply the fix and add CHANGELOG.md's ## {patch.named} section, commit that titled `Cut release {patch.named}`, " + f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun then merges it back and deploys it." + ) return None -def run_ci(worktree: pathlib.Path) -> Failure | None: +def run_ci(worktree: pathlib.Path, ref: str) -> Failure | None: """None where the patch's ci.sh passes on its committed head; a Failure with the end of its output where it fails.""" if not (worktree / "ci.sh").exists(): return Failure("the patch holds no ci.sh to test it with") @@ -164,31 +206,25 @@ def run_ci(worktree: pathlib.Path) -> Failure | None: if ran.returncode == 0: return None tail = "\n".join((ran.stdout + ran.stderr).strip().splitlines()[-30:]) - return Failure(f"ci.sh failed on the patch, so nothing is tagged:\n{tail}") + return Failure(f"ci.sh failed on the patch, so nothing is tagged. Fix it on {ref}, then rerun naming the fix's commits too. The end of its output:\n{tail}") -def push_merge_back(clone: str, ref: str, branch: str, tag: str, named: str, entries: list[str], replacing: str | None) -> Failure | None: - """On ref, merge tag keeping ref's files, with entries moved from ## Unreleased to a ## named section after it, in a worktree of its own; push that as branch: a new one, or in place of replacing, the commit origin's branch points at.""" - worktree = pathlib.Path(tempfile.mkdtemp(prefix="deploy-release-")) / "merge-back" - try: - if isinstance(added := git("worktree", "add", "--quiet", "--detach", str(worktree), ref, cwd=clone), Failure): - return added - if isinstance(merged := git("merge", "--quiet", "--no-ff", "--no-commit", "--strategy", "ours", tag, cwd=str(worktree)), Failure): +def push_merge_back(clone: str, patch: Patch, replacing: str | None) -> Failure | None: + """On origin's main, merge the patch's tag keeping main's files, move its entries from ## Unreleased to a ## section below ## Unreleased, and push that as the branch release-, replacing the commit origin's branch points at, where there is one.""" + with scratch_worktree(clone, patch.ref) as worktree: + if isinstance(worktree, Failure): + return worktree + if isinstance(merged := git("merge", "--quiet", "--no-ff", "--no-commit", "--strategy", "ours", f"v{patch.named}", cwd=str(worktree)), Failure): return merged changelog = worktree / "CHANGELOG.md" - changelog.write_text(moved_entries(changelog.read_text(), entries, named)) - if isinstance(committed := git("commit", "--quiet", "--all", "--message", f"Merge release {named} into main", cwd=str(worktree)), Failure): + changelog.write_text(moved_entries(changelog.read_text(), patch.entries, patch.named)) + if isinstance(committed := git("commit", "--quiet", "--all", "--message", f"Merge release {patch.named} into main", cwd=str(worktree)), Failure): return committed - lease = [f"--force-with-lease=refs/heads/{branch}:{replacing}"] if replacing else [] - pushed = git("push", "--quiet", *lease, "origin", f"HEAD:refs/heads/{branch}", cwd=str(worktree)) - return pushed if isinstance(pushed, Failure) else None - finally: - git("worktree", "remove", "--force", str(worktree), cwd=clone) - shutil.rmtree(worktree.parent, ignore_errors=True) + return push_branch(worktree, f"release-{patch.named}", replacing) def moved_entries(changelog: str, entries: list[str], named: str) -> str: - """changelog with entries taken out of its ## Unreleased section and put in a ## named section right after it.""" + """changelog with entries taken out of its ## Unreleased section and put in a ## named section right below that section.""" lines = changelog.split("\n") start = next(index for index, line in enumerate(lines) if re.fullmatch(f"## {UNRELEASED_TITLE}", line)) end = next((index for index in range(start + 1, len(lines)) if lines[index].startswith("## ")), len(lines)) diff --git a/bin/deploy_release/test_deploy_release.py b/bin/deploy_release/test_deploy_release.py index e10e8e04..8ed6f5d8 100644 --- a/bin/deploy_release/test_deploy_release.py +++ b/bin/deploy_release/test_deploy_release.py @@ -508,7 +508,7 @@ class Cut(unittest.TestCase): self.assertEqual(ran.returncode, 0, ran.stderr) self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") - def test_refuses_changing_nothing_where_the_plan_names_no_patch_release(self): + def test_refuses_before_any_change_where_the_plan_names_no_patch_release(self): self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix tool.txt") self.git(self.clone, "push", "-q", "origin", "main") ran = self.cut_patch("HEAD") @@ -517,7 +517,7 @@ class Cut(unittest.TestCase): self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") self.assertEqual(self.forge_state()["pulls"], []) - def test_refuses_changing_nothing_while_the_patch_release_holds_an_item(self): + def test_refuses_before_any_change_while_the_patch_release_holds_an_item(self): self.plan_patch() self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=4, release="0.1.1")}, "File item 4") self.git(self.clone, "push", "-q", "origin", "main") @@ -532,16 +532,64 @@ class Cut(unittest.TestCase): ran = self.cut_patch(self.plan_patch()) self.assertEqual(ran.returncode, 0, ran.stderr) - def test_refuses_a_commit_the_tag_holds_or_origins_main_doesnt(self): + def test_refuses_a_commit_the_tag_holds(self): self.plan_patch() - for commit in ("v0.1.0", "HEAD"): - if commit == "HEAD": - self.commit({"tool.txt": "local\n"}, "Unpushed") - ran = self.cut_patch(commit) - self.assertEqual(ran.returncode, 1, commit) - self.assertIn(self.git(self.clone, "rev-parse", "--short", f"{commit}^{{commit}}").strip()[:7], ran.stderr) + ran = self.cut_patch("v0.1.0") + self.assertEqual(ran.returncode, 1) + self.assertIn(self.git(self.clone, "rev-parse", "v0.1.0^{commit}")[:12] + " is in v0.1.0 already", ran.stderr) self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + def test_refuses_a_commit_origins_main_doesnt_hold(self): + self.plan_patch() + self.commit({"tool.txt": "local\n"}, "Unpushed") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn(self.git(self.clone, "rev-parse", "HEAD")[:12] + " isn't on origin/main", ran.stderr) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_leaves_out_the_commits_a_merge_of_main_brought_into_the_chunk(self): + self.commit({"todo.md": TODO + ROW.format(id=2, release="0.3.0") + ROW.format(id=3, release="0.1.1")}, "File item 3") + base = self.git(self.clone, "rev-parse", "HEAD").strip() + self.commit({"feature.txt": "new\n"}, "Add a feature") + self.git(self.clone, "switch", "-q", "-c", "chunk", base) + self.git(self.clone, "merge", "-q", "--no-ff", "-m", "Sync with main", "main") + self.commit({"tool.txt": "fixed\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0"), "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Fix item 3") + head = self.git(self.clone, "rev-parse", "HEAD").strip() + self.git(self.clone, "switch", "-q", "main") + self.git(self.clone, "merge", "-q", "--ff-only", "chunk") + self.git(self.clone, "push", "-q", "origin", "main") + ran = self.cut_patch(f"{base}..{head}") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertNotIn("feature.txt", self.origin_git("ls-tree", "--name-only", "v0.1.1")) + self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n") + + def test_says_which_commits_the_patch_ships_before_it_applies_them(self): + ran = self.cut_patch(self.plan_patch()) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn("deploy-release: ships " + self.git(self.clone, "log", "-1", "--format=%h %s", "HEAD").strip(), ran.stderr) + self.assertNotIn("Add a feature", ran.stderr) + + def test_refuses_on_a_github_origin_whose_merge_would_drop_the_tag_from_main(self): + commits = self.plan_patch() + self.use_github() + ran = self.cut_patch(commits) + self.assertEqual(ran.returncode, 1) + self.assertIn("GitHub", ran.stderr) + self.assertEqual(self.forge_state()["calls"], []) + self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "") + + def test_a_rerun_refuses_a_pushed_tag_cut_from_other_commits(self): + self.set_checks("failure") + commits = self.plan_patch() + self.assertEqual(self.cut_patch(commits).returncode, 1) + self.commit({"tool.txt": "fixed twice\n", "CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n- Fixed twice.\n\n## 0.1.0\n\n- First.\n"}, "Fix item 3 again") + self.git(self.clone, "push", "-q", "origin", "main") + self.set_checks("success") + ran = self.cut_patch("HEAD") + self.assertEqual(ran.returncode, 1) + self.assertIn("other changelog entries", ran.stderr) + self.assertNotIn("Fixed twice", self.origin_git("show", "main:CHANGELOG.md").split("## 0.1.0")[0].split("## Unreleased")[0]) + def test_refuses_commits_that_add_no_changelog_entry_under_unreleased(self): self.plan_patch() self.commit({"tool.txt": "fixed again\n"}, "Fix more") @@ -593,7 +641,7 @@ class Cut(unittest.TestCase): self.assertIn("usage", ran.stderr) self.assertEqual(self.forge_state()["calls"], []) - def test_takes_no_option_but_cut(self): + def test_refuses_an_option_it_does_not_know(self): ran = subprocess.run([sys.executable, str(TOOL), "--cut", "--force"], capture_output=True, cwd=self.clone, env=self.env, text=True) self.assertEqual(ran.returncode, 1) self.assertIn("usage", ran.stderr) @@ -618,7 +666,7 @@ class PatchChangelog(unittest.TestCase): def test_heads_the_tags_changelog_with_the_patchs_section(self): self.assertEqual(patch.headed("# Changelog\n\n## 0.1.0\n\n- First.\n", ["- Fixed.", "- Also."], "0.1.1"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n- Also.\n\n## 0.1.0\n\n- First.\n") - def test_ends_a_changelog_with_no_section_with_the_patchs_section(self): + def test_appends_the_patchs_section_to_a_changelog_without_sections(self): self.assertEqual(patch.headed("# Changelog\n\nFor Linux and macOS X\n\n", ["- Fixed."], "0.1.1"), "# Changelog\n\nFor Linux and macOS X\n\n## 0.1.1\n\n- Fixed.\n") def test_moves_the_patchs_entries_from_unreleased_to_a_section_after_it(self): diff --git a/bin/release_plan/release_standing.py b/bin/release_plan/release_standing.py index 427b5371..e4ef5bc8 100644 --- a/bin/release_plan/release_standing.py +++ b/bin/release_plan/release_standing.py @@ -138,14 +138,15 @@ def heading_commit(release: Release, ref: str, changelog: stores.RecordStore, cw def release_reviewed(tag: str | None, ref: str, cwd: str, titles: templates.Titles, after: Release | None = None, run: Git = git) -> bool | Failure: """Whether ref holds a commit titled as a release review opens, `Release review of `: after tag, or anywhere where tag is None. A title that names no version, such as an epic's `Release review of ABC-12` (do_epic/finish.py), reviews no release. - titles holds the project's title templates, and each commit title is read as the summary they give. after is the version a branch with no tag counts as cut, or None. Where it is given, a title counts only where its release is later than after. + titles holds the project's title templates, and each commit title is read as the summary they give. after is the version a branch with no tag counts as cut, or None. A title counts only where its release is later than after, or than tag's version where after is None. A patch release cut beside the default branch and merged back leaves on ref, after its tag, the review of that patch, which reviews no later release. """ log = run("log", "--format=%s", f"{tag}..{ref}" if tag else ref, cwd=cwd) if isinstance(log, Failure): return log summaries = [titles.summary(line) for line in log.splitlines()] reviews = [summary.removeprefix("Release review of ") for summary in summaries if summary.startswith("Release review of ")] - return any((named := parsed(review)) is not None and (after is None or named > after) for review in reviews) + floor = after if after is not None else tagged(tag) + return any((named := parsed(review)) is not None and (floor is None or named > floor) for review in reviews) def todos_since(tag: str | None | Failure, ref: str, plan: str | None, cwd: str, run: Git = git) -> list[str] | Failure: diff --git a/bin/release_plan/test_release_standing.py b/bin/release_plan/test_release_standing.py index 36c52749..349f5854 100644 --- a/bin/release_plan/test_release_standing.py +++ b/bin/release_plan/test_release_standing.py @@ -236,6 +236,24 @@ class ChunkItem(unittest.TestCase): self.assertIs(release_standing.project_plan(dataclasses.replace(config, commit_title="PAY-{id} - {summary}"), "main", repo).cut.reviewed, True) self.assertIs(release_standing.project_plan(dataclasses.replace(config, pull_request_title="PAY-{id} - {summary}"), "main", repo).cut.reviewed, True) + def test_counts_no_release_review_of_the_patch_release_cut_beside_main_as_a_review_of_the_next(self): + repo = tempfile.mkdtemp() + self.addCleanup(subprocess.run, ["rm", "-rf", repo]) + run = lambda *args: subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], capture_output=True, check=True, cwd=repo, env=isolated_env(), text=True) + run("init", "-q", "-b", "main") + run("commit", "-q", "--allow-empty", "-m", "Cut release 0.15.1") + run("tag", "v0.15.1") + run("commit", "-q", "--allow-empty", "-m", "Release review of 0.15.2") + run("switch", "-q", "--detach", "v0.15.1") + run("commit", "-q", "--allow-empty", "-m", "Cut release 0.15.2") + run("tag", "v0.15.2") + run("switch", "-q", "main") + run("merge", "-q", "--strategy", "ours", "--no-ff", "-m", "Merge release 0.15.2 into main", "v0.15.2") + # v0.15.2..main holds the review, which reviewed 0.15.2 itself, so 0.16.0 still waits for its own. + self.assertIs(release_standing.release_reviewed("v0.15.2", "main", repo, BARE), False) + run("commit", "-q", "--allow-empty", "-m", "Release review of 0.16.0") + self.assertIs(release_standing.release_reviewed("v0.15.2", "main", repo, BARE), True) + def test_counts_no_release_review_of_a_release_cut_under_a_dated_heading_on_a_branch_with_no_tag(self): repo = tempfile.mkdtemp() self.addCleanup(subprocess.run, ["rm", "-rf", repo]) diff --git a/docs/decisions.md b/docs/decisions.md index 17e09a93..2442b5a4 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -150,11 +150,11 @@ The cap is 5, `bin/plan/todo_table.py`'s `BUNDLE_MAX_R`, from the same chunks: b Valid while `~/.claude` is a checkout of this repo. -## deploy: `deploy-release --cut` cuts a release through a pull request merged fast-forward only, then tags the merged commit and moves `~/.claude` to it; the human runs it +## deploy: `deploy-release --cut` cuts a release through a pull request merged fast-forward only, then tags the merged commit and moves `~/.claude` to it, and `--cut-patch` tags a patch of the newest tag beside `main`, then merges the tag back; the human runs both 2026-11-08, lilleman, todo item 271. Serves goal 1.5 and goal 2. Nobody can push to `main` on the remote, and it merges only by fast-forward, so a cut that commits on `main` and pushes no longer works. The tool cuts only the release `chunk-preflight` would call ready to cut, through `bin/release_plan/release_standing.py`, so the two never disagree on which release is next or whether it is ready; the version is that release's, never the tool's choice. It builds the cut commit in a worktree of its own, so the clone's checkout stays as it is. It finds the merged commit on `main` by its title, `Cut release `, since GitHub's nearest merge, a rebase merge, may give the commit a new hash. It takes only a pull request from origin's own branch whose head is the commit that branch points at, and has the forge merge it only while its head is still that commit, so a fork's pull request from a branch of the same name, or a push after the checks passed, is never merged and deployed. Each step first checks whether an earlier run did it, so a rerun continues. Releases stay the human's, so the human runs it, and the forge credentials stay theirs. Valid while `main` takes changes only through a pull request. -2026-11-24, todo item 536. `deploy-release --cut-patch ` cuts the newest tag's next patch release, holding only the commits named, for a fix that must ship before `main`'s other unreleased work, as 0.15.1 did by hand. Its commit sits on the tag, not on `main`, so no pull request can merge it, and CI runs only on pull requests: the tool runs `ci.sh` on it, as CI does, before it tags. Then it merges the tag back into `main` with `-s ours` through a pull request, so the tag is in `main`'s history, where the next cut and `chunk-preflight` read it. A patch skips the release review: it holds only fixes, and the review reads the whole project. `chunk-preflight` still calls that review due until the patch is cut, so cut a patch as soon as its fix merges. Plain `--cut` refuses a patch of the newest tag, since it would ship all of `main` under a patch number. +2026-11-24, lilleman, todo item 536. `deploy-release --cut-patch ` cuts the newest tag's next patch release, holding only the commits named, for a fix that must ship before `main`'s other unreleased work. Before it, 0.15.1 was cut by those steps by hand. The patch's commit has the tag as its parent, not `main`'s head, so no pull request into `main` can merge it, and CI runs only on pull requests: the tool runs `ci.sh` on it, as CI does, before it tags. Then it merges the tag back into `main` with `-s ours` through a pull request, so the tag is in `main`'s history, where the next cut and `chunk-preflight` read it, and a release review on `main` counts only for a release later than the last cut. GitHub's rebase merge would drop that merge commit, so the tool refuses a GitHub origin. A patch skips the release review: `chunk-preflight` still calls it due until the patch is cut, so cut a patch as soon as its fix merges. Plain `--cut` refuses a patch of the newest tag, since it would ship all of `main` under a patch number. A panel of three readers seated as the owner picked the spelling `--cut-patch` over `--cut --patch` and `--hotfix`: one flag that names the action, which can't be read as a plain `--cut`. ## do-epic: drives one Jira epic whose items span repos, or have none, ranked by the epic's goals, then code health, then each repo's goals, and closes the epic only once the human confirms every goal diff --git a/todo.md b/todo.md index 0ec382db..bb1fd1cc 100644 --- a/todo.md +++ b/todo.md @@ -128,22 +128,22 @@ Touches: Today a fix that must ship before `main`'s other unreleased work is cut by hand, as 0.15.1 was: branch off the newest tag, apply only the fix's code, write the changelog section, commit `Cut release `, tag and push, then merge the tag back into `main` with `-s ours` through a pull request, so the tag is an ancestor of `main`, and run a bare `deploy-release`. `deploy-release --cut` can't, since it cuts all of `main`. -`deploy-release --cut-patch []`, run in the development clone, does those steps. A reader panel picked the spelling over `--cut --patch` and `--hotfix`: one flag that names the action and can't be read as a plain `--cut`. +`deploy-release --cut-patch []`, run in the development clone, does those steps; `docs/decisions.md` → "deploy: `deploy-release --cut` cuts a release …" says why it is spelled so. - **Version:** the newest tag's next patch, such as 0.15.2 after v0.15.1. The plan must name that release, and it must hold no item, as `--cut` checks. A patch skips the release review: it holds only fixes, and the review is of the whole project. - **Commits:** one revision as `git log` reads it, such as `794ce37..1aa2367`, which follows git's `..` and leaves out the first commit, or one commit. Each must be on `origin/main` and not on the tag. Merge commits are skipped. - **Patch:** in a worktree of its own, at the tag, it applies each commit's changes except to `todo.md`, `CHANGELOG.md` and the records every chunk writes. The changelog section is the bullets the commits add under `## Unreleased`. It commits `Cut release `, runs `ci.sh` on it, and stops where that fails. Then it tags and pushes the tag. - **Merge-back:** a branch `release-` off `origin/main` merges the tag with `-s ours` and moves those bullets under `## `, and goes through a pull request as `--cut`'s branch does. -- **Rerun:** a step an earlier run finished is skipped: a tag on origin, a tag `main` holds. +- **Rerun:** it takes a tag origin holds, once the tag lists the same changelog entries, and the merge-back's open pull request. - **Plain `--cut`** refuses a patch release and names `--cut-patch`, since it would ship all of `main` under a patch number. Touches: +- `README.md`: `## Release`, `## Tools` (small) +- `bin/deploy_release/cut.py`: `cut`, `land`, `push_cut_commit`, `ready_release` - `bin/deploy_release/main.py`: `main` -- `bin/deploy_release/cut.py`: `cut`, `ready_release`, `land`, `push_cut_commit` - `bin/deploy_release/patch.py` - `bin/deploy_release/release_pull.py`: `create_pull` (small) - `bin/deploy_release/test_deploy_release.py`: `Cut` -- `README.md`: `## Release`, `## Tools` (small) ### 524. Write fejkdata's first six bench features, each a spec, acceptance tests in Go and a reference patch that builds it, in the `bench-tasks` folder its config names. @@ -322,7 +322,7 @@ Name the entry and the Dockerfile line. Source the secret-name list from a widel Found while shipping item 461: `mutate-changes` printed `23 mutants on changed lines, 18 not killed. Left out the tests that fail without a mutant, in do_epic/test_main.py, larv_review/test_larv_review.py, larv_review/test_scoring_setup.py, plan/test_ranking.py, repo_checks/…, review_rules/test_review_passes.py, review_rules/test_reviewer_context.py, rule_hook/test_rule_hook.py, test_settings_filter.py`. All 18 survivors were in `bin/larv_review/scoring_setup.py`: `prepare_scoring`, whose tests are among those left out, so the chunk checked four of them by hand and left 14 unchecked. Find why each left-out test fails in mutmut's copy, such as a path to `skills/` or a git checkout it expects, and make it pass there, or report under the count which changed lines no remaining test covers. -Item 536 met it too: `deploy_release/test_deploy_release.py`, which runs `deploy-release` as a subprocess, fails there, so none of 597 mutants of `bin/deploy_release/` was checked. +Item 536 met the same gap: `deploy_release/test_deploy_release.py` runs `deploy-release` as a subprocess, and those tests fail in mutmut's copy, so only its in-process tests ran, and 530 of 590 mutants of `bin/deploy_release/` went unchecked. Touches `bin/mutate_changes/`, and the tests named above.