Fix issue with nested script strings in CI reproduce script

The `reproduce_ci_env.py` script reads in the yaml for the GitLab
runners and replicates the runs using Docker. Through a quirk of the
implemenation of MR !3191, some of the scripts, which are expected to be
a list of command strings, get defined as a list of lists. This is fixed
by flattening this list of commands.
This commit is contained in:
Kenneth Moreland 2024-02-21 16:43:59 -05:00
parent d8a7a9326c
commit e1557f080b

@ -196,13 +196,22 @@ def create_container(ci_file_path, *args):
if os.getenv('https_proxy'):
gitlab_env = [ 'https_proxy=' + os.getenv('https_proxy') ] + gitlab_env
def clean_script(script):
if isinstance(script, list):
from itertools import chain
return list(chain(*[clean_script(command) for command in script]))
elif isinstance(script, str):
return [script.strip()]
else:
raise(TypeError('Encountered bad type in script: `{}`'.format(type(script).__name__)))
# The script and before_script could be anywhere!
script_search_locations = [ci_state, subset, runner]
for loc in script_search_locations:
if 'before_script' in loc:
before_script = [command.strip() for command in loc['before_script']]
before_script = clean_script(loc['before_script'])
if 'script' in loc:
script = [command.strip() for command in loc['script']]
script = clean_script(loc['script'])
docker_template = string.Template('''
FROM $image