Skip to content

Commit 5f96dc6

Browse files
[𝘀𝗽𝗿] initial version
Created using spr 1.3.7
2 parents fe00ab4 + 62255cb commit 5f96dc6

File tree

3 files changed

+79
-15
lines changed

3 files changed

+79
-15
lines changed

.ci/generate_test_report_lib.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
9898
)
9999
return output
100100

101+
def get_failures(junit_objects) -> dict[str, list[tuple[str, str]]]:
102+
failures = {}
103+
for results in junit_objects:
104+
for testsuite in results:
105+
for test in testsuite:
106+
if (
107+
not test.is_passed
108+
and test.result
109+
and isinstance(test.result[0], Failure)
110+
):
111+
if failures.get(testsuite.name) is None:
112+
failures[testsuite.name] = []
113+
failures[testsuite.name].append(
114+
(test.classname + "/" + test.name, test.result[0].text)
115+
)
116+
return failures
117+
101118

102119
# Set size_limit to limit the byte size of the report. The default is 1MB as this
103120
# is the most that can be put into an annotation. If the generated report exceeds
@@ -113,7 +130,7 @@ def generate_report(
113130
size_limit=1024 * 1024,
114131
list_failures=True,
115132
):
116-
failures = {}
133+
failures = get_failures(junit_objects)
117134
tests_run = 0
118135
tests_skipped = 0
119136
tests_failed = 0
@@ -124,18 +141,6 @@ def generate_report(
124141
tests_skipped += testsuite.skipped
125142
tests_failed += testsuite.failures
126143

127-
for test in testsuite:
128-
if (
129-
not test.is_passed
130-
and test.result
131-
and isinstance(test.result[0], Failure)
132-
):
133-
if failures.get(testsuite.name) is None:
134-
failures[testsuite.name] = []
135-
failures[testsuite.name].append(
136-
(test.classname + "/" + test.name, test.result[0].text)
137-
)
138-
139144
report = [f"# {title}", ""]
140145

141146
if tests_run == 0:
@@ -258,7 +263,7 @@ def plural(num_tests):
258263
return report
259264

260265

261-
def generate_report_from_files(title, return_code, build_log_files):
266+
def load_info_from_files(build_log_files):
262267
junit_files = [
263268
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
264269
]
@@ -271,6 +276,11 @@ def generate_report_from_files(title, return_code, build_log_files):
271276
ninja_logs.append(
272277
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
273278
)
279+
return [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
280+
281+
282+
def generate_report_from_files(title, return_code, build_log_files):
283+
junit_objects, ninja_logs = load_info_from_files(build_log_files)
274284
return generate_report(
275-
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
285+
title, return_code, junit_objects, ninja_logs
276286
)

.ci/premerge_advisor_upload.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
9+
import requests
10+
11+
import generate_test_report_lib
12+
13+
PREMERGE_ADVISOR_URL = "http://premerge-advisor:5000/upload"
14+
15+
16+
def main(commit_sha, workflow_run_number, build_log_files):
17+
junit_objects, ninja_logs = generate_test_report_lib.load_info_from_files(
18+
build_log_files
19+
)
20+
test_failures = generate_test_report_lib.get_failures(junit_objects)
21+
source = "pull_request" if "GITHUB_ACTIONS" in os.environ else "postcommit"
22+
failure_info = {
23+
"source_type": source,
24+
"base_commit_sha": commit_sha,
25+
"source_id": workflow_run_number,
26+
"failures": [],
27+
}
28+
if test_failures:
29+
for name, failure_message in test_failures:
30+
failure_info["failures"].append({"name": name, "message": failure_message})
31+
else:
32+
ninja_failures = generate_test_report_lib.find_failure_in_ninja_logs(ninja_logs)
33+
for name, failure_message in ninja_failures:
34+
failure_info["failures"].append({"name": name, "message": failure_message})
35+
requests.post(PREMERGE_ADVISOR_URL, json=failure_info)
36+
37+
38+
if __name__ == "__main__":
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument("commit_sha", help="The base commit SHA for the test.")
41+
parser.add_argument("workflow_run_number", help="The run number from GHA.")
42+
parser.add_argument(
43+
"build_log_files", help="Paths to JUnit report files and ninja logs.", nargs="*"
44+
)
45+
args = parser.parse_args()
46+
47+
main(args.commit_sha, args.workflow_run_number, args.build_log_files)
48+
main()

.ci/utils.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function at-exit {
3838
$retcode "${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log \
3939
>> $GITHUB_STEP_SUMMARY
4040
fi
41+
42+
if [[ "$retcode" != "0" ]]; then
43+
python "${MONOREPO_ROOT}"/.ci/premerge_advisor_upload.py \
44+
$(git rev-parse HEAD~1) $GITHUB_RUN_NUMBER \
45+
"${BUILD_DIR}"/test-results.*.xml "${MONOREPO_ROOT}"/ninja*.log
46+
fi
4147
}
4248
trap at-exit EXIT
4349

0 commit comments

Comments
 (0)