@@ -73,6 +73,25 @@ def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, s
73
73
return failures
74
74
75
75
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
+
76
95
# Set size_limit to limit the byte size of the report. The default is 1MB as this
77
96
# is the most that can be put into an annotation. If the generated report exceeds
78
97
# this limit and failures are listed, it will be generated again without failures
@@ -83,6 +102,7 @@ def generate_report(
83
102
title ,
84
103
return_code ,
85
104
junit_objects ,
105
+ ninja_logs : list [list [str ]],
86
106
size_limit = 1024 * 1024 ,
87
107
list_failures = True ,
88
108
):
@@ -120,15 +140,34 @@ def generate_report(
120
140
]
121
141
)
122
142
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
+ )
132
171
return "\n " .join (report )
133
172
134
173
tests_passed = tests_run - tests_skipped - tests_failed
@@ -173,14 +212,28 @@ def plural(num_tests):
173
212
elif return_code != 0 :
174
213
# No tests failed but the build was in a failed state. Bring this to the user's
175
214
# 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 ))
184
237
185
238
if failures or return_code != 0 :
186
239
report .extend (["" , UNRELATED_FAILURES_STR ])
@@ -200,7 +253,5 @@ def plural(num_tests):
200
253
201
254
def generate_report_from_files (title , return_code , junit_files ):
202
255
return generate_report (
203
- title ,
204
- return_code ,
205
- [JUnitXml .fromfile (p ) for p in junit_files ],
256
+ title , return_code , [JUnitXml .fromfile (p ) for p in junit_files ], []
206
257
)
0 commit comments