| 1 | import argparse |
| 2 | import json |
| 3 | import os |
| 4 | from pathlib import Path |
| 5 | import stat |
| 6 | import subprocess |
| 7 | import sys |
| 8 | |
| 9 | |
| 10 | ROOT = Path(__file__).resolve().parents[2] |
| 11 | TOOLCHAIN = "+1.99.1" |
| 12 | LINUX_ONLY = { |
| 13 | "rust-file-publication", |
| 14 | "rust-file-snapshot", |
| 15 | "rust-gzip-file-job", |
| 16 | "rust-ui-system-font-regressions", |
| 17 | } |
| 18 | FILE_FIXTURES = LINUX_ONLY - {"rust-ui-system-font-regressions"} |
| 19 | |
| 20 | |
| 21 | def manifests(root): |
| 22 | paths = sorted(root.glob("experiments/*/Cargo.toml")) |
| 23 | if not paths: |
| 24 | raise ValueError("experiments/ Rust crate를 찾지 못함") |
| 25 | paths += sorted(root.glob("tests/*/Cargo.toml")) |
| 26 | for path in paths: |
| 27 | if not path.with_name("Cargo.lock").is_file(): |
| 28 | raise ValueError(f"고정 Cargo.lock이 없음: {path}") |
| 29 | return paths |
| 30 | |
| 31 | |
| 32 | def command(manifest, phase): |
| 33 | arguments = [ |
| 34 | "cargo", |
| 35 | TOOLCHAIN, |
| 36 | phase, |
| 37 | "--manifest-path", |
| 38 | str(manifest), |
| 39 | "--locked", |
| 40 | "--all-targets", |
| 41 | "--all-features", |
| 42 | ] |
| 43 | if phase == "test": |
| 44 | arguments += ["--", "--test-threads=1"] |
| 45 | return arguments |
| 46 | |
| 47 | |
| 48 | def prepare_fixtures(root): |
| 49 | for name in sorted(FILE_FIXTURES): |
| 50 | path = root / "tests" / name / "runs" |
| 51 | if not path.exists() and not path.is_symlink(): |
| 52 | path.mkdir(mode=0o700) |
| 53 | info = path.lstat() |
| 54 | if ( |
| 55 | not stat.S_ISDIR(info.st_mode) |
| 56 | or stat.S_IMODE(info.st_mode) != 0o700 |
| 57 | or info.st_uid != os.geteuid() |
| 58 | or path.resolve() != path |
| 59 | or any(path.iterdir()) |
| 60 | ): |
| 61 | raise ValueError(f"비어 있는 소유 시험 디렉터리가 필요함: {path}") |
| 62 | |
| 63 | |
| 64 | def run(root, phase): |
| 65 | paths = manifests(root) |
| 66 | if phase == "test" and sys.platform == "linux": |
| 67 | prepare_fixtures(root) |
| 68 | results = [] |
| 69 | for manifest in paths: |
| 70 | relative = manifest.relative_to(root).as_posix() |
| 71 | if ( |
| 72 | phase == "test" |
| 73 | and sys.platform != "linux" |
| 74 | and manifest.parent.parent.name == "tests" |
| 75 | and manifest.parent.name in LINUX_ONLY |
| 76 | ): |
| 77 | results.append({ |
| 78 | "manifest": relative, |
| 79 | "status": "not-applicable", |
| 80 | "reason": "Linux-only cfg", |
| 81 | }) |
| 82 | print(f"NOT APPLICABLE: {relative} (Linux-only cfg)", flush=True) |
| 83 | continue |
| 84 | print(f"::group::{phase}: {relative}", flush=True) |
| 85 | completed = subprocess.run(command(manifest, phase), cwd=root, check=False) |
| 86 | results.append({ |
| 87 | "manifest": relative, |
| 88 | "status": "passed" if completed.returncode == 0 else "failed", |
| 89 | "exit_code": completed.returncode, |
| 90 | }) |
| 91 | print("::endgroup::", flush=True) |
| 92 | return results |
| 93 | |
| 94 | |
| 95 | def main(): |
| 96 | parser = argparse.ArgumentParser(description="Rust crate 전체 빌드와 tests/ 회귀 실행") |
| 97 | parser.add_argument("phase", choices=["build", "test"]) |
| 98 | args = parser.parse_args() |
| 99 | os.environ.setdefault("CARGO_BUILD_JOBS", "1") |
| 100 | os.environ.setdefault("CARGO_TARGET_DIR", str(ROOT / "tests/ci/target")) |
| 101 | results = run(ROOT, args.phase) |
| 102 | (ROOT / f"tests/ci/{args.phase}-results.json").write_text( |
| 103 | json.dumps(results, ensure_ascii=False, indent=4) + "\n", encoding="utf-8" |
| 104 | ) |
| 105 | summary = os.environ.get("GITHUB_STEP_SUMMARY") |
| 106 | if summary: |
| 107 | with open(summary, "a", encoding="utf-8") as output: |
| 108 | output.write(f"\nRust {args.phase} ({sys.platform})\n\n") |
| 109 | for result in results: |
| 110 | output.write(f"- {result['manifest']}: {result['status']}\n") |
| 111 | output.write("\nGUI harness는 컴파일만 확인하며 실제 화면 시나리오는 실행하지 않음.\n") |
| 112 | return int(any(result["status"] == "failed" for result in results)) |
| 113 | |
| 114 | |
| 115 | if __name__ == "__main__": |
| 116 | raise SystemExit(main()) |