Skip to content
Bitcoin Roots

v29.4-roots.3 · Commit 8: [PATCH 08/30] ci: restore assurance and isolate Core fixtures

ci/nightly-change-gate.py

Before: /dev/null · After: ci/nightly-change-gate.py

File metadata
new file mode 100755
index 0000000000000000000000000000000000000000..4f9b2e475f5573aa0c6e2342224366c65bc25f0e

Download original patch · Release notes

Diff rows 1–77 of 77. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.

ci/nightly-change-gate.py ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env python3
2
+ # Copyright (c) 2026-present The Bitcoin Roots developers
3
+ # Distributed under the MIT software license, see the accompanying file COPYING.
4
+ """Fail-open decision logic for the scheduled nightly workflow.
5
+
6
+ The workflow supplies the current scheduled run followed by its immediate
7
+ predecessor from GitHub's Actions API. A no-op is safe only after validating
8
+ that complete, ordered response and finding a successful predecessor at the
9
+ same commit.
10
+ """
11
+
12
+ import argparse
13
+ import json
14
+
15
+
16
+ RUN = {"run": True, "reason": "uncertain-history"}
17
+
18
+
19
+ def should_run(event_name, current_run_id, current_sha, history):
20
+ """Return a fail-open run decision for one Actions event."""
21
+ if event_name != "schedule":
22
+ return {"run": True, "reason": "non-scheduled-event"}
23
+ if not isinstance(current_run_id, int) or not isinstance(current_sha, str) or not current_sha:
24
+ return RUN
25
+ if not isinstance(history, dict) or history.get("complete") is not True:
26
+ return RUN
27
+ runs = history.get("workflow_runs")
28
+ # The API request deliberately asks for exactly two records. Any other
29
+ # cardinality is missing or truncated history, never a basis for skipping.
30
+ if not isinstance(runs, list) or len(runs) != 2:
31
+ return RUN
32
+ required = ("id", "event", "status", "conclusion", "head_sha")
33
+ if any(not isinstance(run, dict) or any(key not in run for key in required) for run in runs[:2]):
34
+ return RUN
35
+ current, previous = runs[:2]
36
+ if any(isinstance(run["id"], bool) or not isinstance(run["id"], int) or
37
+ not isinstance(run["event"], str) or not run["event"] or
38
+ not isinstance(run["status"], str) or not run["status"] or
39
+ not isinstance(run["head_sha"], str) or not run["head_sha"]
40
+ for run in (current, previous)):
41
+ return RUN
42
+ if (current["id"] != current_run_id or current["event"] != "schedule" or
43
+ current["head_sha"] != current_sha or current["status"] not in ("queued", "in_progress") or
44
+ current["conclusion"] is not None):
45
+ return RUN
46
+ if previous["id"] >= current["id"]:
47
+ return RUN
48
+ if (previous["event"] != "schedule" or previous["status"] != "completed" or
49
+ previous["conclusion"] != "success"):
50
+ return RUN
51
+ if previous["head_sha"] == current_sha:
52
+ return {"run": False, "reason": "unchanged-success"}
53
+ return {"run": True, "reason": "new-commit"}
54
+
55
+
56
+ def main():
57
+ parser = argparse.ArgumentParser(description=__doc__)
58
+ parser.add_argument("--event-name", required=True)
59
+ parser.add_argument("--current-run-id", type=int, required=True)
60
+ parser.add_argument("--current-sha", required=True)
61
+ parser.add_argument("--history-json", default='{"complete": false}')
62
+ parser.add_argument("--github-output")
63
+ args = parser.parse_args()
64
+ try:
65
+ history = json.loads(args.history_json)
66
+ except json.JSONDecodeError:
67
+ history = None
68
+ result = should_run(args.event_name, args.current_run_id, args.current_sha, history)
69
+ if args.github_output:
70
+ with open(args.github_output, "a", encoding="utf-8") as output:
71
+ output.write(f"run={'true' if result['run'] else 'false'}\n")
72
+ output.write(f"reason={result['reason']}\n")
73
+ print(json.dumps(result, sort_keys=True, separators=(",", ":")))
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()