Skip to content

Commit cb21d09

Browse files
authored
CI test stats: collapse test results if more than 5 (#3143)
## Changes - Wrap tests table in `<details>` so that it is collapsed. - Fix log message in gh_report.py to go to stderr as intended. ## Tests Manually: `/tools/gh_report.py --markdown --commit b56f245 | pbcopy` Result: #3139 (comment)
1 parent 9a9e651 commit cb21d09

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

tools/gh_parse.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def print_report(filenames, filter, filter_env, show_output, markdown=False):
172172
**stats,
173173
}
174174
)
175-
print_table(table, markdown=markdown)
175+
print(format_table(table, markdown=markdown))
176176

177177
interesting_envs = set()
178178
for env, stats in per_env_stats.items():
@@ -212,7 +212,11 @@ def print_report(filenames, filter, filter_env, show_output, markdown=False):
212212
**items,
213213
}
214214
)
215-
print_table(table, markdown=markdown)
215+
table_txt = format_table(table, markdown=markdown)
216+
if len(table) > 5:
217+
table_txt = wrap_in_details(table_txt, f"{len(table)} failing tests:")
218+
if table_txt:
219+
print(table_txt)
216220

217221
if show_output:
218222
for testname, stats in simplified_results.items():
@@ -228,7 +232,7 @@ def print_report(filenames, filter, filter_env, show_output, markdown=False):
228232
print()
229233

230234

231-
def print_table(table, columns=None, markdown=False):
235+
def format_table(table, columns=None, markdown=False):
232236
"""
233237
Pretty-print a list-of-dicts as an aligned text table.
234238
@@ -238,7 +242,7 @@ def print_table(table, columns=None, markdown=False):
238242
markdown (bool): whether to output in markdown format
239243
"""
240244
if not table:
241-
return
245+
return []
242246

243247
if columns is None:
244248
columns = []
@@ -256,21 +260,30 @@ def print_table(table, columns=None, markdown=False):
256260
for i, col in enumerate(columns):
257261
widths[i] = max(widths[i], len(str(row.get(col, ""))))
258262

263+
result = []
264+
write = result.append
265+
259266
if markdown:
260267
# Header
261-
print("| " + " | ".join(str(col).ljust(w) for col, w in zip(columns, widths)) + " |")
268+
write("| " + " | ".join(str(col).ljust(w) for col, w in zip(columns, widths)) + " |")
262269
# Separator
263-
print("| " + " | ".join("-" * w for w in widths) + " |")
270+
write("| " + " | ".join("-" * w for w in widths) + " |")
264271
# Data rows
265272
for row in table:
266-
print("| " + " | ".join(str(row.get(col, "")).ljust(w) for col, w in zip(columns, widths)) + " |")
273+
write("| " + " | ".join(str(row.get(col, "")).ljust(w) for col, w in zip(columns, widths)) + " |")
267274
else:
268275
fmt = lambda cells: " ".join(str(cell).ljust(w) for cell, w in zip(cells, widths))
269-
print(fmt(columns))
276+
write(fmt(columns))
270277
for ind, row in enumerate(table):
271-
print(fmt([row.get(col, "") for col in columns]))
278+
write(fmt([row.get(col, "") for col in columns]))
279+
280+
write("")
281+
282+
return "\n".join(result)
283+
272284

273-
print()
285+
def wrap_in_details(txt, summary):
286+
return f"<details><summary>{summary}</summary>\n\n{txt}\n\n</details>"
274287

275288

276289
def main():

tools/gh_report.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ def download_run_id(run_id, repo, rm):
117117
if rm:
118118
run(["rm", "-fr", target_dir])
119119
else:
120-
print(f"Already exists: {target_dir}. If that directory contains partial results, delete it to re-download: rm -fr .gh-logs/{run_id}")
120+
print(
121+
f"Already exists: {target_dir}. If that directory contains partial results, delete it to re-download: rm -fr .gh-logs/{run_id}",
122+
file=sys.stderr,
123+
)
121124
return target_dir
122125
cmd = ["gh", "run", "-R", repo, "download", str(run_id), "-D", target_dir]
123126
run(cmd)

0 commit comments

Comments
 (0)