[bazel] Update copybara scripts (#8822)

I've been running my copybara syncs from this branch for a long time.
Finally deciding to PR it.

The biggest update was due to `mostrobotpy` absorbing the commands,
examples, and pyfrc libraries, but I also added in hooks to "enable" the
flakey `xfail` tests on the allwpilib side, and the ability to run
verbose or force push updates.
This commit is contained in:
PJ Reiniger
2026-04-26 18:14:58 -04:00
committed by GitHub
parent c511fcc160
commit a695865781
2 changed files with 98 additions and 106 deletions

View File

@@ -26,7 +26,13 @@ class CopybaraConfig:
allwpilib_truth_branch: str = "2027"
def run_copybara(copybara_file: pathlib.Path, migration: str, destination_url: str):
def run_copybara(
copybara_file: pathlib.Path,
migration: str,
destination_url: str,
force: bool,
verbose: bool,
):
args = [
"bazel",
"run",
@@ -35,12 +41,16 @@ def run_copybara(copybara_file: pathlib.Path, migration: str, destination_url: s
"migrate",
str(copybara_file),
migration,
"--force",
"--git-destination-url",
destination_url,
"--git-destination-non-fast-forward",
]
if force:
args.append("--force")
if verbose:
args.append("--verbose")
subprocess.check_call(args)
@@ -99,25 +109,31 @@ def allwpilib_to_mostrobotpy(
wpilib_bin_version: str,
is_development_build: bool,
auto_delete_branch: bool,
force: bool,
verbose: bool,
):
run_copybara(copybara_file, "allwpilib_to_mostrobotpy", mostrobotpy_fork_repo)
run_copybara(
copybara_file, "allwpilib_to_mostrobotpy", mostrobotpy_fork_repo, force, verbose
)
os.chdir(mostrobotpy_local_repository)
checkout_branch(auto_delete_branch, "copybara_allwpilib_to_mostrobotpy")
update_mostrobotpy_rdev(wpilib_bin_version, is_development_build)
# Run black
subprocess.check_call(["black", "."])
subprocess.check_call(["git", "add", "-A"])
subprocess.call(["git", "commit", "-m", "Run black"])
subprocess.check_call(["git", "push", "-f"])
def mostrobotpy_to_allwpilib(copybara_file: pathlib.Path, allwpilib_fork):
run_copybara(copybara_file, "mostrobotpy_to_allwpilib", allwpilib_fork)
def commandsv2_to_allwpilib(copybara_file: pathlib.Path, allwpilib_fork):
run_copybara(copybara_file, "commandsv2_to_allwpilib", allwpilib_fork)
def allwpilib_to_commandsv2(copybara_file: pathlib.Path, allwpilib_fork):
run_copybara(copybara_file, "allwpilib_to_commandsv2", allwpilib_fork)
def mostrobotpy_to_allwpilib(
copybara_file: pathlib.Path, allwpilib_fork, force: bool, verbose: bool
):
run_copybara(
copybara_file, "mostrobotpy_to_allwpilib", allwpilib_fork, force, verbose
)
def load_user_config() -> CopybaraConfig:
@@ -144,6 +160,9 @@ def main():
dest="migration", required=True, help="Available commands"
)
parser.add_argument("--force", action="store_true")
parser.add_argument("--verbose", action="store_true")
def add_allwpilib_fork_arg(subparser):
subparser.add_argument(
"--allwpilib_fork_repo",
@@ -191,24 +210,6 @@ def main():
)
add_allwpilib_fork_arg(mostrobotpy_to_allwpilib_parser)
# allwpilib -> commands-v2
allwpilib_to_commandsv2_parser = subparsers.add_parser(
"allwpilib_to_commandsv2",
help="Pushes changes from the allwpilib mirror to the robotpy commands-v2 repo",
)
allwpilib_to_commandsv2_parser.add_argument(
"--robotpy_commandsv2_fork_repo",
default=user_config.robotpy_commandsv2_fork_repo,
help="URL to your github fork of mostrobotpy that you have write permissions for",
)
# commands-v2 -> allwpilib
commandsv2_to_allwpilib_parser = subparsers.add_parser(
"commandsv2_to_allwpilib",
help="Pulls changes from the robotpy commands-v2 source of truth into this mirror",
)
add_allwpilib_fork_arg(commandsv2_to_allwpilib_parser)
script_dir = pathlib.Path(__file__).parent
copybara_file = script_dir / "../../../copy.bara.sky"
@@ -230,25 +231,17 @@ def main():
args.wpilib_bin_version,
args.development_build,
args.auto_delete_branch,
args.force,
args.verbose,
)
elif args.migration == "mostrobotpy_to_allwpilib":
if args.allwpilib_fork_repo is None:
raise Exception(
"You mist specify allwpilib_fork_repo, either on the command line or in your user config"
)
mostrobotpy_to_allwpilib(copybara_file, args.allwpilib_fork_repo)
elif args.migration == "allwpilib_to_commandsv2":
if args.robotpy_commandsv2_fork_repo is None:
raise Exception(
"You mist specify robotpy_commandsv2_fork_repo, either on the command line or in your user config"
)
allwpilib_to_commandsv2(copybara_file, args.robotpy_commandsv2_fork_repo)
elif args.migration == "commandsv2_to_allwpilib":
if args.allwpilib_fork_repo is None:
raise Exception(
"You mist specify allwpilib_fork_repo, either on the command line or in your user config"
)
commandsv2_to_allwpilib(copybara_file, args.allwpilib_fork_repo)
mostrobotpy_to_allwpilib(
copybara_file, args.allwpilib_fork_repo, args.force, args.verbose
)
else:
raise Exception(f"Unexpected migration {args.migration}")