Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

143 lines
3.2 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
"""Fetches the specific pull request, commit or branch from a repo.
This script is available for users, but it is primarily the mechanism
to fetch a monorepo in the CI.
"""
import argparse
from pathlib import Path
import shlex
import subprocess
import sys
THIS_SCRIPT_DIR = Path(__file__).resolve().parent
def log(*args, **kwargs):
print(*args, **kwargs)
sys.stdout.flush()
def run_command(args: list[str | Path], cwd: Path):
args = [str(arg) for arg in args]
log(f"++ Exec [{cwd}]$ {shlex.join(args)}")
sys.stdout.flush()
subprocess.check_call(args, cwd=str(cwd), stdin=subprocess.DEVNULL)
def fetch_branch(args):
run_command(
["git", "checkout", args.remote_branch],
cwd=args.directory,
)
def fetch_commit(args):
additional_args = []
if args.local_branch:
additional_args += ["-b", args.local_branch]
run_command(
["git", "checkout"] + additional_args + [args.commit],
cwd=args.directory,
)
def fetch_pr(args):
if args.local_branch:
local_branch = args.local_branch
else:
local_branch = args.pr_number
run_command(
["git", "fetch", "origin", f"pull/{args.pr_number}/head:{local_branch}"],
cwd=args.directory,
)
run_command(
["git", "switch", local_branch],
cwd=args.directory,
)
def run(args):
additional_args = []
if args.depth:
additional_args += ["--depth", str(args.depth)]
if args.jobs:
additional_args += ["--jobs", str(args.jobs)]
run_command(
["git", "clone"] + additional_args + [args.repo, args.directory],
cwd=THIS_SCRIPT_DIR,
)
if args.pr_number:
fetch_pr(args)
if args.commit:
fetch_commit(args)
if args.remote_branch:
fetch_branch(args)
def main(argv):
parser = argparse.ArgumentParser(prog="fetch_repo")
parser.add_argument(
"--repo",
type=str,
required=True,
help="Monorepo to fetch",
)
parser.add_argument(
"--directory",
type=Path,
required=True,
help="Name of a new directory to clone into.",
)
parser.add_argument(
"--local-branch",
type=str,
required=False,
help="(Optional) Local branch to create if checking out a PR or commit",
)
parser.add_argument(
"--depth",
type=int,
default=None,
help="Git depth when fetch the repository",
)
parser.add_argument(
"--jobs",
type=int,
help="Number of jobs to use for fetching the repo",
default=None,
)
checkout = parser.add_mutually_exclusive_group()
checkout.add_argument(
"--pr-number",
type=int,
help="Pull request (PR) number to checkout",
)
checkout.add_argument(
"--commit",
type=str,
help="Commit hash to checkout",
)
checkout.add_argument(
"--remote-branch",
type=str,
help="Remote branch to checkout",
)
args = parser.parse_args(argv)
run(args)
if __name__ == "__main__":
main(sys.argv[1:])