Skip to content

Commit a6a4177

Browse files
committed
Improved build failure reporting and relevant log chunks extraction.
1 parent 2fdba48 commit a6a4177

File tree

1 file changed

+54
-24
lines changed

1 file changed

+54
-24
lines changed

zorg/buildbot/reporters/utils.py

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from buildbot.process.results import WARNINGS
1919
from buildbot.process.results import statusToString
2020

21+
from zorg.buildbot.commands.LitTestCommand import LitLogObserver
22+
2123
def get_log_details(build):
2224
failed_step = None
2325
text = ""
@@ -58,22 +60,37 @@ def get_log_details(build):
5860
log_text = logs[log_index]['content']['content']
5961
if logs[log_index]['type'] == "s":
6062
# Parse stdio
61-
lines = log_text.splitlines()
62-
for line in lines[:]:
63-
if line.startswith("h"):
64-
lines.remove(line)
65-
for j, line in enumerate(lines):
66-
if line.startswith("o") or line.startswith("e"):
67-
lines[j] = line[1:]
63+
raw_lines = log_text.splitlines()
64+
lines = []
65+
fail_index = -1
66+
for line in raw_lines:
67+
if line.startswith("h"): # header
68+
line = line[1:]
69+
if fail_index == -1:
70+
# Check for "command timed out:"
71+
if LitLogObserver.kTestLineKill.match(line):
72+
fail_index = len(lines)
73+
else:
74+
# Drop this header line
75+
continue
76+
elif line.startswith("o") or line.startswith("e"):
77+
# Adjust stdout or stderr line
78+
line = line[1:]
79+
lines.append(line)
6880
for j, line in enumerate(lines):
81+
if fail_index != -1 and fail_index < j:
82+
break
6983
if line.startswith("FAIL:") or line.find("FAILED") != -1:
70-
if j > 10:
71-
del lines[:j-10] # Start 10 lines before FAIL
72-
lines = ["..."] + lines
73-
del lines[50:] # Keep up to 50 lines around FAIL
84+
fail_index = j
7485
break
75-
if len(lines) > 50:
76-
del lines[:len(lines)-50] # Otherwise keep last 50 lines
86+
if fail_index >= 0:
87+
if fail_index > 10:
88+
del lines[:fail_index-10] # Start 10 lines before FAIL
89+
lines = ["..."] + lines
90+
del lines[50:] # Keep up to 50 lines around FAIL
91+
elif len(lines) > 50:
92+
# Otherwise keep last 50 lines
93+
del lines[:len(lines)-50]
7794
lines = ["..."] + lines
7895

7996
log_text = "\n".join(lines)
@@ -239,13 +256,30 @@ def generate(self, master, reporter, key, build): # override
239256
change = changes[0]
240257
# Get the first line of the commit description.
241258
title = change["comments"].split("\n")[0]
242-
# And store it in properties as 'title'.
243-
build["properties"]["title"] = (
244-
title,
259+
260+
# Search for PR# in the first line of the commit description, which looks like 'Some text (#123)'.
261+
m = re.search(r"^.* \(#(\d+)\)$", title)
262+
if not m:
263+
log.msg(
264+
f"LLVMFailBuildGenerator.generate(buildid={buildid}): WARNING: Cannot extract PR# from the title '{title}'."
265+
)
266+
return None
267+
268+
issue = m.group(1)
269+
270+
# To play it safe for further processing we want a snapshot:
271+
# a local shallow copy of build information,
272+
# along with a copy of build properties.
273+
build_info = build.copy()
274+
build_info["properties"] = build["properties"].copy()
275+
276+
build_info["properties"]["issue"] = (
277+
issue,
245278
None,
246279
)
247280

248-
report = yield self.build_message(self.formatter, master, reporter, build)
281+
#log.msg(f"LLVMFailBuildGenerator.generate(buildid={buildid}): INFO: calling yield self.build_message build_info={build_info}")
282+
report = yield self.build_message(self.formatter, master, reporter, build_info)
249283
# log.msg(f"LLVMFailBuildGenerator.generate(buildid={buildid}): INFO: report={report}")
250284
return report
251285

@@ -255,13 +289,9 @@ class LLVMFailGitHubReporter(GitHubCommentPush):
255289

256290
def _extract_issue(self, props): # override
257291
log.msg(f"LLVMFailGitHubReporter._extract_issue: INFO: props={props}")
258-
title = props.getProperty("title")
259-
if title:
260-
# Search for PR# in the first line of the commit description, which looks like 'Some text (#123)'.
261-
m = re.search(r"^.* \(#(\d+)\)$", title)
262-
if m:
263-
return m.group(1)
264-
return None
292+
issue = props.getProperty("issue")
293+
log.msg(f"LLVMFailGitHubReporter._extract_issue: INFO: issue={issue}")
294+
return issue
265295

266296
# This function is for logging purposes only.
267297
# Could be removed completely if log verbosity would be reduced.

0 commit comments

Comments
 (0)