"""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 | --cut-patch ] [] 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, such as ~/code/claude-config. It prints the version it moved from and to, then CHANGELOG.md's section for each version since, so you can do what each asks, such as a new step under Install. Where the move changed settings.json, it asks you to pick the model again with /model, since git's clean filter keeps the model out of every commit. It refuses, exit 1, and leaves the checkout as it was where a file the checkout tracks has an uncommitted change the newest tag doesn't hold: such as a hook Claude Code wrote into settings.json. Merge the change through the development clone and cut a release first. A model picked with /model is no such change. It also refuses where the newest tag doesn't hold the checkout's commit, since the move would drop work no release holds. Untracked files, such as Claude Code's sessions and 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, as chunk-preflight --help counts one, 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. 2. It opens a pull request for the branch, with gh on a GitHub origin and tea elsewhere, waits for its checks where there are any, and merges it fast-forward only. On Gitea it also waits for each check main's branch protection requires to report, and names them. It gives up after 30 minutes, naming any required check that never passed. GitHub has no fast-forward merge, so there it rebase-merges the branch, which is already on top of main. 3. It tags the merged commit v, annotated `Cut release `, pushes only the tag, deletes the branch on origin, then moves to the tag as above. A failed delete only warns. It says on stderr as each step finishes, and ends stdout, after the changelog, with the line `Done: v is cut and pushed, and is on it.` It keeps each of those lines, with its time, in a file of the run's own under $XDG_STATE_HOME/deploy-release (default ~/.local/state/deploy-release), and so does --cut-patch. 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-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, 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, with its output in a file beside the run's trace, which it names on stderr. It stops where ci.sh fails or still runs after 30 minutes, 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 datetime import os import pathlib import shlex import sys import time from deploy_release.ci_script import ci_runner, CI_SECONDS from deploy_release.cut import cut from deploy_release.patch import cut_patch from deploy_release.deploy import deploy from failure import Failure from deploy_release import trace def main(argv: list[str]) -> int: if argv[:1] in (["-h"], ["--help"]): print(__doc__.strip()) return 0 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 ] []", file=sys.stderr) return 1 checkout = rest[0] if rest else str(pathlib.Path.home() / ".claude") if not cutting and commits is None: moved = deploy(checkout) if isinstance(moved, Failure): print(f"deploy-release: {moved.reason}", file=sys.stderr) return 1 print(moved) return 0 clone, now = os.getcwd(), datetime.datetime.now folder, name = trace.trace_folder(os.environ, pathlib.Path.home()), trace.run_name(now(), os.getpid()) begun = trace.started(folder, name, f"deploy-release {shlex.join([*argv[:2 if patching else 1], checkout])} in {clone}", now) if isinstance(begun, Failure): print(f"deploy-release: warning: {begun.reason}", file=sys.stderr) file = None if isinstance(begun, Failure) else begun say = trace.saying(file, now, sys.stderr) if commits is not None: moved = cut_patch(clone, checkout, commits, time.sleep, say, ci_runner(folder / f"{name}-ci.log", CI_SECONDS, say)) else: moved = cut(clone, checkout, time.sleep, say) if isinstance(moved, Failure): say(moved.reason) return 1 print(moved) # The ending is on stdout already, so only the trace takes it. trace.kept(file, moved.splitlines()[-1], now, sys.stderr) return 0