-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BCR bazel compatibility test: Add generate_report.py (#2091)
This will be run in the last step for a https://buildkite.com/bazel/bcr-bazel-compatibility-test build without `USE_BAZELISK_MIGRATE` and generate a report in markdown that can be used for filing a GitHub issue report for broken modules. e.g.: <img width="685" alt="image" src="https://github.com/user-attachments/assets/3e888dd0-601c-4b38-bce0-047eb80be9bb">
- Loading branch information
1 parent
9b86972
commit 1375273
Showing
2 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env python3 | ||
# | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# 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. | ||
# pylint: disable=line-too-long | ||
# pylint: disable=missing-function-docstring | ||
# pylint: disable=unspecified-encoding | ||
# pylint: disable=invalid-name | ||
"""The CI script for generate report for BCR Bazel Compatibility Test pipeline.""" | ||
|
||
|
||
import argparse | ||
import collections | ||
import os | ||
import json | ||
import re | ||
import sys | ||
|
||
import bazelci | ||
import bcr_presubmit | ||
|
||
BUILDKITE_ORG = os.environ["BUILDKITE_ORGANIZATION_SLUG"] | ||
|
||
PIPELINE = os.environ["BUILDKITE_PIPELINE_SLUG"] | ||
|
||
MODULE_VERSION_PATTERN = re.compile(r'(?P<module_version>[a-z](?:[a-z0-9._-]*[a-z0-9])?@[^\s]+)') | ||
|
||
def extract_module_version(line): | ||
match = MODULE_VERSION_PATTERN.search(line) | ||
if match: | ||
return match.group("module_version") | ||
|
||
|
||
def get_github_maintainer(module_name): | ||
metadata = json.load(open(bcr_presubmit.get_metadata_json(module_name), "r")) | ||
github_maintainers = [] | ||
for maintainer in metadata["maintainers"]: | ||
if "github" in maintainer: | ||
github_maintainers.append(maintainer["github"]) | ||
|
||
if not github_maintainers: | ||
github_maintainers.append("bazelbuild/bcr-maintainers") | ||
return github_maintainers | ||
|
||
|
||
def print_report_in_markdown(failed_jobs_per_module, pipeline_url): | ||
bazel_version = os.environ.get("USE_BAZEL_VERSION") | ||
print("\n") | ||
print("## The following modules are broken%s:" % (f" with Bazel@{bazel_version}" if bazel_version else "")) | ||
print("BCR Bazel Compatibility Test: ", pipeline_url) | ||
for module, jobs in failed_jobs_per_module.items(): | ||
module_name = module.strip().split("@")[0] | ||
github_maintainers = get_github_maintainer(module_name) | ||
print(f"### {module}") | ||
print("Maintainers: ", ", ".join(f"@{maintainer}" for maintainer in github_maintainers)) | ||
for job in jobs: | ||
print(f"- [{job['name']}]({job['web_url']})") | ||
print("\n") | ||
|
||
|
||
def main(argv=None): | ||
if argv is None: | ||
argv = sys.argv[1:] | ||
|
||
parser = argparse.ArgumentParser(description="Script to report BCR Bazel Compatibility Test result.") | ||
parser.add_argument("--build_number", type=str) | ||
|
||
args = parser.parse_args(argv) | ||
if not args.build_number: | ||
parser.print_help() | ||
return 2 | ||
|
||
client = bazelci.BuildkiteClient(org=BUILDKITE_ORG, pipeline=PIPELINE) | ||
build_info = client.get_build_info(args.build_number) | ||
failed_jobs_per_module = collections.defaultdict(list) | ||
for job in build_info["jobs"]: | ||
if job.get("state") == "failed" and "name" in job: | ||
module = extract_module_version(job["name"]) | ||
if not module: | ||
continue | ||
failed_jobs_per_module[module].append(job) | ||
|
||
print_report_in_markdown(failed_jobs_per_module, build_info["web_url"]) | ||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |