|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Script to run template replay tests for all test configuration files. |
| 4 | +Executes: repo.sh template replay <TEST_FILE> for each test file, |
| 5 | +followed by a single repo.sh build to verify the templates can be built. |
| 6 | +""" |
| 7 | + |
| 8 | +import subprocess |
| 9 | +import os |
| 10 | +import sys |
| 11 | +import platform |
| 12 | +from pathlib import Path |
| 13 | + |
| 14 | +# List of test files to process |
| 15 | +TEST_FILES = [ |
| 16 | + ".github/workflows/replay_files/base_editor", |
| 17 | + ".github/workflows/replay_files/usd_composer", |
| 18 | + ".github/workflows/replay_files/usd_explorer", |
| 19 | + ".github/workflows/replay_files/usd_viewer", |
| 20 | + ".github/workflows/replay_files/kit_service", |
| 21 | +] |
| 22 | + |
| 23 | +# Determine the repo script based on OS |
| 24 | +REPO_SCRIPT = "repo.bat" if platform.system() == "Windows" else "./repo.sh" |
| 25 | + |
| 26 | + |
| 27 | +def run_template_replay(test_file: str) -> bool: |
| 28 | + """ |
| 29 | + Run repo.sh template replay for a given test file. |
| 30 | +
|
| 31 | + Args: |
| 32 | + test_file: Name of the test file to process |
| 33 | +
|
| 34 | + Returns: |
| 35 | + True if successful, False if failed |
| 36 | + """ |
| 37 | + cmd = [REPO_SCRIPT, "template", "replay", test_file] |
| 38 | + |
| 39 | + print(f"Running: {' '.join(cmd)}") |
| 40 | + |
| 41 | + try: |
| 42 | + result = subprocess.run( |
| 43 | + cmd, |
| 44 | + check=True, |
| 45 | + capture_output=False, |
| 46 | + text=True, |
| 47 | + timeout=300 # 5 minute timeout |
| 48 | + ) |
| 49 | + |
| 50 | + print(f"SUCCESS: {test_file}") |
| 51 | + if result.stdout: |
| 52 | + print(f" Output: {result.stdout.strip()}") |
| 53 | + return True |
| 54 | + |
| 55 | + except subprocess.CalledProcessError as e: |
| 56 | + print(f"FAILED: {test_file}") |
| 57 | + print(f" Return code: {e.returncode}") |
| 58 | + if e.stdout: |
| 59 | + print(f" Stdout: {e.stdout.strip()}") |
| 60 | + if e.stderr: |
| 61 | + print(f" Stderr: {e.stderr.strip()}") |
| 62 | + return False |
| 63 | + |
| 64 | + except subprocess.TimeoutExpired: |
| 65 | + print(f"TIMEOUT: {test_file} (exceeded 5 minutes)") |
| 66 | + return False |
| 67 | + |
| 68 | + except FileNotFoundError: |
| 69 | + print(f"ERROR: {REPO_SCRIPT} not found. Make sure you're in the correct directory.") |
| 70 | + return False |
| 71 | + |
| 72 | + |
| 73 | +def run_build() -> bool: |
| 74 | + """ |
| 75 | + Run repo.sh build to verify the templates can be built. |
| 76 | +
|
| 77 | + Returns: |
| 78 | + True if successful, False if failed |
| 79 | + """ |
| 80 | + cmd = [REPO_SCRIPT, "build"] |
| 81 | + |
| 82 | + print(f"Running: {' '.join(cmd)}") |
| 83 | + |
| 84 | + try: |
| 85 | + result = subprocess.run( |
| 86 | + cmd, |
| 87 | + check=True, |
| 88 | + capture_output=False, |
| 89 | + text=True, |
| 90 | + timeout=600 # 10 minute timeout for build |
| 91 | + ) |
| 92 | + |
| 93 | + print("SUCCESS: Build completed") |
| 94 | + if result.stdout: |
| 95 | + print(f" Output: {result.stdout.strip()}") |
| 96 | + return True |
| 97 | + |
| 98 | + except subprocess.CalledProcessError as e: |
| 99 | + print("FAILED: Build") |
| 100 | + print(f" Return code: {e.returncode}") |
| 101 | + if e.stdout: |
| 102 | + print(f" Stdout: {e.stdout.strip()}") |
| 103 | + if e.stderr: |
| 104 | + print(f" Stderr: {e.stderr.strip()}") |
| 105 | + return False |
| 106 | + |
| 107 | + except subprocess.TimeoutExpired: |
| 108 | + print("TIMEOUT: Build (exceeded 10 minutes)") |
| 109 | + return False |
| 110 | + |
| 111 | + except FileNotFoundError: |
| 112 | + print(f"ERROR: {REPO_SCRIPT} not found. Make sure you're in the correct directory.") |
| 113 | + return False |
| 114 | + |
| 115 | + |
| 116 | +def main(): |
| 117 | + """Main function to run all template replay tests.""" |
| 118 | + |
| 119 | + os.chdir(Path(__file__).parent.parent.parent.resolve()) # Change to script's parent directory |
| 120 | + print("Starting template replay tests...") |
| 121 | + print("=" * 50) |
| 122 | + |
| 123 | + # Check if repo script exists |
| 124 | + repo_path = Path(REPO_SCRIPT.replace("./", "")) |
| 125 | + if not repo_path.exists(): |
| 126 | + print(f"ERROR: {REPO_SCRIPT} not found in current directory") |
| 127 | + print(repo_path.resolve()) |
| 128 | + print("Please run this script from the repository root.") |
| 129 | + sys.exit(1) |
| 130 | + |
| 131 | + # Check to see if .omniverse_eula_accepted.txt exists. If not, make it. |
| 132 | + eula_file = Path(".omniverse_eula_accepted.txt") |
| 133 | + if not eula_file.exists(): |
| 134 | + print("Creating .omniverse_eula_accepted.txt to accept EULA") |
| 135 | + eula_file.touch() |
| 136 | + |
| 137 | + success_count = 0 |
| 138 | + total_count = len(TEST_FILES) |
| 139 | + |
| 140 | + for test_file in TEST_FILES: |
| 141 | + print() |
| 142 | + if run_template_replay(test_file): |
| 143 | + success_count += 1 |
| 144 | + |
| 145 | + print() |
| 146 | + print("=" * 50) |
| 147 | + print(f"SUMMARY: {success_count}/{total_count} template replay tests passed") |
| 148 | + |
| 149 | + # Delete .omniverse_eula_accepted.txt if it was created |
| 150 | + print("Deleting .omniverse_eula_accepted.txt") |
| 151 | + eula_file.unlink(missing_ok=True) |
| 152 | + |
| 153 | + # Overall success depends template replays |
| 154 | + if success_count == total_count: |
| 155 | + print("\nTemplate creation passed!") |
| 156 | + sys.exit(0) |
| 157 | + else: |
| 158 | + if success_count < total_count: |
| 159 | + print(f"\n{total_count - success_count} template replay(s) failed") |
| 160 | + sys.exit(1) |
| 161 | + |
| 162 | + |
| 163 | +if __name__ == "__main__": |
| 164 | + main() |
0 commit comments