#!/usr/bin/env python3
import subprocess
import sys
from pathlib import Path

REPO_ROOT = Path(__file__).resolve().parent
CRON_SCRIPTS = REPO_ROOT / "personal" / "cron_scripts"

BUILD_SCRIPTS = [
    CRON_SCRIPTS / "build_multi_powercycle.py",
    CRON_SCRIPTS / "build_set_fanspeed.py",
    CRON_SCRIPTS / "build_ilo_status.py",
    CRON_SCRIPTS / "build_ilo_powercycle.py",
    CRON_SCRIPTS / "build_ipmi_poweron.py",
    CRON_SCRIPTS / "build_ipmi_poweroff.py",
]


def main():
    failures = []
    for script in BUILD_SCRIPTS:
        print(f"\n{'='*60}")
        print(f"Building: {script.name}")
        print(f"{'='*60}")
        result = subprocess.run([sys.executable, str(script)], cwd=REPO_ROOT)
        if result.returncode != 0:
            failures.append(script.name)

    print(f"\n{'='*60}")
    if failures:
        print(f"FAILED builds ({len(failures)}/{len(BUILD_SCRIPTS)}):")
        for name in failures:
            print(f"  - {name}")
        raise SystemExit(1)
    else:
        print(f"All {len(BUILD_SCRIPTS)} builds completed successfully.")
        print(f"Executables are in: {REPO_ROOT / 'dist'}")


if __name__ == "__main__":
    main()
