Skip to content

Commit f9270f6

Browse files
authored
Merge branch 'main' into bzl-mlir-ubops
2 parents 35acc85 + f4cf610 commit f9270f6

File tree

116 files changed

+2547
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2547
-573
lines changed

.ci/generate_test_report_github.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
if __name__ == "__main__":
1717
parser = argparse.ArgumentParser()
1818
parser.add_argument("return_code", help="The build's return code.", type=int)
19-
parser.add_argument("junit_files", help="Paths to JUnit report files.", nargs="*")
19+
parser.add_argument(
20+
"build_test_logs", help="Paths to JUnit report files and ninja logs.", nargs="*"
21+
)
2022
args = parser.parse_args()
2123

2224
report = generate_test_report_lib.generate_report_from_files(
23-
PLATFORM_TITLES[platform.system()], args.return_code, args.junit_files
25+
PLATFORM_TITLES[platform.system()], args.return_code, args.build_test_logs
2426
)
2527

2628
print(report)

.ci/generate_test_report_lib.py

Lines changed: 84 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@ def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, s
7373
return failures
7474

7575

76+
def _format_ninja_failures(ninja_failures: list[tuple[str, str]]) -> list[str]:
77+
"""Formats ninja failures into summary views for the report."""
78+
output = []
79+
for build_failure in ninja_failures:
80+
failed_action, failure_message = build_failure
81+
output.extend(
82+
[
83+
"<details>",
84+
f"<summary>{failed_action}</summary>",
85+
"",
86+
"```",
87+
failure_message,
88+
"```",
89+
"</details>",
90+
]
91+
)
92+
return output
93+
94+
7695
# Set size_limit to limit the byte size of the report. The default is 1MB as this
7796
# is the most that can be put into an annotation. If the generated report exceeds
7897
# this limit and failures are listed, it will be generated again without failures
@@ -83,6 +102,7 @@ def generate_report(
83102
title,
84103
return_code,
85104
junit_objects,
105+
ninja_logs: list[list[str]],
86106
size_limit=1024 * 1024,
87107
list_failures=True,
88108
):
@@ -120,15 +140,34 @@ def generate_report(
120140
]
121141
)
122142
else:
123-
report.extend(
124-
[
125-
"The build failed before running any tests.",
126-
"",
127-
SEE_BUILD_FILE_STR,
128-
"",
129-
UNRELATED_FAILURES_STR,
130-
]
131-
)
143+
ninja_failures = find_failure_in_ninja_logs(ninja_logs)
144+
if not ninja_failures:
145+
report.extend(
146+
[
147+
"The build failed before running any tests. Detailed "
148+
"information about the build failure could not be "
149+
"automatically obtained.",
150+
"",
151+
SEE_BUILD_FILE_STR,
152+
"",
153+
UNRELATED_FAILURES_STR,
154+
]
155+
)
156+
else:
157+
report.extend(
158+
[
159+
"The build failed before running any tests. Click on a "
160+
"failure below to see the details.",
161+
"",
162+
]
163+
)
164+
report.extend(_format_ninja_failures(ninja_failures))
165+
report.extend(
166+
[
167+
"",
168+
UNRELATED_FAILURES_STR,
169+
]
170+
)
132171
return "\n".join(report)
133172

134173
tests_passed = tests_run - tests_skipped - tests_failed
@@ -173,14 +212,28 @@ def plural(num_tests):
173212
elif return_code != 0:
174213
# No tests failed but the build was in a failed state. Bring this to the user's
175214
# attention.
176-
report.extend(
177-
[
178-
"",
179-
"All tests passed but another part of the build **failed**.",
180-
"",
181-
SEE_BUILD_FILE_STR,
182-
]
183-
)
215+
ninja_failures = find_failure_in_ninja_logs(ninja_logs)
216+
if not ninja_failures:
217+
report.extend(
218+
[
219+
"",
220+
"All tests passed but another part of the build **failed**. "
221+
"Information about the build failure could not be automatically "
222+
"obtained.",
223+
"",
224+
SEE_BUILD_FILE_STR,
225+
]
226+
)
227+
else:
228+
report.extend(
229+
[
230+
"",
231+
"All tests passed but another part of the build **failed**. Click on "
232+
"a failure below to see the details.",
233+
"",
234+
]
235+
)
236+
report.extend(_format_ninja_failures(ninja_failures))
184237

185238
if failures or return_code != 0:
186239
report.extend(["", UNRELATED_FAILURES_STR])
@@ -198,9 +251,19 @@ def plural(num_tests):
198251
return report
199252

200253

201-
def generate_report_from_files(title, return_code, junit_files):
254+
def generate_report_from_files(title, return_code, build_log_files):
255+
junit_files = [
256+
junit_file for junit_file in build_log_files if junit_file.endswith(".xml")
257+
]
258+
ninja_log_files = [
259+
ninja_log for ninja_log in build_log_files if ninja_log.endswith(".log")
260+
]
261+
ninja_logs = []
262+
for ninja_log_file in ninja_log_files:
263+
with open(ninja_log_file, "r") as ninja_log_file_handle:
264+
ninja_logs.append(
265+
[log_line.strip() for log_line in ninja_log_file_handle.readlines()]
266+
)
202267
return generate_report(
203-
title,
204-
return_code,
205-
[JUnitXml.fromfile(p) for p in junit_files],
268+
title, return_code, [JUnitXml.fromfile(p) for p in junit_files], ninja_logs
206269
)

0 commit comments

Comments
 (0)