@@ -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 ])
0 commit comments