From 4a170859e6f456cc104103bcf3e645e1069c686c Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Sat, 5 Dec 2026 06:27:44 -0500 Subject: [PATCH] Release a beta skipped for the gap within minutes of the gap ending A beta skipped for the gap waited for beta-follow-up.yml's schedule, which GitHub can start hours late. The run that skips it now starts a waiter (beta-follow-up.yml with its skip record) that sleeps in its own run until the gap ends, then starts mode beta-after-deploy again. It re-checks that the commit is still unreleased, checks again every two minutes while a run of auto-release.yml is queued or running, and hands over to a new waiter when its minutes run out. A newer skip's waiter replaces it. The schedule stays as the backstop, in its own concurrency group. --- .github/scripts/auto_release.py | 97 ++++++++++++++++----- .github/scripts/test_auto_release.py | 124 ++++++++++++++++++++++++++- .github/workflows/auto-release.yml | 40 +++++++-- .github/workflows/beta-follow-up.yml | 70 ++++++++++++--- docs/self-host/updates-security.md | 2 +- 5 files changed, 287 insertions(+), 46 deletions(-) diff --git a/.github/scripts/auto_release.py b/.github/scripts/auto_release.py index a2b83154..bb5a2945 100644 --- a/.github/scripts/auto_release.py +++ b/.github/scripts/auto_release.py @@ -5,7 +5,7 @@ [--commit SHA] [--version vX.Y.Z] [--evidence FILE] [--min-gap-hours H] \\ [--due-file FILE] --notes-dir DIR [--github-output "$GITHUB_OUTPUT"] python3 .github/scripts/auto_release.py follow-up --repo OWNER/NAME \\ - [--record FILE] [--github-output "$GITHUB_OUTPUT"] + [--record FILE] [--wait-minutes M] [--github-output "$GITHUB_OUTPUT"] Run in a full clone of main (all tags fetched). Two update channels (docs/self-host/updates.md, "Channels"): @@ -75,18 +75,30 @@ skips past its name instead. The tag it names never exists yet: a tag is never re-cut or moved. -follow-up (.github/workflows/beta-follow-up.yml, every 30 minutes) reads the -newest skip record (the "beta-due" artifact of a run of auto-release.yml on -main, or --record) and says due=true once its time has come, while the -commit it skipped is in no release yet and no run of auto-release.yml is -queued or running; that workflow then starts auto-release.yml in mode -beta-after-deploy, which plans again with the gap, so a follow-up never cuts -a second beta within it and a commit released meanwhile is skipped. A record -older than FOLLOW_UP_HOURS past its time is left to the nightly. +follow-up (.github/workflows/beta-follow-up.yml) reads a skip record and +says due=true once its time has come, while the commit it skipped is in no +release yet and no run of auto-release.yml is queued or running; that +workflow then starts auto-release.yml in mode beta-after-deploy, which plans +again with the gap, so a follow-up never cuts a second beta within it and a +commit released meanwhile is skipped. A record older than FOLLOW_UP_HOURS +past its time is left to the nightly. Two ways it runs: + + the waiter the run that skipped starts beta-follow-up.yml with its own + record (--record) and --wait-minutes: it sleeps until the + record is due, checks, and while a run of auto-release.yml is + queued or running checks again every POLL_SECONDS. When the + minutes run out first it writes again=true, and the workflow + starts a new waiter with the same record. So the beta never + waits on GitHub's schedule. A newer skip's waiter replaces it; + the backstop every 30 minutes (when GitHub runs the schedule), or by + hand: one check of the newest record (the "beta-due" artifact + of a run of auto-release.yml on main). Outputs (GITHUB_OUTPUT): releases (a JSON list of {kind, channel, tag, commit, previous, stable_tag, beta}), count, summary, and due (when the gap -ends) on a skip for the gap; follow-up writes due (true or false) and why. Notes for each release +ends) and due_record (the skip record, JSON) on a skip for the gap; +follow-up writes due (true or false), why, and again (true when a waiter ran +out of minutes before an answer). Notes for each release go to DIR/.md. Only the standard library is used; git and gh must be on PATH. """ @@ -98,6 +110,7 @@ import re import subprocess import sys +import time import zipfile from datetime import datetime, timedelta, timezone @@ -116,6 +129,9 @@ DUE_ARTIFACT = "beta-due" DUE_MARGIN = timedelta(minutes=1) FOLLOW_UP_HOURS = 24 +# How often a waiter checks again while a run of auto-release.yml is queued or +# running. +POLL_SECONDS = 120 # What a self-host release is built from (.github/workflows/release.yml, build # job): the Rust Lambdas (services/), the MCP proxy and the updater (lambda/), @@ -512,29 +528,54 @@ def skip_record(commit, published, now, hours): def follow_up(record, now, released_in, busy=False): - """Whether the follow-up starts the beta a skip left: {due, reason}. + """Whether the follow-up starts the beta a skip left: {due, reason, wait}. record the newest skip record ({commit, skipped_at, due}), or None; released_in f(commit, skipped_at) -> the release tag that already holds the commit (published since the skip), or None; - busy a run of auto-release.yml is queued or running: it plans - again itself, and a new run would only replace a queued one. + busy a run of auto-release.yml is queued or running (a bool, or + f() -> bool, asked only when it matters): it plans again + itself, and a new run would only replace a queued one. + wait seconds after which checking again may answer otherwise + (not due yet, or busy); None when the answer is final. """ if not record: - return {"due": False, "reason": "no beta was skipped for the gap"} + return {"due": False, "reason": "no beta was skipped for the gap", "wait": None} commit, due, skipped = record.get("commit"), _when(record.get("due")), _when(record.get("skipped_at")) if not (isinstance(commit, str) and re.fullmatch(r"[0-9a-f]{40}", commit)) or not due or not skipped: - return {"due": False, "reason": "the skip record can't be read"} + return {"due": False, "reason": "the skip record can't be read", "wait": None} if now < due: - return {"due": False, "reason": "%s waits for the gap: due at %s" % (commit[:12], _iso(due))} + return {"due": False, "reason": "%s waits for the gap: due at %s" % (commit[:12], _iso(due)), + "wait": max(1, int((due - now).total_seconds() + 0.999))} if now > due + timedelta(hours=FOLLOW_UP_HOURS): - return {"due": False, "reason": "%s was due at %s, over %d hours ago: left to the nightly" % (commit[:12], _iso(due), FOLLOW_UP_HOURS)} + return {"due": False, "reason": "%s was due at %s, over %d hours ago: left to the nightly" % (commit[:12], _iso(due), FOLLOW_UP_HOURS), + "wait": None} tag = released_in(commit, skipped) if tag: - return {"due": False, "reason": "%s is already released in %s" % (commit[:12], tag)} - if busy: - return {"due": False, "reason": "%s is due, but a run of auto-release.yml is queued or running: the next check starts it" % commit[:12]} - return {"due": True, "reason": "%s was skipped for the gap and is due since %s" % (commit[:12], _iso(due))} + return {"due": False, "reason": "%s is already released in %s" % (commit[:12], tag), "wait": None} + if busy() if callable(busy) else busy: + return {"due": False, "reason": "%s is due, but a run of auto-release.yml is queued or running: checked again later" % commit[:12], + "wait": POLL_SECONDS} + return {"due": True, "reason": "%s was skipped for the gap and is due since %s" % (commit[:12], _iso(due)), "wait": None} + + +def wait_for_due(record, released_in, busy, clock, sleep, minutes): + """follow_up, checked again as long as waiting may change its answer, for + at most `minutes` (a waiter). {due, reason, again}: again is True when the + minutes ran out before a final answer, so a new waiter carries on. + + clock f() -> now (an aware datetime); sleep f(seconds). + """ + end = clock() + timedelta(minutes=minutes) + while True: + now = clock() + r = follow_up(record, now, released_in, busy) + if r["wait"] is None: + return {"due": r["due"], "reason": r["reason"], "again": False} + left = (end - now).total_seconds() + if left <= 0: + return {"due": False, "reason": r["reason"] + "; this waiter's time is up, a new one carries on", "again": True} + sleep(min(r["wait"], left)) def _api_json(path): @@ -633,6 +674,8 @@ def main(argv): f = sub.add_parser("follow-up") f.add_argument("--repo", required=True) f.add_argument("--record", help="the skip record (JSON); default: the newest %s artifact" % DUE_ARTIFACT) + f.add_argument("--wait-minutes", type=float, default=0, + help="a waiter: check again until the record's answer is final, for at most this long") f.add_argument("--github-output") p = sub.add_parser("plan") p.add_argument("--repo", required=True) @@ -701,6 +744,7 @@ def keep(kind, channel, r, tag, commit): f.write("summary=%s\n" % " ".join(summary.split())) if due: f.write("due=%s\n" % due["due"]) + f.write("due_record=%s\n" % json.dumps(due, separators=(",", ":"))) if failed: print("::error::" + summary, file=sys.stderr) return 1 @@ -717,11 +761,20 @@ def main_follow_up(a): record = None else: record = _due_record(a.repo) - r = follow_up(record, now, lambda c, since: _released_in(a.repo, c, since), busy=_busy(a.repo) if record else False) + released = lambda c, since: _released_in(a.repo, c, since) # noqa: E731 + busy = lambda: _busy(a.repo) # noqa: E731 + if a.wait_minutes > 0: + def sleep(s): + print("follow-up: checking again in %d second(s)" % s, flush=True) + time.sleep(s) + r = wait_for_due(record, released, busy, lambda: datetime.now(timezone.utc), sleep, a.wait_minutes) + else: + r = follow_up(record, now, released, busy) print("follow-up: " + r["reason"]) if a.github_output: with open(a.github_output, "a", encoding="utf-8") as f: f.write("due=%s\n" % ("true" if r["due"] else "false")) + f.write("again=%s\n" % ("true" if r.get("again") else "false")) f.write("reason=%s\n" % " ".join(r["reason"].split())) return 0 diff --git a/.github/scripts/test_auto_release.py b/.github/scripts/test_auto_release.py index 03357a76..8c098867 100644 --- a/.github/scripts/test_auto_release.py +++ b/.github/scripts/test_auto_release.py @@ -505,12 +505,15 @@ def test_a_skip_for_the_gap_records_when_it_is_due(self): want = ar._iso(last + timedelta(hours=4, minutes=1)) self.assertEqual((record["commit"], record["due"], outputs["due"]), (SHA, want, want)) self.assertIn("the follow-up at %s releases this" % want, outputs["summary"]) + # The same record, for the waiter the run starts. + self.assertEqual(json.loads(outputs["due_record"]), record) def test_a_beta_past_the_gap_records_nothing(self): rc, outputs, record = self.run_plan([datetime.now(timezone.utc) - timedelta(hours=5)]) self.assertEqual((rc, outputs["count"]), (0, "1")) self.assertIsNone(record) self.assertNotIn("due", outputs) + self.assertNotIn("due_record", outputs) def test_the_record_is_due_a_minute_past_the_gap(self): last = self.now - timedelta(hours=3, minutes=42) @@ -543,6 +546,90 @@ def test_what_is_not_due_waits(self): self.assertFalse(r["due"]) self.assertIn("queued or running", r["reason"]) + def test_busy_is_asked_only_when_it_matters(self): + never = lambda: self.fail("busy asked") # noqa: E731 + self.assertFalse(ar.follow_up(self.record(due_in_minutes=10), self.now, lambda c, s: None, never)["due"]) + self.assertFalse(ar.follow_up(self.record(), self.now, lambda c, s: "v0.9.1-beta.20261204", never)["due"]) + self.assertTrue(ar.follow_up(self.record(), self.now, lambda c, s: None, lambda: False)["due"]) + r = ar.follow_up(self.record(), self.now, lambda c, s: None, lambda: True) + self.assertEqual((r["due"], r["wait"]), (False, ar.POLL_SECONDS)) + + def test_how_long_waiting_may_change_the_answer(self): + rel = lambda c, s: None # noqa: E731 + self.assertEqual(ar.follow_up(self.record(due_in_minutes=10), self.now, rel)["wait"], 600) + # Final answers: due, released, unreadable, none, too old. + self.assertIsNone(ar.follow_up(self.record(), self.now, rel)["wait"]) + self.assertIsNone(ar.follow_up(self.record(), self.now, lambda c, s: "v0.9.1-beta.20261204")["wait"]) + self.assertIsNone(ar.follow_up({"commit": "x"}, self.now, rel)["wait"]) + self.assertIsNone(ar.follow_up(None, self.now, rel)["wait"]) + self.assertIsNone(ar.follow_up(self.record(due_in_minutes=-25 * 60), self.now, rel)["wait"]) + + class Clock: + """A fake clock that sleeping moves forward.""" + + def __init__(self, now): + self.now, self.slept = now, [] + + def __call__(self): + return self.now + + def sleep(self, s): + self.slept.append(s) + self.now += timedelta(seconds=s) + + def test_the_waiter_sleeps_until_due_then_releases(self): + clock = self.Clock(self.now) + asked = [] + r = ar.wait_for_due(self.record(due_in_minutes=230), lambda c, s: asked.append(clock()) or None, + lambda: False, clock, clock.sleep, 330) + self.assertEqual((r["due"], r["again"]), (True, False), r["reason"]) + # One sleep, to the minute it is due: never a schedule's half hour. + self.assertEqual(clock.slept, [230 * 60]) + self.assertEqual(asked, [self.now + timedelta(minutes=230)]) + + def test_the_waiter_waits_out_a_busy_release_run(self): + clock = self.Clock(self.now) + busy = iter([True, True, False]) + r = ar.wait_for_due(self.record(due_in_minutes=1), lambda c, s: None, lambda: next(busy), clock, clock.sleep, 330) + self.assertTrue(r["due"], r["reason"]) + self.assertEqual(clock.slept, [60, ar.POLL_SECONDS, ar.POLL_SECONDS]) + + def test_the_waiter_stops_once_the_commit_is_released(self): + clock = self.Clock(self.now) + answers = iter([None, "v0.9.1-beta.20261204"]) + r = ar.wait_for_due(self.record(), lambda c, s: next(answers), lambda: True, clock, clock.sleep, 330) + self.assertEqual((r["due"], r["again"]), (False, False)) + self.assertIn("already released", r["reason"]) + self.assertEqual(clock.slept, [ar.POLL_SECONDS]) + + def test_a_waiter_out_of_minutes_hands_over(self): + clock = self.Clock(self.now) + r = ar.wait_for_due(self.record(), lambda c, s: None, lambda: True, clock, clock.sleep, 5) + self.assertEqual((r["due"], r["again"]), (False, True)) + # Never sleeps past its minutes. + self.assertEqual(sum(clock.slept), 300) + clock = self.Clock(self.now) + r = ar.wait_for_due(self.record(due_in_minutes=400), lambda c, s: None, lambda: False, clock, clock.sleep, 330) + self.assertEqual((r["due"], r["again"], clock.slept), (False, True, [330 * 60])) + + def test_the_waiter_command(self): + d = tempfile.mkdtemp() + rec, out = os.path.join(d, "rec.json"), os.path.join(d, "out") + now = datetime.now(timezone.utc) + with open(rec, "w") as f: + json.dump({"commit": SHA, "skipped_at": ar._iso(now - timedelta(hours=4)), "due": ar._iso(now - timedelta(minutes=1))}, f) + real = ar._released_in, ar._busy, ar.time.sleep + ar._released_in, ar._busy = lambda repo, c, since: None, lambda repo: False + ar.time.sleep = lambda s: self.fail("a due record never sleeps") + try: + self.assertEqual(ar.main(["follow-up", "--repo", "o/r", "--record", rec, "--wait-minutes", "330", "--github-output", out]), 0) + finally: + ar._released_in, ar._busy, ar.time.sleep = real + with open(out) as f: + lines = f.read().splitlines() + self.assertIn("due=true", lines) + self.assertIn("again=false", lines) + def test_follow_up_writes_its_answer(self): d = tempfile.mkdtemp() rec, out = os.path.join(d, "rec.json"), os.path.join(d, "out") @@ -558,22 +645,51 @@ def test_the_workflows(self): on = doc.get("on", doc.get(True)) self.assertEqual([s["cron"] for s in on["schedule"]], ["7,37 * * * *"]) self.assertEqual(doc["permissions"], {}) - self.assertEqual(doc["concurrency"]["group"], "beta-follow-up") - due, start = doc["jobs"]["due"], doc["jobs"]["start"] + # A waiter (started with a record) and the backstop never cancel each other; + # a newer waiter replaces an older one. + self.assertEqual(doc["concurrency"]["group"], + "${{ inputs.record != '' && 'beta-follow-up-wait' || 'beta-follow-up' }}") + self.assertTrue(doc["concurrency"]["cancel-in-progress"]) + self.assertEqual(on["workflow_dispatch"]["inputs"]["record"]["default"], "") + due, start, again = doc["jobs"]["due"], doc["jobs"]["start"], doc["jobs"]["again"] self.assertEqual(due["permissions"], {"contents": "read", "actions": "read"}) - self.assertIn("auto_release.py follow-up", due["steps"][-1]["run"]) + step = due["steps"][-1] + self.assertIn("auto_release.py follow-up", step["run"]) + self.assertIn('--record "$RUNNER_TEMP/record.json" --wait-minutes "$WAIT"', step["run"]) + self.assertEqual(step["env"]["RECORD"], "${{ inputs.record }}") + # The waiter outlasts the gap and its margin, inside GitHub's 6-hour job limit. + wait = float(step["env"]["WAIT"]) + _, auto = Wiring.load("auto-release.yml") + self.assertGreater(wait, float(auto["env"]["BETA_GAP_HOURS"]) * 60 + ar.DUE_MARGIN.total_seconds() / 60 + 30) + self.assertGreater(due["timeout-minutes"], wait) + self.assertLess(due["timeout-minutes"], 360) + # Out of minutes: a new waiter with the same record. + self.assertEqual(again["if"], "success() && needs.due.outputs.again == 'true'") + self.assertEqual(again["permissions"], {"actions": "write"}) + self.assertEqual(again["steps"][-1]["env"]["RECORD"], "${{ inputs.record }}") + self.assertEqual(again["steps"][-1]["run"], + 'gh workflow run beta-follow-up.yml -R "$GITHUB_REPOSITORY" --ref main -f record="$RECORD"') self.assertEqual(start["permissions"], {"actions": "write"}) self.assertEqual(start["if"], "success() && needs.due.outputs.due == 'true'") # The same run a deploy starts, so the gap holds: never two betas within it. self.assertEqual(start["steps"][-1]["run"], 'gh workflow run auto-release.yml -R "$GITHUB_REPOSITORY" --ref main -f mode=beta-after-deploy') - _, auto = Wiring.load("auto-release.yml") steps = auto["jobs"]["plan"]["steps"] plan = next(s for s in steps if s.get("id") == "plan")["run"] self.assertIn('[ "$gap" != 0 ] && args+=(--due-file "$RUNNER_TEMP/beta-due/beta-due.json")', plan) up = next(s for s in steps if (s.get("with") or {}).get("name") == ar.DUE_ARTIFACT) self.assertEqual(up["if"], "steps.plan.outputs.due != ''") self.assertEqual(up["with"]["path"], "${{ runner.temp }}/beta-due/beta-due.json") + # The run that skipped starts the waiter itself, without sleeping in the "auto-release" group. + self.assertEqual(auto["jobs"]["plan"]["outputs"]["due_record"], "${{ steps.plan.outputs.due_record }}") + w = auto["jobs"]["wait"] + self.assertEqual(w["needs"], "plan") + self.assertEqual(w["if"], "${{ !cancelled() && needs.plan.result == 'success' && needs.plan.outputs.due_record != '' }}") + self.assertEqual(w["permissions"], {"actions": "write"}) + self.assertLessEqual(w["timeout-minutes"], 5) + self.assertEqual(w["steps"][-1]["env"]["RECORD"], "${{ needs.plan.outputs.due_record }}") + self.assertEqual(w["steps"][-1]["run"], + 'gh workflow run beta-follow-up.yml -R "$GITHUB_REPOSITORY" --ref main -f record="$RECORD"') class WithGit(unittest.TestCase): diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 256a1252..68a8a5ac 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -30,12 +30,17 @@ name: Auto release # beta needs a post-update watch on a live install # before it can be promoted, so a burst of merges makes # one beta. A skip for the gap records when the gap -# ends (the "beta-due" artifact, a minute past it), and -# beta-follow-up.yml, every 30 minutes, starts this mode -# again once that time has come, unless a newer deploy -# or the nightly released the commit first. The run it -# starts plans with the gap too, so no two betas are -# ever cut within it. +# ends (a minute past it; also the "beta-due" +# artifact), and the same run starts the waiter +# (beta-follow-up.yml with that record, job "wait"): it +# sleeps until then and starts this mode again, unless +# a newer deploy or the nightly released the commit +# first, so the beta never waits on GitHub's schedule. +# The waiter's own run sleeps, not this one, so the +# "auto-release" group is never held. Its 30-minute +# schedule is only the backstop. The run it starts +# plans with the gap too, so no two betas are ever cut +# within it. # schedule 06:17 nightly: tonight's beta (once main's head is # deployed), the fallback when no deploy cut one. # a beta's publish the promotion, right after each beta is published (a @@ -185,6 +190,7 @@ jobs: releases: ${{ steps.plan.outputs.releases || '[]' }} count: ${{ steps.plan.outputs.count || '0' }} mode: ${{ steps.guard.outputs.mode }} + due_record: ${{ steps.plan.outputs.due_record }} steps: # A new release's signature names this run's ref and commit, and installs # require refs/heads/main and the tag's commit: the run must be on main, @@ -304,7 +310,8 @@ jobs: fi [ "$gap" != 0 ] && args+=(--due-file "$RUNNER_TEMP/beta-due/beta-due.json") python3 .github/scripts/auto_release.py plan "${args[@]}" - # A beta skipped for the gap: when it is due, for beta-follow-up.yml. + # A beta skipped for the gap: when it is due, for beta-follow-up.yml's + # backstop (the waiter gets the record from job "wait"). - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 if: steps.plan.outputs.due != '' with: @@ -320,6 +327,25 @@ jobs: if-no-files-found: error retention-days: 3 + # A beta skipped for the gap: start the waiter (beta-follow-up.yml with + # this run's skip record), which sleeps in its own run until the gap ends + # and then starts mode beta-after-deploy again. Started, not waited for: + # this run, and the "auto-release" group, end now. + wait: + name: Start the waiter for the gap + needs: plan + if: ${{ !cancelled() && needs.plan.result == 'success' && needs.plan.outputs.due_record != '' }} + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: write # start beta-follow-up.yml + steps: + - name: Start beta-follow-up.yml with the skip record + env: + GH_TOKEN: ${{ github.token }} + RECORD: ${{ needs.plan.outputs.due_record }} + run: gh workflow run beta-follow-up.yml -R "$GITHUB_REPOSITORY" --ref main -f record="$RECORD" + tag: name: Attest and tag ${{ matrix.tag }} needs: plan diff --git a/.github/workflows/beta-follow-up.yml b/.github/workflows/beta-follow-up.yml index 5e67a3a2..38ee82c6 100644 --- a/.github/workflows/beta-follow-up.yml +++ b/.github/workflows/beta-follow-up.yml @@ -3,23 +3,43 @@ name: Beta follow-up # A beta that a deploy's run of auto-release.yml skipped because the newest # release was under BETA_GAP_HOURS old, released once the gap ends, so merged # work never waits for the nightly. That run records when the gap ends, a -# minute past it (the "beta-due" artifact). Every 30 minutes this reads the -# newest record (.github/scripts/auto_release.py follow-up) and, once it is -# due, starts auto-release.yml on main in mode beta-after-deploy, exactly as -# a deploy does. Nothing happens when there is no record, when it is not due -# yet, when a newer deploy or the nightly already released its commit, or -# while a run of auto-release.yml is queued or running (a new one would only -# replace a queued one; the next check starts it). The run it starts plans -# again with the gap, so it never cuts a second beta within it. +# minute past it (.github/scripts/auto_release.py follow-up), and starts this +# workflow with that record right away: the waiter. +# +# the waiter (started with "record") sleeps until the record is due, +# checks, and while a run of auto-release.yml is queued or +# running checks again every two minutes. Once it is due it +# starts auto-release.yml on main in mode beta-after-deploy, +# exactly as a deploy does. It never waits on GitHub's +# schedule. A newer skip starts a newer waiter, which +# replaces this one (one group, cancel-in-progress); when its +# minutes run out before an answer, it starts a new waiter +# with the same record. +# the backstop every 30 minutes (when GitHub runs the schedule), or by +# hand without "record": one check of the newest record (the +# "beta-due" artifact), in its own group, so it never cancels +# a waiter. +# +# Either way, nothing happens when it is not due yet, when a newer deploy or +# the nightly already released its commit, or (for now) while a run of +# auto-release.yml is queued or running: a new one would replace a queued +# one. The run it starts checks the deploy and CI again and plans again with +# the gap, so it never cuts a second beta within it. on: schedule: - cron: "7,37 * * * *" workflow_dispatch: + inputs: + record: + description: "A waiter: the skip record auto-release.yml wrote ({commit, skipped_at, due}, JSON). Empty: one check of the newest record." + required: false + type: string + default: "" permissions: {} concurrency: - group: beta-follow-up + group: ${{ inputs.record != '' && 'beta-follow-up-wait' || 'beta-follow-up' }} cancel-in-progress: true jobs: @@ -27,12 +47,15 @@ jobs: name: Is a skipped beta due if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest - timeout-minutes: 10 + # A waiter sleeps up to WAIT minutes (past the 4-hour gap and its margin), + # under GitHub's 6-hour job limit. + timeout-minutes: 350 permissions: contents: read # the planner script actions: read # the skip record, and the runs of auto-release.yml outputs: due: ${{ steps.due.outputs.due }} + again: ${{ steps.due.outputs.again }} steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -41,10 +64,18 @@ jobs: sparse-checkout: .github/scripts/auto_release.py sparse-checkout-cone-mode: false - id: due - name: Read the newest skip record + name: Wait for the skip record, or read the newest one env: GH_TOKEN: ${{ github.token }} - run: python3 .github/scripts/auto_release.py follow-up --repo "$GITHUB_REPOSITORY" --github-output "$GITHUB_OUTPUT" + RECORD: ${{ inputs.record }} + WAIT: "330" + run: | + args=(--repo "$GITHUB_REPOSITORY" --github-output "$GITHUB_OUTPUT") + if [ -n "$RECORD" ]; then + printf '%s' "$RECORD" > "$RUNNER_TEMP/record.json" + args+=(--record "$RUNNER_TEMP/record.json" --wait-minutes "$WAIT") + fi + python3 .github/scripts/auto_release.py follow-up "${args[@]}" start: name: Start the beta that waited @@ -59,3 +90,18 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: gh workflow run auto-release.yml -R "$GITHUB_REPOSITORY" --ref main -f mode=beta-after-deploy + + again: + name: Keep waiting in a new waiter + needs: due + if: success() && needs.due.outputs.again == 'true' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: write # start this workflow again + steps: + - name: Start a new waiter with the same record + env: + GH_TOKEN: ${{ github.token }} + RECORD: ${{ inputs.record }} + run: gh workflow run beta-follow-up.yml -R "$GITHUB_REPOSITORY" --ref main -f record="$RECORD" diff --git a/docs/self-host/updates-security.md b/docs/self-host/updates-security.md index d9760ee6..f25d87c1 100644 --- a/docs/self-host/updates-security.md +++ b/docs/self-host/updates-security.md @@ -55,7 +55,7 @@ A release is a `vX.Y.Z` tag (or a nightly beta, `vX.Y.Z-beta.YYYYMMDD`) on `Code **Automatic (the usual way).** `.github/workflows/auto-release.yml` on `main` cuts three kinds of release ([Channels](./updates.md#channels)): -- **A beta after a deploy**: each successful deploy of `main` starts a run for the commit it shipped, which releases a beta when anything that ships changed and the newest published release is at least a few hours old (`BETA_GAP_HOURS` in the workflow), so a burst of deploys makes one beta. A beta skipped for that gap records when the gap ends, and `.github/workflows/beta-follow-up.yml` (every 30 minutes) starts the same run again once it is due, unless a newer deploy or the nightly released that commit first; that run plans with the gap again, so two betas are never cut within it. +- **A beta after a deploy**: each successful deploy of `main` starts a run for the commit it shipped, which releases a beta when anything that ships changed and the newest published release is at least a few hours old (`BETA_GAP_HOURS` in the workflow), so a burst of deploys makes one beta. A beta skipped for that gap records when the gap ends, and the run that skipped it starts `.github/workflows/beta-follow-up.yml` with that record right away. That waiter sleeps in its own run until the gap ends, then starts the same run again within a few minutes, unless a newer deploy or the nightly released that commit first. It does not depend on GitHub's schedule, which can start hours late. While another release run is queued or running, it checks again every two minutes, and a newer skip's waiter replaces it. The workflow's 30-minute schedule is only a backstop. The run it starts checks the deploy and CI again and plans with the gap again, so two betas are never cut within it. - **The nightly beta**, on its schedule (06:17 UTC), the fallback: the commit `main`'s hosted deploy shipped, once that deploy succeeded (the run waits for it). - **A promotion**, after each beta is published, on its backstop schedule (10:17 UTC) or by hand: the newest beta a live install showed working ([Channels](./updates.md#channels): installed with a healthy watch, a finished run, a Chat answer where Chat is used; never rolled back, no open `release-blocker` issue naming it) becomes `vX.Y.Z` on the same commit. The reports are read with `coderhelm-prod-release-evidence`, a role that may only Query their one partition of the hosted settings table, assumed by `auto-release.yml` on `main` in `release-auto` alone. - **An urgent stable release**, when a maintainer runs `deploy.yml` by hand with "stable release": the commit that deploy shipped, in that same deploy run, so it is exactly that commit even when more pull requests merged into `main` meanwhile.