65 lines
1.5 KiB
Python
Executable File
65 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from datetime import UTC, datetime
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
COMMANDS = [
|
|
["ruff", "check", "."],
|
|
["ty", "check"],
|
|
["pytest"],
|
|
[
|
|
sys.executable,
|
|
"scripts/probe_garmin.py",
|
|
"dummy",
|
|
"--date",
|
|
"tomorrow",
|
|
"--dry-run",
|
|
],
|
|
]
|
|
|
|
|
|
def main() -> int:
|
|
results = [_run(command) for command in COMMANDS]
|
|
passed = all(result["returncode"] == 0 for result in results)
|
|
report: dict[str, Any] = {
|
|
"timestamp": datetime.now(tz=UTC).isoformat(),
|
|
"passed": passed,
|
|
"results": results,
|
|
}
|
|
out = ROOT / "debug" / "local_checks.json"
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
out.write_text(json.dumps(report, indent=2), encoding="utf-8")
|
|
|
|
for result in results:
|
|
status = "PASS" if result["returncode"] == 0 else "FAIL"
|
|
print(f"{status}: {' '.join(result['command'])}")
|
|
print(f"Local check report written to {out.relative_to(ROOT)}")
|
|
return 0 if passed else 1
|
|
|
|
|
|
def _run(command: list[str]) -> dict[str, Any]:
|
|
completed = subprocess.run(
|
|
command,
|
|
cwd=ROOT,
|
|
text=True,
|
|
capture_output=True,
|
|
check=False,
|
|
)
|
|
return {
|
|
"command": command,
|
|
"returncode": completed.returncode,
|
|
"stdout": completed.stdout,
|
|
"stderr": completed.stderr,
|
|
}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|
|
|