diff --git a/bou.py b/bou.py index dae323f..d23471d 100755 --- a/bou.py +++ b/bou.py @@ -12,6 +12,10 @@ BUILD_FILES = ['build.yaml', 'build.yml', 'bou.yaml', 'bou.yml'] ENV_VAR = re.compile(r'(\$([A-Za-z0-9_]+))') +class StepFailedError(Exception): + pass + + def parse_args(): """ Parse command line arguments, and return an object with all the arguments @@ -55,6 +59,7 @@ def setup_step(config, step_name): """ step = config['steps'][step_name] step['environment'] = config.get('environment', []) + step.get('environment', []) + step['name'] = step_name return step @@ -91,7 +96,9 @@ def run_step(step, base_path): for output in iter(lambda: proc.stdout.read(1), b''): sys.stdout.buffer.write(output) sys.stdout.buffer.flush() - return proc.returncode == 0 + proc.stdout.close() + proc.wait() + return not proc.returncode def run_stage(config, stage_name, base_path): @@ -102,10 +109,11 @@ def run_stage(config, stage_name, base_path): :param stage_name: The stage to run :param base_path: The base path of the build """ - for step in get_steps_for_stage(config, stage_name): + steps = get_steps_for_stage(config, stage_name) + for step in steps: result = run_step(step, base_path) if not result: - break + raise StepFailedError('Error running step "{name}"'.format(name=step['name'])) def get_all_stages(config): @@ -161,24 +169,28 @@ def main(): config = yaml.full_load(build_file.open()) all_stages = get_all_stages(config) all_steps = get_all_steps(config) - if args.stage_or_step: - if args.stage_or_step in all_stages: - run_stage(config, args.stage_or_step, base_path) - elif args.stage_or_step in all_steps: - step = setup_step(config, args.stage_or_step) - run_step(config, step, base_path) - else: - print('"{stage}" is not a valid stage or step name'.format(stage=args.stage_or_step)) - return 2 - else: - stages = config.get('stages', all_stages) - if stages: - for stage_name in stages: - run_stage(config, stage_name, base_path) - else: - for step_name in all_steps: - step = setup_step(config, step_name) + try: + if args.stage_or_step: + if args.stage_or_step in all_stages: + run_stage(config, args.stage_or_step, base_path) + elif args.stage_or_step in all_steps: + step = setup_step(config, args.stage_or_step) run_step(config, step, base_path) + else: + print('"{stage}" is not a valid stage or step name'.format(stage=args.stage_or_step)) + return 2 + else: + stages = config.get('stages', all_stages) + if stages: + for stage_name in stages: + run_stage(config, stage_name, base_path) + else: + for step_name in all_steps: + step = setup_step(config, step_name) + run_step(config, step, base_path) + except StepFailedError as e: + print(str(e)) + return 3 return 0 diff --git a/setup.cfg b/setup.cfg index fefd0f8..dcf0d2c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -24,6 +24,7 @@ keywords = build, task [options] py_modules = bou python_requires = >=3.7 +install_requires = PyYAML [options.entry_points] console_scripts =