Windows와 Ubuntu Rust 빌드 및 시험 CI 추가
- 작성자
- 코노모리 카논
- 작성 시각
- 커밋
f0a86969417c3136f03fbb092ff01f77243a1372- 부모
- 78cb231
변경된 파일 5개
+246-0| @@ -0,0 +1,52 @@ | ||
| 1 | 추가: name: Rust build and tests | |
| 2 | 추가: | |
| 3 | 추가: on: | |
| 4 | 추가: pull_request: | |
| 5 | 추가: push: | |
| 6 | 추가: branches: [main] | |
| 7 | 추가: workflow_dispatch: | |
| 8 | 추가: | |
| 9 | 추가: permissions: | |
| 10 | 추가: contents: read | |
| 11 | 추가: | |
| 12 | 추가: concurrency: | |
| 13 | 추가: group: rust-${{ github.workflow }}-${{ github.ref }} | |
| 14 | 추가: cancel-in-progress: true | |
| 15 | 추가: | |
| 16 | 추가: jobs: | |
| 17 | 추가: rust: | |
| 18 | 추가: name: Rust (${{ matrix.os }}) | |
| 19 | 추가: runs-on: ${{ matrix.os }} | |
| 20 | 추가: timeout-minutes: 45 | |
| 21 | 추가: strategy: | |
| 22 | 추가: fail-fast: false | |
| 23 | 추가: matrix: | |
| 24 | 추가: os: [ubuntu-latest, windows-latest] | |
| 25 | 추가: env: | |
| 26 | 추가: CARGO_TERM_COLOR: always | |
| 27 | 추가: CARGO_BUILD_JOBS: 1 | |
| 28 | 추가: CARGO_TARGET_DIR: ${{ github.workspace }}/tests/ci/target | |
| 29 | 추가: RUST_BACKTRACE: 1 | |
| 30 | 추가: steps: | |
| 31 | 추가: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 | |
| 32 | 추가: with: | |
| 33 | 추가: persist-credentials: false | |
| 34 | 추가: - uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 | |
| 35 | 추가: with: | |
| 36 | 추가: python-version: '3.13' | |
| 37 | 추가: - name: Install Rust | |
| 38 | 추가: run: rustup toolchain install 1.99.1 --profile minimal --no-self-update | |
| 39 | 추가: - name: Install Linux GUI build dependencies and test font | |
| 40 | 추가: if: runner.os == 'Linux' | |
| 41 | 추가: run: | | |
| 42 | 추가: sudo apt-get update | |
| 43 | 추가: sudo apt-get install -y pkg-config libxkbcommon-dev libwayland-dev libgl1-mesa-dev fonts-noto-cjk | |
| 44 | 추가: - name: Check CI runner | |
| 45 | 추가: run: python -m unittest discover -s tests/ci -p 'test_*.py' -v | |
| 46 | 추가: - name: Build every Rust crate and test harness | |
| 47 | 추가: timeout-minutes: 20 | |
| 48 | 추가: run: python tests/ci/run_rust.py build | |
| 49 | 추가: - name: Run Rust tests | |
| 50 | 추가: if: ${{ !cancelled() }} | |
| 51 | 추가: timeout-minutes: 20 | |
| 52 | 추가: run: python tests/ci/run_rust.py test |
| @@ -0,0 +1,2 @@ | ||
| 1 | 추가: /target/ | |
| 2 | 추가: /*-results.json |
| @@ -0,0 +1,17 @@ | ||
| 1 | 추가: # Rust CI | |
| 2 | 추가: | |
| 3 | 추가: `.github/workflows/rust.yml`은 PR, main push와 수동 실행에서 Ubuntu와 Windows를 각각 검사합니다. Rust 1.99.1과 기존 Cargo.lock을 사용하며 제품 소스와 의존성 버전을 바꾸지 않습니다. | |
| 4 | 추가: | |
| 5 | 추가: ```sh | |
| 6 | 추가: python -m unittest discover -s tests/ci -p 'test_*.py' -v | |
| 7 | 추가: python tests/ci/run_rust.py build | |
| 8 | 추가: python tests/ci/run_rust.py test | |
| 9 | 추가: ``` | |
| 10 | 추가: | |
| 11 | 추가: - `experiments/*/Cargo.toml`과 `tests/*/Cargo.toml`을 자동 발견합니다. 새 crate도 같은 구조와 Cargo.lock을 사용하면 포함됩니다. | |
| 12 | 추가: - 모든 target과 feature를 빌드합니다. 시험은 Cargo에 등록된 루트 tests/의 Rust 회귀와 crate의 단위시험을 실행합니다. 시험 스레드는 1개입니다. | |
| 13 | 추가: - Linux 전용 publication, snapshot, file-job, system-font 시험은 Windows에서 `not-applicable`로 표시합니다. 해당 crate의 Windows 빌드는 확인합니다. | |
| 14 | 추가: - Linux 파일 시험에는 새 소유 `runs` 디렉터리를 0700으로 생성합니다. 기존 디렉터리의 권한은 변경하지 않으며 비어 있지 않으면 중단합니다. 글꼴 시험에는 `fonts-noto-cjk`가 필요합니다. | |
| 15 | 추가: - GUI 앱과 GUI race harness는 컴파일하며 실제 GUI 시나리오는 실행하지 않습니다. C# 시험과 역사적 manifest/hash 검사는 이 Rust CI 범위에 포함하지 않습니다. | |
| 16 | 추가: - Cargo 실패를 숨기지 않고 나머지 crate 결과도 수집한 뒤 실패로 종료합니다. OS 간에는 fail-fast를 끕니다. 빌드와 시험 단계는 각각 20분, 전체 job은 45분 제한입니다. | |
| 17 | 추가: - 결과는 Actions 로그와 job summary 및 로컬 `tests/ci/*-results.json`에 남습니다. 공유 target은 `tests/ci/target`이며 `CARGO_TARGET_DIR`로 바꿀 수 있습니다. |
| @@ -0,0 +1,116 @@ | ||
| 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()) |
| @@ -0,0 +1,59 @@ | ||
| 1 | 추가: from pathlib import Path | |
| 2 | 추가: import subprocess | |
| 3 | 추가: import unittest | |
| 4 | 추가: from unittest.mock import patch | |
| 5 | 추가: | |
| 6 | 추가: import run_rust | |
| 7 | 추가: | |
| 8 | 추가: | |
| 9 | 추가: class RunnerTests(unittest.TestCase): | |
| 10 | 추가: def test_all_manifests_have_locks(self): | |
| 11 | 추가: paths = run_rust.manifests(run_rust.ROOT) | |
| 12 | 추가: expected = set(run_rust.ROOT.glob("experiments/*/Cargo.toml")) | |
| 13 | 추가: expected |= set(run_rust.ROOT.glob("tests/*/Cargo.toml")) | |
| 14 | 추가: self.assertEqual(set(paths), expected) | |
| 15 | 추가: | |
| 16 | 추가: def test_failure_does_not_hide_later_crates(self): | |
| 17 | 추가: paths = [ | |
| 18 | 추가: Path("/repo/experiments/a/Cargo.toml"), | |
| 19 | 추가: Path("/repo/experiments/b/Cargo.toml"), | |
| 20 | 추가: ] | |
| 21 | 추가: with ( | |
| 22 | 추가: patch.object(run_rust, "manifests", return_value=paths), | |
| 23 | 추가: patch.object(run_rust.subprocess, "run", side_effect=[ | |
| 24 | 추가: subprocess.CompletedProcess([], 7), | |
| 25 | 추가: subprocess.CompletedProcess([], 0), | |
| 26 | 추가: ]), | |
| 27 | 추가: ): | |
| 28 | 추가: results = run_rust.run(Path("/repo"), "build") | |
| 29 | 추가: self.assertEqual([row["status"] for row in results], ["failed", "passed"]) | |
| 30 | 추가: self.assertEqual(results[0]["exit_code"], 7) | |
| 31 | 추가: | |
| 32 | 추가: def test_windows_exclusion_is_explicit_and_only_for_linux_tests(self): | |
| 33 | 추가: paths = [ | |
| 34 | 추가: Path("/repo/tests/rust-file-publication/Cargo.toml"), | |
| 35 | 추가: Path("/repo/experiments/rust-file-publication/Cargo.toml"), | |
| 36 | 추가: ] | |
| 37 | 추가: with ( | |
| 38 | 추가: patch.object(run_rust, "manifests", return_value=paths), | |
| 39 | 추가: patch.object(run_rust.sys, "platform", "win32"), | |
| 40 | 추가: patch.object( | |
| 41 | 추가: run_rust.subprocess, "run", | |
| 42 | 추가: return_value=subprocess.CompletedProcess([], 0), | |
| 43 | 추가: ) as execute, | |
| 44 | 추가: ): | |
| 45 | 추가: results = run_rust.run(Path("/repo"), "test") | |
| 46 | 추가: self.assertEqual( | |
| 47 | 추가: [row["status"] for row in results], ["not-applicable", "passed"] | |
| 48 | 추가: ) | |
| 49 | 추가: self.assertEqual(execute.call_count, 1) | |
| 50 | 추가: | |
| 51 | 추가: def test_cargo_contract(self): | |
| 52 | 추가: args = run_rust.command(Path("tests/example/Cargo.toml"), "test") | |
| 53 | 추가: self.assertIn("--locked", args) | |
| 54 | 추가: self.assertIn("--all-features", args) | |
| 55 | 추가: self.assertEqual(args[-2:], ["--", "--test-threads=1"]) | |
| 56 | 추가: | |
| 57 | 추가: | |
| 58 | 추가: if __name__ == "__main__": | |
| 59 | 추가: unittest.main() |