From 5cfecdedb751449fa8acaccbbca122d4a357fe8b Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 21 Aug 2024 10:51:42 -0700 Subject: [PATCH] scripts: add build-matrix script to ease matching ci problem: we have good scripts for running in our images locally, but not always with all the same flags as in CI solution: add a script, build-matrix, that takes a name from the actions build matrix and runs docker_run_checks with the same flags as that matrix entry --- scripts/build-matrix | 64 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 scripts/build-matrix diff --git a/scripts/build-matrix b/scripts/build-matrix new file mode 100755 index 000000000..915405156 --- /dev/null +++ b/scripts/build-matrix @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 + +import argparse +from pprint import pprint +import json +import os +from pathlib import Path +from re import L +import platform +import subprocess as sp +import shlex +import sys + +p = argparse.ArgumentParser() +p.add_argument("-p","--platform", default=platform.machine()) +p.add_argument("--interactive", action="store_true") +p.add_argument("name") +args = p.parse_args() + +my_path = Path(__file__).absolute() +generate_matrix = my_path.parent.parent.joinpath("src/test/generate-matrix.py") +docker_run_checks = my_path.parent.parent.joinpath("src/test/docker/docker-run-checks.sh") +includes = json.loads(sp.check_output([generate_matrix], env={ + "GITHUB_REF": "refs/heads/master" +}).decode())["include"] +matrix = {} +for b in includes: + matrix[b['name']] = b + +plt = args.platform +if plt in ('x86_64', 'amd64'): + plt = 'test-install' +elif plt == 'aarch64': + plt = 'arm64' +suffix = plt +suffix = f" - {suffix}" + +def usage(): + print("specify the name of a matrix entry as the first argument, from this list:") + for tgt in matrix.keys(): + print(tgt) + +tgt = None +if args.name in matrix: + tgt = matrix[args.name] +else: + tgt = matrix.get(f"{args.name}{suffix}", None) + +if tgt is None: + usage() + sys.exit(1) + + +cmd_arr = shlex.split(tgt['command']) +brk = cmd_arr.index("--") +if args.interactive: + cmd_arr.insert(brk, f"--interactive") +cmd_arr.insert(brk, "-D") +cmd_arr.insert(brk+1, f"build/{tgt['image']}") +print(f"running {cmd_arr} with env={tgt['env']}") +base_env = dict(os.environ) +base_env.update(tgt['env']) +sp.call(cmd_arr, env=base_env) +