From cb12bc798478b4a508c363ea140e474d3e58bc72 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 29 Nov 2026 16:16:22 -0500 Subject: [PATCH] ci(nightly): enable automated 00:30 UTC schedule and Stage 2 signer dispatch (#3616) --- .github/nightly-signing-policy.json | 4 +- .github/workflows/nightly-dispatch.yml | 72 ++++++++++++++++++++++++++ .github/workflows/nightly.yml | 6 ++- packaging/nightly-release-tests.py | 41 ++++++++++++--- 4 files changed, 113 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/nightly-dispatch.yml diff --git a/.github/nightly-signing-policy.json b/.github/nightly-signing-policy.json index dedff705a..1e6a5c867 100644 --- a/.github/nightly-signing-policy.json +++ b/.github/nightly-signing-policy.json @@ -83,7 +83,9 @@ } }, "max_artifact_bytes": 2147483648, - "automatic_signer_actors": [], + "automatic_signer_actors": [ + "github-actions[bot]" + ], "platforms": { "windows-x86_64": { "unsigned_artifact_name": "nightly-unsigned-windows-x86_64", diff --git a/.github/workflows/nightly-dispatch.yml b/.github/workflows/nightly-dispatch.yml new file mode 100644 index 000000000..41808334a --- /dev/null +++ b/.github/workflows/nightly-dispatch.yml @@ -0,0 +1,72 @@ +name: Dispatch release-ref nightly + +# Transport only, never authorization. No checkout, payload parsing or release environment. +on: + workflow_run: + workflows: [CADCraft unsigned nightly] + types: [completed] + branches: [main] + +permissions: {} + +jobs: + dispatch: + # Actual context guards: official repository and completed workflow_run only. + if: >- + github.repository == 'storytold/cadcraft' && + github.event_name == 'workflow_run' + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + actions: write + steps: + - name: Dispatch only the exact completed producer run and attempt + shell: python + env: + GH_TOKEN: ${{ github.token }} + run: | + import json + import os + import urllib.request + + def require(value, message): + if not value: + raise RuntimeError(message) + + # These filters reduce noise; the protected signer-branch validator repeats admission + # against authenticated API metadata and required attestation/quality evidence. + require(os.environ.get('GITHUB_REPOSITORY') == 'storytold/cadcraft', 'wrong repository') + require(os.environ.get('GITHUB_EVENT_NAME') == 'workflow_run', 'wrong event') + with open(os.environ['GITHUB_EVENT_PATH'], encoding='utf-8') as stream: + event = json.load(stream) + require(event.get('action') == 'completed', 'producer is not complete') + require(event.get('repository', {}).get('full_name') == 'storytold/cadcraft', 'wrong event repository') + producer = event.get('workflow_run', {}) + require(producer.get('head_repository', {}).get('full_name') == 'storytold/cadcraft', 'foreign producer') + require(producer.get('path') == '.github/workflows/nightly.yml', 'wrong producer path') + require(producer.get('head_branch') == 'main', 'wrong producer branch') + require(producer.get('status') == 'completed' and producer.get('conclusion') == 'success', 'producer did not succeed') + # First scheduled attempt only; reviewed manual/re-run authority belongs to release policy. + require(producer.get('event') == 'schedule', 'not an automatic scheduled producer') + run_id, attempt = producer.get('id'), producer.get('run_attempt') + require(type(run_id) is int and run_id > 0, 'invalid producer run id') + require(type(attempt) is int and attempt == 1, 'invalid automatic producer attempt') + body = json.dumps({'ref': 'refs/heads/nightly-signer', 'inputs': { + 'producer_run_id': str(run_id), 'producer_run_attempt': str(attempt) + }}).encode('utf-8') + request = urllib.request.Request( + 'https://api.github.com/repos/storytold/cadcraft/actions/workflows/nightly-sign.yml/dispatches', + data=body, method='POST', headers={ + 'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], + 'Accept': 'application/vnd.github+json', + 'Content-Type': 'application/json', + 'X-GitHub-Api-Version': '2022-11-28', + 'User-Agent': 'cadcraft-nightly-dispatch' + }) + class NoRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self, req, fp, code, msg, headers, newurl): + raise RuntimeError('dispatch redirects are forbidden') + # One bounded request, no retry: duplicate transport is not publication authority. + with urllib.request.build_opener(NoRedirect()).open(request, timeout=20) as response: + require(response.status == 204, 'dispatch was not accepted') + print('Dispatched producer run/attempt to the release-ref validator; not a signing result.') diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 0c7e3547f..dbf33d355 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,8 +1,10 @@ name: CADCraft unsigned nightly -# Enabled for supervised manual runs by the reviewed manual actor only; no schedule yet. -# A later explicit opt-in may add a cadence (and turn on nightly-dispatch.yml with it). +# Automated nightly builds at 00:30 UTC (paired with nightly-dispatch.yml for automatic +# Stage 2 signer dispatch) plus supervised manual runs by the reviewed manual actors. on: + schedule: + - cron: '30 0 * * *' workflow_dispatch: permissions: diff --git a/packaging/nightly-release-tests.py b/packaging/nightly-release-tests.py index bef73c94b..d9dbf317e 100755 --- a/packaging/nightly-release-tests.py +++ b/packaging/nightly-release-tests.py @@ -185,7 +185,9 @@ class TrustedSourcePreparation(unittest.TestCase): producer_platforms(source.replace(" " + current + "\n", "")) def test_continuation_lines_of_any_scalar_form_reach_the_guard_checks(self): - for name, workflow in (("nightly.yml", "nightly.yml"), ("nightly-sign.yml", "nightly-sign.yml")): + for name, workflow in (("nightly.yml", "nightly.yml"), + ("nightly-sign.yml", "nightly-sign.yml"), + ("nightly-dispatch.yml", "nightly-dispatch.yml")): source = (ROOT / ".github/workflows" / workflow).read_text() expected = NightlyEnabledCallers.GUARDS[name] guard = re.search(r"(?m)^ if: >-\n(?: [^\n]*\n)+", source)[0] @@ -195,15 +197,38 @@ class TrustedSourcePreparation(unittest.TestCase): (indicator, expression), = job_conditions(jobs) self.assertFalse(indicator == ">-" and " ".join(expression.split()) == expected) - def test_no_nightly_schedule_is_registered(self): - for name, event in (("nightly.yml", "workflow_dispatch"), - ("nightly-sign.yml", "workflow_dispatch")): + def test_nightly_workflow_triggers_and_schedule_match_review(self): + expected_triggers = ( + ("nightly.yml", [" schedule:", " workflow_dispatch:"]), + ("nightly-sign.yml", [" workflow_dispatch:"]), + ("nightly-dispatch.yml", [" workflow_run:"]), + ) + for name, expected in expected_triggers: source = (ROOT / ".github/workflows" / name).read_text() events = source.split("\non:\n", 1)[1].split("\npermissions:", 1)[0] triggers = [line for line in events.splitlines() if line.startswith(" ") and not line.startswith(" ") and line.strip() and not line.lstrip().startswith("#")] with self.subTest(workflow=name): - self.assertEqual(triggers, [f" {event}:"], "schedule/activation needs explicit review") + self.assertEqual(triggers, expected, "schedule/activation needs explicit review") + producer = (ROOT / ".github/workflows/nightly.yml").read_text() + self.assertEqual(re.findall(r"(?m)^ - cron: '([^']+)'$", producer), ["30 0 * * *"], + "nightly schedule must stay pinned to 00:30 UTC") + + def test_nightly_dispatch_is_transport_only_for_scheduled_producer(self): + producer = (ROOT / ".github/workflows/nightly.yml").read_text() + producer_name = re.findall(r"(?m)^name: (.+)$", producer)[0] + dispatch = (ROOT / ".github/workflows/nightly-dispatch.yml").read_text() + self.assertIn(f"workflows: [{producer_name}]", dispatch) + self.assertIn("types: [completed]", dispatch) + self.assertIn("branches: [main]", dispatch) + self.assertIn("\npermissions: {}\n", dispatch) + self.assertNotIn("false &&", dispatch) + self.assertNotRegex(dispatch, r"(?im)^\s*(?:-\s*)?uses:") + self.assertNotRegex(dispatch, r"(?im)^\s*environment:|\bsecrets\b") + self.assertIn("storytold/cadcraft/actions/workflows/nightly-sign.yml/dispatches", dispatch) + self.assertIn("'ref': 'refs/heads/" + SIGNER_BRANCH + "'", dispatch) + self.assertIn("producer.get('event') == 'schedule'", dispatch) + self.assertIn("type(attempt) is int and attempt == 1", dispatch) def test_signer_serialization_contract_is_enforced(self): assert_nightly_serialization((ROOT / ".github/workflows/nightly-sign.yml").read_text()) @@ -224,7 +249,7 @@ class TrustedSourcePreparation(unittest.TestCase): assert_nightly_serialization(source.replace(old, new)) def test_no_cache_actions_or_cache_setup_options_in_app_trusted_closure(self): - for name in ("nightly.yml", "nightly-sign.yml"): + for name in ("nightly.yml", "nightly-sign.yml", "nightly-dispatch.yml"): source = (ROOT / ".github/workflows" / name).read_text() executable = "\n".join(line for line in source.splitlines() if not line.lstrip().startswith("#")) @@ -322,6 +347,7 @@ class NightlyEnabledCallers(unittest.TestCase): "github.event_name == 'workflow_dispatch')", "nightly-sign.yml": "github.repository == 'storytold/cadcraft' && github.event_name == 'workflow_dispatch' && " "github.ref == 'refs/heads/" + SIGNER_BRANCH + "' && github.ref_type == 'branch'", + "nightly-dispatch.yml": "github.repository == 'storytold/cadcraft' && github.event_name == 'workflow_run'", } def test_enabled_jobs_keep_exact_context_guards(self): @@ -338,7 +364,8 @@ class NightlyEnabledCallers(unittest.TestCase): source = (ROOT / ".github/workflows/nightly.yml").read_text() policy = json.loads(INSTALLED_POLICY.read_text()) self.assertEqual(reviewed_manual_actors(source, policy), RELEASE_MANAGERS) - self.assertEqual(policy["automatic_signer_actors"], [], "no automatic signer without a schedule") + self.assertEqual(policy["automatic_signer_actors"], ["github-actions[bot]"], + "only github-actions[bot] may trigger automatic scheduled signing") def test_an_actor_outside_the_release_managers_is_refused(self): source = (ROOT / ".github/workflows/nightly.yml").read_text()