示例#1
0
def ninja_check_all_report(step: Step, _: Report, filter_output: bool):
    print('Full log will be available in Artifacts "ninja-check-all.log"',
          flush=True)
    step.reproduce_commands.append('ninja check-all')
    with open(f'{artifacts_dir}/ninja-check-all.log', 'wb') as f:
        w = sys.stdout.buffer.write
        if filter_output:
            r = re.compile(
                r'^(\[.*] (Building|Linking|Generating)|(PASS|XFAIL|UNSUPPORTED):)'
            )
            w = partial(if_not_matches,
                        write=sys.stdout.buffer.write,
                        regexp=r)
        rc = watch_shell(partial(tee, write1=w, write2=f.write),
                         partial(tee,
                                 write1=sys.stderr.buffer.write,
                                 write2=f.write),
                         'ninja check-all',
                         cwd=build_dir)
        logging.debug(f'ninja check-all: returned {rc}')
        step.set_status_from_exit_code(rc)
    test_results_report.run(build_dir, 'test-results.xml', step, report)
    if not step.success:
        message = 'tests failed'
        f = report.test_stats['fail']
        if f == 1:
            message = '1 test failed'
        if f > 1:
            message = f'{f} tests failed'
        report.add_artifact(artifacts_dir, 'ninja-check-all.log', message)
示例#2
0
def from_shell_output(command) -> []:
    """
    Executes shell command and parses stdout as multidoc yaml file, see
    https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format.
    :param command: command, may include env variables
    :return: all 'steps' that defined in the result ("env" section is ignored).
             Non-zero exit code and malformed YAML produces empty result.
    """
    path = os.path.expandvars(command)
    logging.debug(f'invoking "{path}"')
    out = io.BytesIO()
    err = io.BytesIO()
    rc = watch_shell(out.write, err.write, path)
    logging.debug(
        f'exit code: {rc}, stdout: "{out.getvalue().decode()}", stderr: "{err.getvalue().decode()}"'
    )
    steps = []
    if rc != 0:
        logging.error(
            f'{path} returned non-zero code {rc}, stdout: "{out.getvalue().decode()}", stderr: "{err.getvalue().decode()}"'
        )
        return steps
    try:
        for part in yaml.safe_load_all(out.getvalue()):
            part.setdefault('steps', [])
            steps.extend(part['steps'])
    except yaml.YAMLError as e:
        logging.error(f'''"{path}" produced malformed YAML, exception:
{e}

stdout: >>>{out.getvalue().decode()}>>>''')
    return steps
示例#3
0
def ninja_all_report(step: Step, _: Report, filter_output: bool):
    print('Full log will be available in Artifacts "ninja-all.log"',
          flush=True)
    step.reproduce_commands.append('ninja all')
    with open(f'{artifacts_dir}/ninja-all.log', 'wb') as f:
        w = sys.stdout.buffer.write
        if filter_output:
            r = re.compile(
                r'^\[.*] (Building|Linking|Linting|Copying|Generating|Creating)'
            )
            w = partial(if_not_matches,
                        write=sys.stdout.buffer.write,
                        regexp=r)
        rc = watch_shell(partial(tee, write1=w, write2=f.write),
                         partial(tee,
                                 write1=sys.stderr.buffer.write,
                                 write2=f.write),
                         'ninja all',
                         cwd=build_dir)
        logging.debug(f'ninja all: returned {rc}')
        step.set_status_from_exit_code(rc)
        if not step.success:
            report.add_artifact(artifacts_dir, 'ninja-all.log', 'build failed')