Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a38dad4a6c | |||
| a1e6791cdb | |||
| 0a38f99a8d | |||
| 010be0c9e7 | |||
| db32e4ef59 | |||
| ec497aa989 | |||
| 3f74d32cae | |||
| 39cb2f4d9e | |||
| 459a3d5f54 | |||
| 366a10cc0e | |||
| 2cdd346060 | |||
| 9c2587b5ca | |||
| 80de753b9e |
@@ -2,6 +2,7 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- `deploy-release --cut-patch <commits>` cuts the newest tag's next patch release, such as 0.15.2 after v0.15.1, holding only the commits named, for a fix that must ship before main's other unreleased work. It runs `ci.sh` on the patch, tags and pushes it, merges the tag back into main through a pull request, and moves `~/.claude` to it. Plain `--cut` now refuses a patch release, and a release review counts only for a release later than the last cut.
|
||||
- `task-bench` plants bugs in Rust files too, from the mutants cargo-mutants catches, and tells Haiku the panic message `cargo test` prints.
|
||||
- `task-bench --tasks shipped-features` benches rebuilding features the project shipped: it takes each one's change out of the code, tells Haiku the tagline of its plan item, and checks the build with the tests that change holds. `--shipped <n>` sets how many it takes, and a feature whose branch landed by fast-forward is passed over.
|
||||
- `task-bench` plants a Python mutant in a file whose lines end in CRLF, which it could not re-apply before, and a Go mutant there keeps applying.
|
||||
|
||||
@@ -198,6 +198,14 @@ 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<version>`, 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 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. 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
|
||||
|
||||
Install puts only `loop-claude` on `PATH`; call the others by their path, such as `~/.claude/bin/metric-bench`, from the project's checkout. Those under `~/.claude` are the release's; test a change to one from `~/code/claude-config/bin`. The tools are listed in alphabetical order, and the packages under `bin/` follow under their own heading.
|
||||
@@ -206,7 +214,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a
|
||||
- `chunk-preflight` finds the mechanical facts a chunk starts from, and with `--worktree` makes its worktree; `loop-claude` runs it with `--worktree` before it routes each chunk, and `chunk-preflight --help` lists the facts.
|
||||
- `command-patterns [<version>] [--calls <file>]` prints a table of the shell command patterns a release's archived chunks ran, such as `tea pr create`, for an audit of the release, and with `--calls <file>` saves each call as a JSON line; `command-patterns --help` states the columns and the line's keys.
|
||||
- `compress-archives` gzips each transcript in loop-claude's archive and each file in the review folders 30 days after it last changed, keeping all of them; Install's crontab line runs it daily.
|
||||
- `deploy-release [--cut] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, as Release says.
|
||||
- `deploy-release [--cut | --cut-patch <commits>] [<checkout>]` moves `~/.claude`, or the checkout named, to the newest release, as Update says; with `--cut`, run in the development clone, it first cuts the next release, and with `--cut-patch`, a patch release of only the commits named, as Release says.
|
||||
- `do-epic <EPIC-KEY>` runs the chunks of one Jira epic whose items span repos, or have none, each in its own window of the tmux session `epic-<EPIC-KEY>`, on the same cycle, judge and interrupt as loop-claude. The epic's description is its record: goals, audience, scoring and decisions. Before it starts chunks, do-epic plans each open issue that no label places yet, as "Set up a project" says. It files a sub-task per repo where the issue changes several repos. Otherwise it labels the issue with where it is worked, and asks you where that is unclear. It plans no issue your team filed a sub-task under: those sub-tasks run instead, each under a label of its own, and your team closes the issue. Then, where two or more issues may start, it scores each of them that holds no scores, and moves the issues that do-epic itself filed into order of score on the board. An open issue runs once a label names its repo or marks it as Claude's, in order of score, as many at once as a line such as `**Max parallel chunks:** 2` in the epic's description allows, 1 without it, and as each repo's `parallel-chunks` allows. A chunk whose pull request waits on a gate parks. An open task of yours that blocks another issue gets a window that DMs you once and reads the epic every minute; once you close the task, the issues it blocked may start. `do-epic <EPIC-KEY> --dry-run` prints what `do-epic <EPIC-KEY>` would write to Jira and which chunks it would start, and does neither; run it before the first real run on a team's epic. `--help` lists what it prints and leaves out. do-epic closes the epic only once you confirm every goal. Install → "Set up a project" says how to set it up; `do-epic --help` states the flags and the contract.
|
||||
- `do-epic-e2e` runs `do-epic` against a sandbox epic on a real Jira site, as Test says.
|
||||
- `judge-replay <model> [--offline]` replays loop-claude's judge on archived verdicts of the projects run on the model. It prints what each rung a review climbs to misses, and the lowest rung below those that returns every verdict, as each candidate above it does. With `--offline` it doesn't call a judge: it counts what a "?" rule, a decision table and a classifier trained on the archive decide of each verdict's kind from the worker's final message, and how many interrupts each misses. `judge-replay --help` states both replays.
|
||||
|
||||
+56
-21
@@ -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
|
||||
@@ -16,12 +17,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 +41,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 +65,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)
|
||||
@@ -100,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
|
||||
|
||||
|
||||
@@ -116,8 +134,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 +147,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 +170,14 @@ 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 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
|
||||
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 +186,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 +194,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):
|
||||
@@ -206,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:
|
||||
@@ -218,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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Move the checkout Claude Code reads its configuration from to this repo's newest release; with --cut, first cut the next release.
|
||||
"""Move the checkout Claude Code reads its configuration from to this repo's newest release; with --cut, first cut the next release, and with --cut-patch, a patch release of only the commits named.
|
||||
|
||||
usage: deploy-release [--cut] [<checkout>]
|
||||
usage: deploy-release [--cut | --cut-patch <commits>] [<checkout>]
|
||||
|
||||
<checkout> defaults to ~/.claude. The tool fetches origin's tags and checks out the newest v* tag,
|
||||
detached, so the checkout holds only what a release holds. Development happens in another clone,
|
||||
@@ -18,7 +18,9 @@ memory, stay as they are.
|
||||
|
||||
--cut runs in the development clone, and refuses where that clone's origin isn't <checkout>'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 <version>`, and pushes it as the branch release-<version>. The clone's own
|
||||
checkout stays as it is. Where main has moved past the branch, it rebuilds the branch on main.
|
||||
@@ -35,6 +37,28 @@ Where a step fails it stops, exit 1, with git's or the forge's reason, and leave
|
||||
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-patch <commits> 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, holding only <commits> on top of the tag. <commits> 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 <version>`. 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<version>, annotated `Cut release <version>`, 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
|
||||
## <version> section below it, commits that titled `Merge release <version> into main`, and lands it through the branch
|
||||
release-<version> and a pull request as --cut does. Then it checks main holds the tag.
|
||||
6. It moves <checkout> 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
|
||||
@@ -42,6 +66,7 @@ import sys
|
||||
import time
|
||||
|
||||
from deploy_release.cut import cut
|
||||
from deploy_release.patch import cut_patch
|
||||
from deploy_release.deploy import deploy
|
||||
from failure import Failure
|
||||
|
||||
@@ -50,13 +75,17 @@ def main(argv: list[str]) -> int:
|
||||
if argv[:1] in (["-h"], ["--help"]):
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
cutting = argv[:1] == ["--cut"]
|
||||
rest = argv[1:] if cutting else argv
|
||||
if len(rest) > 1 or rest[:1] and rest[0].startswith("-"):
|
||||
print("deploy-release: usage: deploy-release [--cut] [<checkout>]", file=sys.stderr)
|
||||
cutting, patching = argv[:1] == ["--cut"], argv[:1] == ["--cut-patch"]
|
||||
commits = argv[1] if patching and len(argv) > 1 else None
|
||||
rest = argv[2:] if patching else argv[1:] if cutting else argv
|
||||
if len(rest) > 1 or rest[:1] and rest[0].startswith("-") or patching and (commits is None or commits.startswith("-")):
|
||||
print("deploy-release: usage: deploy-release [--cut | --cut-patch <commits>] [<checkout>]", file=sys.stderr)
|
||||
return 1
|
||||
checkout = rest[0] if rest else str(pathlib.Path.home() / ".claude")
|
||||
moved = cut(os.getcwd(), checkout, time.sleep) if cutting else deploy(checkout)
|
||||
if commits is not None:
|
||||
moved = cut_patch(os.getcwd(), checkout, commits, time.sleep)
|
||||
else:
|
||||
moved = cut(os.getcwd(), checkout, time.sleep) if cutting else deploy(checkout)
|
||||
if isinstance(moved, Failure):
|
||||
print(f"deploy-release: {moved.reason}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
@@ -0,0 +1,235 @@
|
||||
"""`deploy-release --cut-patch <commits>`: 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.
|
||||
|
||||
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 subprocess
|
||||
import typing
|
||||
|
||||
from git_cli.git_repo import default_ref, git
|
||||
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 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 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 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):
|
||||
return dropped
|
||||
ref = default_ref(cwd=clone)
|
||||
if isinstance(ref, Failure):
|
||||
return ref
|
||||
base = newest_tag(clone, merged_into=ref)
|
||||
if isinstance(base, Failure):
|
||||
return base
|
||||
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):
|
||||
return release
|
||||
if version(release) != named:
|
||||
return Failure(f"the next release in todo.md is {version(release)}, not {named}, the patch of {base}: file the fix under {named}")
|
||||
picked = patch_commits(clone, ref, base, commits)
|
||||
if isinstance(picked, Failure):
|
||||
return picked
|
||||
entries = changelog_entries(clone, ref, picked)
|
||||
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, 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 that isn't a merge: write a range as <older>..<newer>")
|
||||
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")
|
||||
if not isinstance(git("merge-base", "--is-ancestor", commit, base, cwd=clone), Failure):
|
||||
return Failure(f"{commit[:12]} is in {base} already")
|
||||
return picked
|
||||
|
||||
|
||||
def changelog_entries(clone: str, ref: str, commits: list[str]) -> list[str] | Failure:
|
||||
"""The entries under ref's ## Unreleased in CHANGELOG.md that commits added, in the order ref lists them; a Failure where they added none."""
|
||||
added: set[str] = set()
|
||||
for commit in commits:
|
||||
diff = git("diff", f"{commit}^", commit, "--", "CHANGELOG.md", cwd=clone)
|
||||
if isinstance(diff, Failure):
|
||||
return diff
|
||||
added |= {line[1:] for line in diff.splitlines() if line.startswith("+- ")}
|
||||
changelog = git("show", f"{ref}:CHANGELOG.md", cwd=clone)
|
||||
if isinstance(changelog, Failure):
|
||||
return changelog
|
||||
entries = [line for line in section(changelog, UNRELEASED_TITLE) or [] if line in added]
|
||||
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 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 under ## {patch.named} than the commits named added under ## Unreleased. The tag lists:\n" + "\n".join(listed) + "\nThe commits added:\n" + "\n".join(patch.entries))
|
||||
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 <version>`, 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", patch.entries, patch.named))
|
||||
if isinstance(committed := git("commit", "--quiet", "--all", "--message", title, cwd=str(worktree)), Failure):
|
||||
return committed
|
||||
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):
|
||||
return made
|
||||
if isinstance(pushed := git("push", "--quiet", "origin", f"refs/tags/{tag}", cwd=clone), Failure):
|
||||
# Until a rerun, chunk-preflight would read a tag only the clone holds as cut.
|
||||
git("tag", "--delete", tag, cwd=clone)
|
||||
return pushed
|
||||
said(f"pushed the tag {tag}")
|
||||
return None
|
||||
|
||||
|
||||
def headed(changelog: str, entries: list[str], named: str) -> str:
|
||||
"""changelog with a ## named section holding entries before its first ## section, or at its end where it has none."""
|
||||
added = f"## {named}\n\n" + "\n".join(entries) + "\n"
|
||||
first = re.search(r"^## ", changelog, flags=re.M)
|
||||
if first is None:
|
||||
return changelog.rstrip() + "\n\n" + added
|
||||
return changelog[:first.start()] + added + "\n" + changelog[first.start():]
|
||||
|
||||
|
||||
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_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 {patch.base}: {applied.reason}. "
|
||||
f"Cut the patch by hand: on {patch.base}, apply the fix and add a ## {patch.named} section to CHANGELOG.md, commit that titled `Cut release {patch.named}`, "
|
||||
f"tag it v{patch.named}, annotated with that title, and push the tag. A rerun with the same commits then merges it back and deploys it, "
|
||||
f"where the section holds exactly these lines:\n" + "\n".join(patch.entries)
|
||||
)
|
||||
return 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")
|
||||
ran = subprocess.run(["sh", "ci.sh"], capture_output=True, cwd=worktree, text=True, errors="replace")
|
||||
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. 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, 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 ## <version> section below ## Unreleased, and push that as the branch release-<version>, 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(), 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
|
||||
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 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))
|
||||
kept = [line for line in lines[start + 1:end] if line not in entries]
|
||||
while kept and not kept[-1].strip():
|
||||
kept.pop()
|
||||
return "\n".join([*lines[:start + 1], *kept, "", f"## {named}", "", *entries, "", *lines[end:]])
|
||||
@@ -6,10 +6,10 @@ from failure import Failure
|
||||
from forge.commands import Forge, gitea, Run
|
||||
|
||||
|
||||
def create_pull(forge: Forge, branch: str, base: str, title: str, run: Run) -> Failure | None:
|
||||
body = ["--body" if forge == "gh" else "--description", "Rename ## Unreleased in CHANGELOG.md to the version."]
|
||||
def create_pull(forge: Forge, branch: str, base: str, title: str, body: str, run: Run) -> Failure | None:
|
||||
described = ["--body" if forge == "gh" else "--description", body]
|
||||
command = ["gh", "pr"] if forge == "gh" else ["tea", "pulls"]
|
||||
created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *body])
|
||||
created = run([*command, "create", "--head", branch, "--base", base, "--title", title, *described])
|
||||
return created if isinstance(created, Failure) else None
|
||||
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
|
||||
from failure import Failure
|
||||
from test_env import isolated_env
|
||||
from deploy_release import patch
|
||||
|
||||
TOOL = pathlib.Path(__file__).resolve().parents[1] / "deploy-release"
|
||||
|
||||
@@ -248,7 +249,7 @@ class Cut(unittest.TestCase):
|
||||
self.git(self.temp, "init", "-q", "--bare", "-b", "main", str(self.origin))
|
||||
self.clone = self.temp / "claude-config"
|
||||
self.git(self.temp, "clone", "-q", str(self.origin), str(self.clone))
|
||||
self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0")}, "Start")
|
||||
self.commit({"CHANGELOG.md": "# Changelog\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=1, release="0.2.0") + ROW.format(id=2, release="0.3.0"), "tool.txt": "broken\n", "ci.sh": "exit 0\n"}, "Start")
|
||||
self.git(self.clone, "tag", "-a", "v0.1.0", "-m", "Cut release 0.1.0")
|
||||
self.commit({"CHANGELOG.md": "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.0\n\n- First.\n", "todo.md": TODO + ROW.format(id=2, release="0.3.0")}, "Ship item 1")
|
||||
self.git(self.clone, "commit", "-q", "--allow-empty", "-m", "Release review of 0.2.0")
|
||||
@@ -469,7 +470,196 @@ class Cut(unittest.TestCase):
|
||||
self.assertEqual(self.cut().returncode, 1, "0.2.0 is cut, so a second run refuses")
|
||||
self.assertEqual(self.git(self.clone, "tag", "-l", "v0.2.0", "v9.9.9").split(), ["v0.2.0", "v9.9.9"])
|
||||
|
||||
def test_takes_no_option_but_cut(self):
|
||||
def plan_patch(self, fix: dict[str, str] | None = None) -> str:
|
||||
"""On top of setUp's main: a feature no patch may ship, item 3 filed under 0.1.1, then the commit that fixes tool.txt and finishes item 3, pushed. The revision range that names only the fix."""
|
||||
self.commit({"feature.txt": "new\n"}, "Add a feature")
|
||||
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({"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 or {})}, "Fix item 3")
|
||||
head = self.git(self.clone, "rev-parse", "HEAD").strip()
|
||||
self.git(self.clone, "push", "-q", "origin", "main")
|
||||
return f"{base}..{head}"
|
||||
|
||||
def cut_patch(self, *commits: str) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run([sys.executable, str(TOOL), "--cut-patch", *commits, str(self.target)], capture_output=True, cwd=self.clone, env=self.env, text=True)
|
||||
|
||||
def test_cuts_a_patch_of_the_newest_tag_holding_only_the_named_commits_then_merges_the_tag_back_and_deploys_it(self):
|
||||
ran = self.cut_patch(self.plan_patch())
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertEqual(self.origin_git("cat-file", "-t", "v0.1.1").strip(), "tag", "the tag is annotated")
|
||||
self.assertEqual(self.origin_git("tag", "-l", "--format=%(contents:subject)", "v0.1.1").strip(), "Cut release 0.1.1")
|
||||
self.assertEqual(self.origin_git("log", "-1", "--format=%s", "v0.1.1").strip(), "Cut release 0.1.1")
|
||||
self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}~1"), self.origin_git("rev-parse", "v0.1.0^{commit}"))
|
||||
self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n")
|
||||
self.assertEqual(self.origin_git("show", "v0.1.1:CHANGELOG.md"), "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
|
||||
self.assertEqual(self.origin_git("show", "v0.1.1:todo.md"), self.origin_git("show", "v0.1.0:todo.md"))
|
||||
self.assertNotIn("feature.txt", self.origin_git("ls-tree", "--name-only", "v0.1.1"))
|
||||
self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main")
|
||||
self.assertEqual(self.origin_git("log", "-1", "--format=%s", "main").strip(), "Merge release 0.1.1 into main")
|
||||
self.assertEqual(self.origin_git("show", "main:CHANGELOG.md"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
|
||||
self.assertEqual(self.origin_git("show", "main:feature.txt"), "new\n")
|
||||
self.assertIn(["tea", "pulls", "create", "--head", "release-0.1.1", "--base", "main"], [call[:7] for call in self.forge_state()["calls"]])
|
||||
self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "v0.1.1")
|
||||
self.assertIn("Done: v0.1.1 is cut and pushed", ran.stdout)
|
||||
|
||||
def test_takes_one_commit_as_the_patch(self):
|
||||
head = self.plan_patch().split("..")[1]
|
||||
ran = self.cut_patch(head)
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertEqual(self.origin_git("show", "v0.1.1:tool.txt"), "fixed\n")
|
||||
|
||||
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")
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("0.1.1", ran.stderr)
|
||||
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
|
||||
self.assertEqual(self.forge_state()["pulls"], [])
|
||||
|
||||
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")
|
||||
ran = self.cut_patch("HEAD~1")
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("still holds items", ran.stderr)
|
||||
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
|
||||
|
||||
def test_skips_the_release_review_a_patch_would_otherwise_wait_for(self):
|
||||
self.git(self.clone, "reset", "-q", "--hard", "HEAD~1")
|
||||
self.git(self.clone, "push", "-q", "--force", "origin", "main")
|
||||
ran = self.cut_patch(self.plan_patch())
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
|
||||
def test_refuses_a_commit_the_tag_holds(self):
|
||||
self.plan_patch()
|
||||
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_merges_back_and_deploys_a_patch_cut_by_hand_as_the_refusal_says(self):
|
||||
self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main")
|
||||
commits = self.plan_patch()
|
||||
refused = self.cut_patch(commits)
|
||||
self.assertEqual(refused.returncode, 1)
|
||||
self.assertIn("exactly these lines:\n- Fixed.", refused.stderr)
|
||||
self.git(self.clone, "switch", "-q", "--detach", "v0.1.0")
|
||||
self.commit({"tool.txt": "fixed\n", "CHANGELOG.md": "# Changelog\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n"}, "Cut release 0.1.1")
|
||||
self.git(self.clone, "tag", "-a", "v0.1.1", "-m", "Cut release 0.1.1")
|
||||
self.git(self.clone, "push", "-q", "origin", "v0.1.1")
|
||||
self.git(self.clone, "switch", "-q", "main")
|
||||
tagged = self.origin_git("rev-parse", "v0.1.1^{commit}")
|
||||
ran = self.cut_patch(commits)
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}"), tagged)
|
||||
self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main")
|
||||
self.assertEqual(self.git(self.target, "describe", "--tags", "--exact-match", "HEAD").strip(), "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("The tag lists:\n- Fixed.\nThe commits added:\n- Fixed twice.", 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")
|
||||
self.git(self.clone, "push", "-q", "origin", "main")
|
||||
ran = self.cut_patch("HEAD")
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("## Unreleased", ran.stderr)
|
||||
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
|
||||
|
||||
def test_stops_before_tagging_where_ci_fails_on_the_patch(self):
|
||||
ran = self.cut_patch(self.plan_patch({"ci.sh": "echo the suite failed >&2\nexit 1\n"}))
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("ci.sh", ran.stderr)
|
||||
self.assertIn("the suite failed", ran.stderr)
|
||||
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
|
||||
self.assertEqual(self.git(self.clone, "tag", "-l", "v0.1.1"), "")
|
||||
self.assertEqual(self.forge_state()["pulls"], [])
|
||||
|
||||
def test_stops_naming_the_commit_that_does_not_apply_on_the_tag(self):
|
||||
self.commit({"tool.txt": "half fixed\n"}, "Change tool.txt on main")
|
||||
ran = self.cut_patch(self.plan_patch())
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("Fix item 3", ran.stderr)
|
||||
self.assertIn("v0.1.0", ran.stderr)
|
||||
self.assertEqual(self.origin_git("tag", "-l", "v0.1.1"), "")
|
||||
|
||||
def test_a_rerun_after_a_failed_merge_back_check_keeps_the_pushed_tag_and_merges_back(self):
|
||||
self.set_checks("failure")
|
||||
commits = self.plan_patch()
|
||||
ran = self.cut_patch(commits)
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
tagged = self.origin_git("rev-parse", "v0.1.1^{commit}")
|
||||
self.set_checks("success")
|
||||
ran = self.cut_patch(commits)
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
self.assertEqual(self.origin_git("rev-parse", "v0.1.1^{commit}"), tagged)
|
||||
self.origin_git("merge-base", "--is-ancestor", "v0.1.1", "main")
|
||||
|
||||
def test_plain_cut_refuses_a_patch_release_and_names_cut_patch(self):
|
||||
self.plan_patch()
|
||||
ran = self.cut()
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("--cut-patch", ran.stderr)
|
||||
self.assertEqual(self.forge_state()["pulls"], [])
|
||||
|
||||
def test_cut_patch_needs_its_commits(self):
|
||||
ran = subprocess.run([sys.executable, str(TOOL), "--cut-patch"], capture_output=True, cwd=self.clone, env=self.env, text=True)
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
self.assertIn("usage", ran.stderr)
|
||||
self.assertEqual(self.forge_state()["calls"], [])
|
||||
|
||||
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)
|
||||
@@ -488,5 +678,26 @@ class Cut(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
class PatchChangelog(unittest.TestCase):
|
||||
"""The changelog edits of a patch cut, read in-process, so a mutation tester reaches them."""
|
||||
|
||||
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_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):
|
||||
changelog = "# Changelog\n\n## Unreleased\n\n- Second.\n- Fixed.\n\n## 0.1.0\n\n- First.\n"
|
||||
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n- Second.\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- First.\n")
|
||||
|
||||
def test_leaves_an_older_section_entry_that_reads_the_same(self):
|
||||
changelog = "# Changelog\n\n## Unreleased\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n"
|
||||
self.assertEqual(patch.moved_entries(changelog, ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n\n## 0.1.0\n\n- Fixed.\n")
|
||||
|
||||
def test_puts_the_section_last_where_unreleased_is_the_last_section(self):
|
||||
self.assertEqual(patch.moved_entries("# Changelog\n\n## Unreleased\n\n- Fixed.\n", ["- Fixed."], "0.1.1"), "# Changelog\n\n## Unreleased\n\n## 0.1.1\n\n- Fixed.\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -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 <release>`: 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:
|
||||
|
||||
@@ -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])
|
||||
|
||||
+3
-1
@@ -150,10 +150,12 @@ 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 <version>`, 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, lilleman, todo item 536. `deploy-release --cut-patch <commits>` 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
|
||||
|
||||
2026-11-18, lilleman's answers to claude's questions while planning release 0.12.0. Serves goal 1, so development scales past one repo, and goal 1.6, since the epic stays in the client's Jira. Valid while Jira is the only backend; another backend goes behind the same interface.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
`Bar = 0.1`
|
||||
|
||||
`Next ID = 536`
|
||||
`Next ID = 537`
|
||||
|
||||
## Items
|
||||
|
||||
@@ -300,6 +300,8 @@ 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 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.
|
||||
|
||||
### 77. Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel.
|
||||
|
||||
Reference in New Issue
Block a user