Nightly: the scheduled run deletes nightly/build-* branches older than 7 days
Ludovic's decision (2026-10-27). `nightly.py prune-builds` runs in the scheduled `pick` only, with main's code, and lists each deletion in the run summary. It deletes only branches named nightly/build-<date>-<n> older than 7 days, never the newest build, and never one a published `nightly` or nightly-<date> release points to. nightly-state and every other branch are left alone. tests/test_nightly.py pins it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -95,6 +95,14 @@ jobs:
|
||||
run: |
|
||||
python3 tools/ci/nightly.py pick ${FORCE:+--force} | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
{ echo; cat nightly-notes.md; } >> "$GITHUB_STEP_SUMMARY"
|
||||
- name: Old nightly/build-* branches deleted (scheduled runs only)
|
||||
# Ludovic, 2026-10-27: older than 7 days, but never the newest build or one a published nightly points to;
|
||||
# nothing but nightly/build-* (nightly.py stale_builds, tests/test_nightly.py).
|
||||
if: github.event_name == 'schedule'
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
run: |
|
||||
{ echo "### nightly/build-* branches"; python3 tools/ci/nightly.py prune-builds --days 7; } | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: nightly-notes
|
||||
|
||||
@@ -447,6 +447,9 @@ comment on any issue or pull request (`.github/workflows/nightly-command.yml`, `
|
||||
Equal inputs give the same commit, so an unchanged set and main publish nothing new. On a conflict the build
|
||||
stops and answers which two pull requests conflict and where; a reviewer can then open an integration pull
|
||||
request from their fork that combines them, and pick that one instead.
|
||||
- **Old builds.** The scheduled run deletes the `nightly/build-*` branches older than 7 days (Ludovic,
|
||||
2026-10-27), and lists each in its summary. It never deletes the newest build, a build a published `nightly` or
|
||||
`nightly-<date>` release points to, or any other branch (`nightly.py prune-builds`).
|
||||
- **Refused.** A pull request that changes a path CODEOWNERS gives to Ludovic (`.github/`, `tools/ci/`, the
|
||||
signing and update code, `launcher/src/backend.rs`, `launcher/links.json`…), more than 30 in a set, and more than
|
||||
6 builds a day (the scheduled one always runs).
|
||||
|
||||
@@ -120,3 +120,39 @@ class UntrustedBuildTests(unittest.TestCase):
|
||||
self.assertEqual(self.game.count("HORIZON_NO_SCCACHE: ${{ inputs.trusted && '1' || '' }}"), calls)
|
||||
env = (Path(__file__).resolve().parents[1] / "tools/ci/runner-env.sh").read_text()
|
||||
self.assertEqual(env.count('-z "${HORIZON_NO_SCCACHE:-}"'), 2)
|
||||
|
||||
|
||||
class PruneBuildsTests(unittest.TestCase):
|
||||
TODAY = dt.date(2026, 11, 10)
|
||||
|
||||
def test_only_old_unpublished_builds_go(self):
|
||||
branches = {
|
||||
"nightly/build-2026-10-27-1": "a", # old: goes
|
||||
"nightly/build-2026-10-27-2": "pub", # old, but a published nightly-<date> points to it: stays
|
||||
"nightly/build-2026-11-02-1": "c", # old enough by one day: goes
|
||||
"nightly/build-2026-11-03-1": "d", # exactly 7 days: stays
|
||||
"nightly/build-2026-11-09-3": "e", # recent: stays
|
||||
}
|
||||
self.assertEqual(nightly.stale_builds(branches, {"pub"}, self.TODAY, 7),
|
||||
["nightly/build-2026-10-27-1", "nightly/build-2026-11-02-1"])
|
||||
|
||||
def test_the_newest_build_always_stays(self):
|
||||
branches = {"nightly/build-2026-10-01-1": "a", "nightly/build-2026-10-01-2": "b"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), ["nightly/build-2026-10-01-1"])
|
||||
self.assertEqual(nightly.stale_builds({"nightly/build-2026-10-01-1": "a"}, set(), self.TODAY, 7), [])
|
||||
# the newest by number, not by text: -10 is newer than -9
|
||||
branches = {"nightly/build-2026-10-01-9": "a", "nightly/build-2026-10-01-10": "b"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), ["nightly/build-2026-10-01-9"])
|
||||
|
||||
def test_nothing_else_is_touched(self):
|
||||
branches = {"nightly-state": "s", "nightly/build-x": "x", "main": "m", "nightly/build-2026-10-01-1-fix": "f",
|
||||
"feature/nightly/build-2026-10-01-1": "g", "nightly/build-2026-10-02-1": "n"}
|
||||
self.assertEqual(nightly.stale_builds(branches, set(), self.TODAY, 7), [])
|
||||
|
||||
def test_the_workflow_prunes_on_schedule_only(self):
|
||||
build = (WORKFLOWS / "nightly-build.yml").read_text()
|
||||
step = build.split("Old nightly/build-* branches deleted", 1)[1].split("- uses:", 1)[0]
|
||||
self.assertIn("if: github.event_name == 'schedule'", step)
|
||||
self.assertIn("prune-builds --days 7", step)
|
||||
self.assertIn("GITHUB_STEP_SUMMARY", step)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
nightly.py pick [--force] which commit tonight's nightly builds: GitHub outputs and nightly-notes.md
|
||||
nightly.py rotate renames the current `nightly` pre-release to nightly-<its date>, frees the tag
|
||||
nightly.py prune [--days 7] deletes the nightly-<date> pre-releases and tags older than that, nothing else
|
||||
nightly.py prune-builds [--days 7] deletes the nightly/build-<date>-<n> branches older than that, but the
|
||||
newest and any a published nightly points to (Ludovic, 2026-10-27)
|
||||
|
||||
A nightly builds main plus the pull requests the trusted reviewers picked (the set: tools/ci/nightly_set.py), merged
|
||||
in their order and pushed as nightly/build-<date>-<n>. With no set it builds the newest union branch on origin
|
||||
@@ -264,17 +266,63 @@ def prune(days: int) -> None:
|
||||
print(f"deleted {tag}")
|
||||
|
||||
|
||||
BUILD = re.compile(r"^nightly/build-(\d{4}-\d{2}-\d{2})-(\d+)$")
|
||||
|
||||
|
||||
def stale_builds(branches: dict[str, str], published: set[str], today: dt.date, days: int) -> list[str]:
|
||||
"""The nightly/build-<date>-<n> branches (name -> commit) to delete: older than `days`, never the newest build,
|
||||
never one whose commit a published nightly release points to, never a branch not named like a build."""
|
||||
builds = {name: sha for name, sha in branches.items() if BUILD.match(name)}
|
||||
if not builds:
|
||||
return []
|
||||
order = lambda name: (BUILD.match(name).group(1), int(BUILD.match(name).group(2))) # noqa: E731
|
||||
newest = max(builds, key=order)
|
||||
cutoff = today - dt.timedelta(days=days)
|
||||
return sorted(name for name, sha in builds.items() if name != newest and sha not in published
|
||||
and dt.date.fromisoformat(BUILD.match(name).group(1)) < cutoff)
|
||||
|
||||
|
||||
def remote_refs(pattern: str) -> dict[str, str]:
|
||||
"""origin's refs matching `pattern`: short name -> commit (annotated tags peeled)."""
|
||||
refs: dict[str, str] = {}
|
||||
for line in git("ls-remote", "origin", pattern).splitlines():
|
||||
sha, ref = line.split("\t", 1)
|
||||
name = ref.removeprefix("refs/heads/").removeprefix("refs/tags/")
|
||||
if name.endswith("^{}"):
|
||||
refs[name[:-3]] = sha # the peeled commit wins over the tag object
|
||||
else:
|
||||
refs.setdefault(name, sha)
|
||||
return refs
|
||||
|
||||
|
||||
def prune_builds(days: int) -> None:
|
||||
"""Deletes old nightly/build-* branches on origin through the API, one line per deletion (the run summary)."""
|
||||
branches = remote_refs("refs/heads/nightly/build-*")
|
||||
tags = {name: sha for name, sha in remote_refs("refs/tags/nightly*").items()
|
||||
if name == "nightly" or DATED.match(name)}
|
||||
today = dt.datetime.now(dt.timezone.utc).date()
|
||||
doomed = stale_builds(branches, set(tags.values()), today, days)
|
||||
for name in doomed:
|
||||
gh("api", "-X", "DELETE", f"repos/{os.environ['GITHUB_REPOSITORY']}/git/refs/heads/{name}")
|
||||
print(f"- deleted `{name}` ({branches[name][:7]})")
|
||||
print(f"{len(doomed)} of {len(branches)} nightly/build-* branches deleted (kept: the newest, the published "
|
||||
f"nightlies' and the last {days} days')")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
sub = ap.add_subparsers(dest="cmd", required=True)
|
||||
sub.add_parser("pick").add_argument("--force", action="store_true")
|
||||
sub.add_parser("rotate")
|
||||
sub.add_parser("prune").add_argument("--days", type=int, default=7)
|
||||
sub.add_parser("prune-builds").add_argument("--days", type=int, default=7)
|
||||
args = ap.parse_args()
|
||||
if args.cmd == "pick":
|
||||
pick(args.force)
|
||||
elif args.cmd == "rotate":
|
||||
rotate()
|
||||
elif args.cmd == "prune-builds":
|
||||
prune_builds(args.days)
|
||||
else:
|
||||
prune(args.days)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user