def maybe_add_url_artifact(phab: PhabTalk, url: str, name: str): phid = os.getenv('ph_target_phid') if phid is None: return phab.create_artifact(phid, str(uuid.uuid4()), 'uri', { 'uri': url, 'ui.external': True, 'name': name })
def maybe_add_url_artifact(phab: PhabTalk, phid: str, url: str, name: str): if phid is None: logging.warning('PHID is not provided, cannot create URL artifact') return phab.create_artifact(phid, str(uuid.uuid4()), 'uri', { 'uri': url, 'ui.external': True, 'name': name })
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)
0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # from phabtalk import PhabTalk # else: from phabtalk.phabtalk import PhabTalk def maybe_add_url_artifact(phab: PhabTalk, phid: str, url: str, name: str): if phid is None: logging.warning('PHID is not provided, cannot create URL artifact') return phab.create_artifact(phid, str(uuid.uuid4()), 'uri', { 'uri': url, 'ui.external': True, 'name': name }) if __name__ == '__main__': parser = argparse.ArgumentParser(description='Runs premerge checks8') parser.add_argument('--url', type=str) parser.add_argument('--name', type=str) parser.add_argument('--phid', type=str) parser.add_argument('--log-level', type=str, default='WARNING') 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) maybe_add_url_artifact(phabtalk, args.phid, args.url, args.name)
shutil.copy2(file, artifacts_dir) return add_shell_result(report, 'cmake', cmake_result) def furl(url: str, name: Optional[str] = None): if name is None: name = url return f"\033]1339;url='{url}';content='{name}'\a\n" if __name__ == '__main__': build_dir = '' logging.basicConfig(level=logging.WARNING, format='%(levelname)-7s %(message)s') scripts_dir = pathlib.Path(__file__).parent.absolute() phab = PhabTalk(os.getenv('CONDUIT_TOKEN'), 'https://reviews.llvm.org/api/', False) maybe_add_url_artifact(phab, os.getenv('BUILDKITE_BUILD_URL'), 'Buildkite build') artifacts_dir = os.path.join(os.getcwd(), 'artifacts') os.makedirs(artifacts_dir, exist_ok=True) report = Report() timings = {} cmake_result = run_step('cmake', report, cmake_report) if cmake_result == CheckResult.SUCCESS: compile_result = run_step('ninja all', report, ninja_all_report) if compile_result == CheckResult.SUCCESS: run_step('ninja check all', report, ninja_check_all_report) run_step( 'clang-tidy', report, lambda x: clang_tidy_report.run( 'HEAD~1', os.path.join(scripts_dir, 'clang-tidy.ignore'), x)) run_step(
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)
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--log-level', type=str, default='INFO') args = parser.parse_args() logging.basicConfig(level=args.log_level, format='%(levelname)-7s %(message)s') ph_buildable_diff = os.getenv('ph_buildable_diff') 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) phabtalk = PhabTalk(os.getenv('CONDUIT_TOKEN'), dry_run_updates=(os.getenv('ph_dry_run_report') is not None)) report_success = False # for try block failed_tests = [] try: 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 failed_tests = process_unit_test_reports(bk, build, '') for i, job in enumerate(build.get('jobs', [])): job = benedict(job) job_web_url = job.get('web_url', os.getenv('BUILDKITE_BUILD_URL', '')) logging.info(f'{job.get("id")} state {job.get("state")}')
print(f'{mark} {s.name}{msg}', flush=True) print('--- Reproduce build locally', flush=True) print(f'git clone {os.getenv("BUILDKITE_REPO")} llvm-project') print('cd llvm-project') print(f'git checkout {os.getenv("BUILDKITE_COMMIT")}') 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') if ph_target_phid is not None: phabtalk = PhabTalk(os.getenv('CONDUIT_TOKEN')) for u in report.unit: u['engine'] = step_key phabtalk.update_build_status(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: phabtalk.maybe_add_url_artifact(ph_target_phid, url, f'{a["name"]} ({step_key})') else: logging.warning( 'ph_target_phid is not specified. Will not update the build status in Phabricator' ) with open(report_path, 'w') as f: json.dump(report.__dict__, f, default=as_dict)
# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import logging import os from phabtalk.phabtalk import PhabTalk if __name__ == '__main__': parser = argparse.ArgumentParser(description='Runs premerge checks8') parser.add_argument('--url', type=str) parser.add_argument('--name', type=str) parser.add_argument('--phid', type=str) parser.add_argument('--log-level', type=str, default='WARNING') args = parser.parse_args() logging.basicConfig(level=args.log_level, format='%(levelname)-7s %(message)s') PhabTalk(os.getenv('CONDUIT_TOKEN')).maybe_add_url_artifact( args.phid, args.url, args.name)
# See the License for the specific language governing permissions and # limitations under the License. import argparse import logging import os 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'), dry_run_updates=(os.getenv('ph_dry_run_report') is not None)) 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) 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') phabtalk.update_build_status(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)
] if __name__ == '__main__': scripts_refspec = os.getenv("ph_scripts_refspec", "master") diff_id = os.getenv("ph_buildable_diff", "") no_cache = os.getenv('ph_no_cache') is not None filter_output = '--filter-output' if os.getenv( 'ph_no_filter_output') is None else '' projects = os.getenv('ph_projects', 'detect') log_level = os.getenv('ph_log_level', 'INFO') logging.basicConfig(level=log_level, format='%(levelname)-7s %(message)s') phid = os.getenv('ph_target_phid') # Add link in review to the build. if phid is not None: PhabTalk(os.getenv('CONDUIT_TOKEN')).maybe_add_url_artifact( phid, os.getenv('BUILDKITE_BUILD_URL'), 'buildkite') # List all affected projects. repo = git.Repo('.') patch = repo.git.diff("HEAD~1") cp = ChooseProjects('.') modified_files = cp.get_changed_files(patch) modified_projects, unmapped_changes = cp.get_changed_projects( modified_files) if unmapped_changes: logging.warning( 'There were changes that could not be mapped to a project. Checking everything' ) modified_projects = cp.all_projects logging.info(f'modified projects: {modified_projects}') # Add projects that depend on modified.
# You may obtain a copy of the License at # # https://llvm.org/LICENSE.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import logging import os from phabtalk.phabtalk import PhabTalk if __name__ == '__main__': parser = argparse.ArgumentParser(description='Runs premerge checks8') parser.add_argument('--url', type=str) parser.add_argument('--name', type=str) parser.add_argument('--phid', type=str) parser.add_argument('--log-level', type=str, default='WARNING') args = parser.parse_args() logging.basicConfig(level=args.log_level, format='%(levelname)-7s %(message)s') dry = os.getenv('ph_dry_run_report') is not None PhabTalk(os.getenv('CONDUIT_TOKEN'), dry_run_updates=dry).maybe_add_url_artifact( args.phid, args.url, args.name)