65 lines
3.8 KiB
Python
65 lines
3.8 KiB
Python
"""Move the checkout Claude Code reads its configuration from to this repo's newest release; with --cut, first cut the next release.
|
|
|
|
usage: deploy-release [--cut] [<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.
|
|
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.
|
|
"""
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import time
|
|
|
|
from deploy_release.cut import cut
|
|
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 = 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)
|
|
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 isinstance(moved, Failure):
|
|
print(f"deploy-release: {moved.reason}", file=sys.stderr)
|
|
return 1
|
|
print(moved)
|
|
return 0
|