def start_bisecting(project_name, platform_name, git_repo_location, commits_list, needs_clean, repeat_times): left = 0 right = len(commits_list) while left < right: mid = (left + right) // 2 mid_commit = commits_list[mid] bazelci.print_expanded_group(":bazel: Test with Bazel built at " + mid_commit) bazelci.eprint("Remaining suspected commits are:\n") for i in range(left, right): bazelci.eprint(commits_list[i] + "\n") if test_with_bazel_at_commit( project_name, platform_name, git_repo_location, mid_commit, needs_clean, repeat_times ): bazelci.print_collapsed_group(":bazel: Succeeded at " + mid_commit) left = mid + 1 else: bazelci.print_collapsed_group(":bazel: Failed at " + mid_commit) right = mid bazelci.print_expanded_group(":bazel: Bisect Result") if right == len(commits_list): bazelci.eprint("first bad commit not found, every commit succeeded.") else: first_bad_commit = commits_list[right] bazelci.eprint("first bad commit is " + first_bad_commit) os.chdir(BAZEL_REPO_DIR) bazelci.execute_command(["git", "--no-pager", "log", "-n", "1", first_bad_commit])
def main(argv=None): org = os.getenv("BUILDKITE_ORGANIZATION_SLUG") repo = os.getenv("BUILDKITE_REPO") settings = DOCGEN_SETTINGS.get(org, {}).get(repo) if not settings: bazelci.eprint("docgen is not enabled for '%s' org and repository %s", org, repo) return 1 bazelci.print_expanded_group( ":bazel: Building documentation from {}".format(repo)) try: bazelci.execute_command(["bazel", "build"] + DEFAULT_FLAGS + settings.build_flags + [settings.target]) except subprocess.CalledProcessError as e: bazelci.eprint("Bazel failed with exit code {}".format(e.returncode)) return e.returncode src_root = os.path.join(os.getcwd(), settings.output_dir) if settings.rewrite: bazelci.print_expanded_group( ":bazel: Rewriting links in documentation files") dest_root = os.path.join(tempfile.mkdtemp(), "site") rewrite_and_copy(src_root, dest_root, settings.rewrite) src_root = dest_root bucket = "gs://{}".format(settings.gcs_bucket) dest = get_destination(bucket, settings.gcs_subdir) bazelci.print_expanded_group( ":bazel: Uploading documentation to {}".format(dest)) try: bazelci.execute_command( ["gsutil", "-m", "rsync", "-r", "-c", "-d", src_root, dest]) bazelci.execute_command([ "gsutil", "web", "set", "-m", "index.html", "-e", "404.html", bucket ]) # TODO: does not work with 404 pages in sub directories except subprocess.CalledProcessError as e: bazelci.eprint("Upload to GCS failed with exit code {}".format( e.returncode)) return e.returncode bazelci.print_collapsed_group(":bazel: Publishing documentation URL") message = "You can find the documentation at {}".format(get_url(settings)) bazelci.execute_command([ "buildkite-agent", "annotate", "--style=info", message, "--context", "doc_url" ]) bazelci.execute_command( ["buildkite-agent", "meta-data", "set", "message", message]) return 0
def print_info(context, style, info): # CHUNK_SIZE is to prevent buildkite-agent "argument list too long" error CHUNK_SIZE = 20 for i in range(0, len(info), CHUNK_SIZE): info_str = "\n".join(info[i:i + CHUNK_SIZE]) bazelci.execute_command([ "buildkite-agent", "annotate", "--append", f"--context={context}", f"--style={style}", f"\n{info_str}\n", ])
def print_info(context, style, info, append=True): info_str = "\n".join(info) bazelci.execute_command( args=[ "buildkite-agent", "annotate", ] + (["--append"] if append else []) + [ f"--context={context}", f"--style={style}", f"\n{info_str}\n", ], print_output=False, )
def print_projects_need_to_migrate(failed_jobs_per_flag): info_text = ["#### The following projects need migration"] jobs_need_migration = {} for jobs in failed_jobs_per_flag.values(): for job in jobs.values(): jobs_need_migration[job["name"]] = job job_list = jobs_need_migration.values() job_num = len(job_list) if job_num == 0: return projects = set() for job in job_list: project, _ = get_pipeline_and_platform(job) projects.add(project) project_num = len(projects) s1 = "" if project_num == 1 else "s" s2 = "s" if project_num == 1 else "" info_text.append( f"<details><summary>{project_num} project{s1} need{s2} migration, click to see details</summary><ul>" ) entries = merge_and_format_jobs(job_list, " <li><strong>{}</strong>: {}</li>") info_text += entries info_text.append("</ul></details>") info_str = "\n".join(info_text) bazelci.execute_command( [ "buildkite-agent", "annotate", "--append", f"--context=projects_need_migration", f"--style=error", f"\n{info_str}\n", ] )