Files
claude-config/bin/deploy_release/main.py
T

94 lines
6.6 KiB
Python

"""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 <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,
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 <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. 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.
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<version>, annotated `Cut release <version>`, pushes only the tag,
deletes the branch on origin, then moves <checkout> 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<version> is cut and pushed, and <checkout> is on it.`
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 <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
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
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 <commits>] [<checkout>]", file=sys.stderr)
return 1
checkout = rest[0] if rest else str(pathlib.Path.home() / ".claude")
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
print(moved)
return 0