Debian Codegraph @

.ci/premerge_advisor_upload.py

raw
1 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4 """Script for uploading results to the premerge advisor."""
5
6 import argparse
7 import os
8 import platform
9 import sys
10
11 import requests
12
13 import generate_test_report_lib
14
15 # These are IP addresses of the two premerge advisor instances. They should
16 # eventually be updated to domain names.
17 PREMERGE_ADVISOR_URLS = [
18 "http://34.82.126.63:5000/upload",
19 "http://136.114.125.23:5000/upload",
20 ]
21
22
23 def main(commit_sha, workflow_run_number, build_log_files):
24 junit_objects, ninja_logs = generate_test_report_lib.load_info_from_files(
25 build_log_files
26 )
27 test_failures = generate_test_report_lib.get_failures(junit_objects)
28 source = "pull_request" if "GITHUB_ACTIONS" in os.environ else "postcommit"
29 current_platform = f"{platform.system()}-{platform.machine()}".lower()
30 failure_info = {
31 "source_type": source,
32 "base_commit_sha": commit_sha,
33 "source_id": workflow_run_number,
34 "failures": [],
35 "platform": current_platform,
36 }
37 if test_failures:
38 for _, failures in test_failures.items():
39 for name, failure_message in failures:
40 failure_info["failures"].append(
41 {"name": name, "message": failure_message}
42 )
43 else:
44 ninja_failures = generate_test_report_lib.find_failure_in_ninja_logs(ninja_logs)
45 for name, failure_message in ninja_failures:
46 failure_info["failures"].append({"name": name, "message": failure_message})
47 for premerge_advisor_url in PREMERGE_ADVISOR_URLS:
48 requests.post(premerge_advisor_url, json=failure_info, timeout=5)
49
50
51 if __name__ == "__main__":
52 parser = argparse.ArgumentParser()
53 parser.add_argument("commit_sha", help="The base commit SHA for the test.")
54 parser.add_argument("workflow_run_number", help="The run number from GHA.")
55 parser.add_argument(
56 "build_log_files", help="Paths to JUnit report files and ninja logs.", nargs="*"
57 )
58 args = parser.parse_args()
59
60 # Skip uploading results on AArch64 for now because the premerge advisor
61 # service is not available on AWS currently.
62 if platform.machine() == "arm64" or platform.machine() == "aarch64":
63 sys.exit(0)
64
65 main(args.commit_sha, args.workflow_run_number, args.build_log_files)