Skip to content

Commit

Permalink
scripts: add build-matrix script to ease matching ci
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trws committed Aug 21, 2024
1 parent 17b756c commit 5cfecde
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions scripts/build-matrix
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 5cfecde

Please sign in to comment.