99 lines
6.5 KiB
Python
99 lines
6.5 KiB
Python
"""Cut the next release of the clone this tool ships in; with --patch, a patch release of only the commits named.
|
|
|
|
usage: cut-release [--patch <commits>]
|
|
|
|
Run the development clone's copy, as in bin/cut-release there: it cuts that clone, whatever the directory it is run from.
|
|
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 --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,
|
|
and deletes the branch on origin. A failed delete only warns.
|
|
It says on stderr as each step finishes, and prints on stdout the line
|
|
`Done: v<version> is cut and pushed. Each clone of a release takes it with its own bin/self-update.`
|
|
It keeps each of those lines, with its time in UTC, in the run's trace: a file of its own under
|
|
$XDG_STATE_HOME/build-release/cut-release (default ~/.local/state/build-release/cut-release), named by when the run began. --patch does too.
|
|
Where Ctrl-C or an unexpected fault ends the run, the trace ends with a line that starts `stopped:`.
|
|
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.
|
|
|
|
--patch <commits> is 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 build-release 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 names on stderr the file, beside the run's trace, that takes ci.sh's output. It
|
|
stops where ci.sh fails or still runs after 30 minutes, 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 a cut without --patch does. Then it checks main holds the tag.
|
|
It prints the same `Done:` line on stdout as a cut without --patch 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.
|
|
"""
|
|
import os
|
|
import pathlib
|
|
import shlex
|
|
import sys
|
|
import time
|
|
|
|
from cut_release.ci_script import ci_runner, CI_SECONDS, removed_container
|
|
from cut_release.cut import cut
|
|
from cut_release.patch import cut_patch
|
|
from failure import Failure
|
|
from loop_state.paths import RELEASE_ROOT
|
|
from cut_release import trace
|
|
|
|
|
|
def main(argv: list[str], clone: str = str(RELEASE_ROOT)) -> int:
|
|
"""Cut the next release of clone, which is the clone this tool ships in unless a test names another."""
|
|
if argv[:1] in (["-h"], ["--help"]):
|
|
print(__doc__.strip())
|
|
return 0
|
|
if argv and (argv[0] != "--patch" or len(argv) != 2 or argv[1].startswith("-")):
|
|
print("cut-release: usage: cut-release [--patch <commits>]", file=sys.stderr)
|
|
return 1
|
|
commits = argv[1] if argv else None
|
|
now = time.time
|
|
folder, name = trace.trace_folder(os.environ, pathlib.Path.home()), trace.run_name(now(), os.getpid())
|
|
begun = trace.started(folder, name, f"{shlex.join(['cut-release', *argv])} in {clone}", now)
|
|
if isinstance(begun, Failure):
|
|
print(f"cut-release: warning: {begun.reason}", file=sys.stderr)
|
|
file = None if isinstance(begun, Failure) else begun
|
|
say = trace.saying(file, now, sys.stderr)
|
|
try:
|
|
if commits is not None:
|
|
moved = cut_patch(clone, commits, time.sleep, say, ci_runner(folder / f"{name}-ci.log", CI_SECONDS, say, f"cut-release-ci-{name}", removed_container))
|
|
else:
|
|
moved = cut(clone, time.sleep, say)
|
|
except BaseException as stopped:
|
|
# Ctrl-C or a fault nobody foresaw: its traceback reaches only the terminal, so the trace says the run ended here.
|
|
trace.kept(file, f"stopped: {stopped!r}", now, sys.stderr)
|
|
raise
|
|
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, now, sys.stderr)
|
|
return 0
|