import sys
import uuid

if __name__ == '__main__':
    sys.path.insert(
        0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from phabtalk.phabtalk import PhabTalk
from buildkite.utils import format_url

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('--log-level', type=str, default='WARNING')
    parser.add_argument('--success', action='store_true')
    args = parser.parse_args()
    logging.basicConfig(level=args.log_level,
                        format='%(levelname)-7s %(message)s')
    phabtalk = PhabTalk(os.getenv('CONDUIT_TOKEN'),
                        'https://reviews.llvm.org/api/', False)
    build_url = f'https://reviews.llvm.org/harbormaster/build/{os.getenv("ph_build_id")}'
    print(f'Reporting results to Phabricator build {format_url(build_url)}',
          flush=True)
    ph_buildable_diff = os.getenv('ph_buildable_diff')
    ph_target_phid = os.getenv('ph_target_phid')
    phabtalk.update_build_status(ph_buildable_diff, ph_target_phid, False,
                                 args.success)
    bug_url = f'https://github.com/google/llvm-premerge-checks/issues/new?assignees=&labels=bug' \
              f'&template=bug_report.md&title=buildkite build {os.getenv("BUILDKITE_PIPELINE_SLUG")} ' \
              f'{os.getenv("BUILDKITE_BUILD_NUMBER")}'
    print(f'{format_url(bug_url, "report issue")}', flush=True)
Beispiel #2
0
    for s in report.steps:
        mark = 'V'
        if s['result'] == CheckResult.UNKNOWN:
            mark = '?'
        if s['result'] == CheckResult.FAILURE:
            success = False
            mark = 'X'
        msg = s['message']
        if len(msg):
            msg = ': ' + msg
        print(f'{mark} {s["title"]}{msg}')

    # TODO: dump the report and deduplicate tests and other reports later (for multiple OS) in a separate step.
    ph_target_phid = os.getenv('ph_target_phid')
    if ph_target_phid is not None:
        build_url = f'https://reviews.llvm.org/harbormaster/build/{os.getenv("ph_build_id")}'
        print(f'Reporting results to Phabricator build {furl(build_url)}')
        phab.update_build_status(ph_buildable_diff, ph_target_phid, False,
                                 success, report.lint, report.unit)
        for a in report.artifacts:
            url = upload_file(a['dir'], a['file'])
            if url is not None:
                maybe_add_url_artifact(phab, url, a['name'])
    else:
        logging.warning(
            'No phabricator phid is specified. Will not update the build status in Phabricator'
        )
    # TODO: add link to report issue on github
    with open(os.path.join(artifacts_dir, 'step-timings.json'), 'w') as f:
        f.write(json.dumps(timings))
                # Current and irrelevant steps.
                continue
            if job_state == 'passed' and i == 0:
                # Skip successful first step as we assume it to be a pipeline setup
                continue
            name = job.get('name')
            if job.get('type') == 'trigger':
                job_web_url = job.get('triggered_build.web_url', job_web_url)
                triggered_url = job.get('triggered_build.url')
                if triggered_url != '':
                    sub_build = benedict(bk.get(triggered_url).json())
                    name = name or sub_build.get('pipeline.name')
                    failed_steps = get_failed_jobs(sub_build)
                    failed_tests.extend(
                        process_unit_test_reports(bk, sub_build, name))
                    if job_state == 'failed' and failed_steps:
                        name = f"{name} ({', '.join(failed_steps[:2])}{', ...' if len(failed_steps) > 2 else ''})"
            name = strip_emojis(name) or 'unknown'
            phabtalk.maybe_add_url_artifact(ph_target_phid, job_web_url,
                                            f"{name} {job_state}")
            if job_state == 'failed':
                success = False
        report_success = success  # Must be last before finally: block to report errors in this script.
    finally:
        build_url = f'https://reviews.llvm.org/harbormaster/build/{os.getenv("ph_build_id")}'
        print(
            f'Reporting results to Phabricator build {format_url(build_url)}',
            flush=True)
        phabtalk.update_build_status(ph_target_phid, False, report_success, {},
                                     failed_tests)
Beispiel #4
0
    for s in report.steps:
        if len(s.reproduce_commands) == 0:
            continue
        print('\n'.join(s.reproduce_commands), flush=True)
    print('', flush=True)
    if not report.success:
        print('^^^ +++', flush=True)

    ph_target_phid = os.getenv('ph_target_phid')
    ph_buildable_diff = os.getenv('ph_buildable_diff')
    if ph_target_phid is not None:
        phabtalk = PhabTalk(os.getenv('CONDUIT_TOKEN'),
                            'https://reviews.llvm.org/api/', False)
        for u in report.unit:
            u['engine'] = step_key
        phabtalk.update_build_status(ph_buildable_diff, ph_target_phid, True,
                                     report.success, report.lint, report.unit)
        for a in report.artifacts:
            url = upload_file(a['dir'], a['file'])
            if url is not None:
                maybe_add_url_artifact(phabtalk, ph_target_phid, url,
                                       f'{a["name"]} ({step_key})')
    else:
        logging.warning(
            'No phabricator phid is specified. Will not update the build status in Phabricator'
        )
    with open(report_path, 'w') as f:
        json.dump(report.__dict__, f, default=as_dict)

    if not report.success:
        print('Build completed with failures', flush=True)
        exit(1)
Beispiel #5
0
              f'builds/{os.getenv("BUILDKITE_TRIGGERED_FROM_BUILD_NUMBER")}'
        print(f'Triggered from build {format_url(url)}', flush=True)
    ph_target_phid = os.getenv('ph_target_phid')
    if ph_target_phid is None:
        logging.warning(
            'ph_target_phid is not specified. Will not update the build status in Phabricator'
        )
        exit(0)

    bk = BuildkiteApi(os.getenv("BUILDKITE_API_TOKEN"),
                      os.getenv("BUILDKITE_ORGANIZATION_SLUG"))
    build = bk.get_build(os.getenv("BUILDKITE_PIPELINE_SLUG"),
                         os.getenv("BUILDKITE_BUILD_NUMBER"))
    success = True
    build.setdefault('jobs', [])
    for j in build['jobs']:
        j.setdefault('state', '')
        j.setdefault('id', '')
        logging.info(f'{j["id"]} state {j["state"]}')
        success = success and (j['state'] != 'failed')

    phabtalk = PhabTalk(os.getenv('CONDUIT_TOKEN'))
    build_url = f'https://reviews.llvm.org/harbormaster/build/{os.getenv("ph_build_id")}'
    print(f'Reporting results to Phabricator build {format_url(build_url)}',
          flush=True)
    phabtalk.update_build_status(ph_target_phid, False, success, {}, [])
    bug_url = f'https://github.com/google/llvm-premerge-checks/issues/new?assignees=&labels=bug' \
              f'&template=bug_report.md&title=buildkite build {os.getenv("BUILDKITE_PIPELINE_SLUG")} ' \
              f'{os.getenv("BUILDKITE_BUILD_NUMBER")}'
    print(f'{format_url(bug_url, "report issue")}', flush=True)