A wrapper to run commands in a directory (specifically for use in CI tests)
| 30 | |
| 31 | |
| 32 | class TempGit: |
| 33 | """ |
| 34 | A wrapper to run commands in a directory (specifically for use in CI tests) |
| 35 | """ |
| 36 | |
| 37 | def __init__(self, cwd): |
| 38 | self.cwd = cwd |
| 39 | # Jenkins git is too old and doesn't have 'git init --initial-branch', |
| 40 | # so init and checkout need to be separate steps |
| 41 | self.run("init", stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
| 42 | self.run("checkout", "-b", "main", stderr=subprocess.PIPE) |
| 43 | self.run("remote", "add", "origin", "https://github.com/apache/tvm.git") |
| 44 | |
| 45 | def run(self, *args, **kwargs): |
| 46 | """ |
| 47 | Run a git command based on *args |
| 48 | """ |
| 49 | proc = subprocess.run( |
| 50 | ["git"] + list(args), encoding="utf-8", cwd=self.cwd, check=False, **kwargs |
| 51 | ) |
| 52 | if proc.returncode != 0: |
| 53 | raise RuntimeError(f"git command failed: '{args}'") |
| 54 | |
| 55 | return proc |
| 56 | |
| 57 | |
| 58 | def run_script(command: list[Any], check: bool = True, **kwargs): |
no outgoing calls
searching dependent graphs…