Files

94 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""VDE 平台 CI 配置的静态自检(不触发构建)。
检查:
- CMakePresets.json 必填 configure/build/test preset;
- tools/ci 平台脚本存在;
- 平台 workflow 模板含 linux/windows/macos;
- shell/PowerShell 脚本语法(工具存在时)。
"""
from __future__ import annotations
import argparse
import json
import pathlib
import shutil
import subprocess
REQUIRED = [
"linux-release", "linux-debug", "macos-release",
"windows-msvc-release", "windows-msvc-debug",
"windows-msvc2026-release", "windows-msvc2026-debug",
]
def fail(message: str) -> None:
print(f"FAIL: {message}")
raise SystemExit(1)
def run_checked(cmd: list[str], label: str) -> None:
try:
result = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
except Exception as exc: # noqa: BLE001
fail(f"{label}: {exc}")
if result.returncode != 0:
detail = (result.stderr or result.stdout).strip()
fail(f"{label}: exit {result.returncode}: {detail}")
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--root", default=".")
args = parser.parse_args()
root = pathlib.Path(args.root).resolve()
preset_path = root / "CMakePresets.json"
if not preset_path.exists():
fail("missing CMakePresets.json")
try:
presets = json.loads(preset_path.read_text(encoding="utf-8"))
except Exception as exc: # noqa: BLE001
fail(f"CMakePresets.json invalid JSON: {exc}")
for section in ("configurePresets", "buildPresets", "testPresets"):
names = {item.get("name") for item in presets.get(section, [])}
for required in REQUIRED:
if required not in names:
fail(f"{section} missing preset {required}")
for rel in ("tools/ci/run_platform_ci.sh", "tools/ci/run_platform_ci.ps1",
"tools/ci/validate_ci.py",
"docs/ci-templates/platform-ci/platform-ci.yml"):
if not (root / rel).is_file():
fail(f"missing {rel}")
workflow = (root / "docs/ci-templates/platform-ci/platform-ci.yml").read_text(
encoding="utf-8")
for token in ("linux", "windows", "macos", "linux-release",
"windows-msvc-release"):
if token not in workflow:
fail(f"platform workflow missing {token}")
bash = shutil.which("bash")
if bash:
run_checked([bash, "-n", str(root / "tools/ci/run_platform_ci.sh")],
"bash syntax")
pwsh = shutil.which("pwsh")
if pwsh:
script = str(root / "tools/ci/run_platform_ci.ps1").replace("'", "''")
command = (
"$e=$null; [System.Management.Automation.Language.Parser]::ParseFile("
f"'{script}',[ref]$null,[ref]$e) | Out-Null; if($e){{exit 1}}"
)
run_checked([pwsh, "-NoProfile", "-Command", command],
"powershell syntax")
print("PASS: CMakePresets / platform scripts / workflow template")
return 0
if __name__ == "__main__":
raise SystemExit(main())