File size: 3,383 Bytes
e7b8e7e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | """Validate a render request and expose its settings to GitHub Actions."""
import json
import math
import os
from pathlib import Path
import re
import subprocess
from final_review import validate_final_review
def read_request():
if os.environ["EVENT"] == "workflow_dispatch":
return json.loads(os.environ["INPUTS"])
added = subprocess.check_output(
["git", "diff-tree", "--root", "--no-commit-id", "--diff-filter=A", "-r",
"--name-only", "HEAD", "--", "render-requests/"],
text=True,
).splitlines()
requests = [p for p in added if re.fullmatch(r"render-requests/[a-z0-9-]+\.json", p)]
if len(requests) != 1:
raise SystemExit("Add exactly one new render-requests/<id>.json per launch commit.")
return json.loads(Path(requests[0]).read_text(encoding="utf-8"))
def main():
request = read_request()
root = Path("scenes").resolve(strict=True)
raw_scene = request["scene"]
if not re.fullmatch(r"scenes/(?:[a-zA-Z0-9_-]+/)*[a-zA-Z0-9_-]+\.py", raw_scene):
raise SystemExit("Choose a Python file under scenes/.")
scene = Path(raw_scene).resolve(strict=True)
if not scene.is_relative_to(root) or not scene.is_file():
raise SystemExit("Scene must be a file under scenes/.")
duration = float(request.get("duration", 3))
fps_value = str(request.get("fps", 30))
video_format = request.get("format", "horizontal")
voice = request.get("voice", False)
if not math.isfinite(duration) or not 0 < duration <= 300:
raise SystemExit("Duration must be greater than zero and at most 300 seconds.")
if not re.fullmatch(r"[0-9]{1,3}", fps_value) or not 1 <= int(fps_value) <= 120:
raise SystemExit("FPS must be between 1 and 120.")
if video_format not in ("horizontal", "vertical", "square") or not isinstance(voice, bool):
raise SystemExit("Invalid video format or voice option.")
stage = request.get("stage", "standard")
if stage not in ("standard", "assets", "draft", "final"):
raise SystemExit("Invalid render stage.")
checks = request.get("checkpoints", [])
if not isinstance(checks, list) or len(checks) > 20:
raise SystemExit("Supply at most 20 checkpoints.")
if stage in ("draft", "final") and not checks:
raise SystemExit("Draft and final requests require checkpoints.")
for check in checks:
if (not isinstance(check, dict) or set(check) != {"time", "label"}
or type(check["time"]) not in (int, float) or not 0 <= check["time"] < duration
or not isinstance(check["label"], str) or not 0 < len(check["label"].strip()) <= 100):
raise SystemExit("Checkpoint requires an in-range time and a short label.")
motion = request.get("motion")
if motion is not None:
from motion_review import validate_motion
validate_motion(motion, duration)
print("motion=" + json.dumps(motion or [], ensure_ascii=True, separators=(",", ":")))
if stage == "final":
validate_final_review(request)
print(f"stage={stage}")
print("checkpoints=" + json.dumps(checks, ensure_ascii=True, separators=(",", ":")))
print(f"scene={raw_scene}")
print(f"duration={duration}")
print(f"fps={int(fps_value)}")
print(f"format={video_format}")
print(f"voice={str(voice).lower()}")
if __name__ == "__main__":
main()
|