Skip to content

Commit

Permalink
On fails, extract the lines with the failure marker >> from the logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardkaindl committed Oct 12, 2024
1 parent e11b227 commit 95cd01b
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions build_pr_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,40 @@ def main(args) -> int:
return build_and_act_on_results(args, installed, specs_to_check)


def generate_build_results(installed, passed, failed, about_build_host) -> str:
def failure_summary(fails: List[Tuple[str, str]]) -> str:
"""Generate a summary of the failed specs."""
if not fails:
return ""

fails_summary = f"{len(fails)} failed specs:" if len(fails) > 1 else "One failed spec:"
for failed_spec, _ in fails:
fails_summary += f"- `{failed_spec}`\n"

for failed_spec, log_file in fails:
fails_summary += f"### `{failed_spec}`:\n```py\n"
with open(log_file, "r", encoding="utf-8") as log:
lines = log.readlines()
# Print one line before lines with the error marker as well:
previous_line = ""
for line in lines:
if r"[0;91m>> " in line: # Match the color code and error marker.
fails_summary += previous_line
fails_summary += line
previous_line = ""
else:
previous_line = line
fails_summary += ("".join(lines)).strip()
fails_summary += "\n```\n"
if "failed to concretize" in lines[0]:
fails_summary += "spack failed to concretize specs due to conflicts.\nThis is"
fails_summary += " likely intentional due to a conflict() in the recipe(s).\n"

# TODO: Add support for showing details about the failed specs
# like used deps (cmake version, openssl version, etc.)
return fails_summary


def generate_build_results(installed, passed, fails, about_build_host) -> str:
"""Generate a report in markdown format for cut-and-paste into the PR comment."""

build_results = f"\nBuild results{about_build_host}:\n```py\n"
Expand All @@ -851,32 +884,8 @@ def generate_build_results(installed, passed, failed, about_build_host) -> str:
build_results += stdout.replace(" build_system=python_pip", "")
else:
build_results += stderr or stdout
build_results += "\n```\n"
if failed:
title = f"{len(failed)} failed specs:" if len(failed) > 1 else "One failed spec:"
build_results += f"\n## {title}\n"
for failed_spec, _ in failed:
build_results += f"- `{failed_spec}`\n"

for failed_spec, log_file in failed:
build_results += f"### `{failed_spec}`:\n```py\n"
# Read log file, look for "found in build log" and add the lines after it.
with open(log_file, "r", encoding="utf-8") as log:
lines = log.readlines()
for line in lines:
if "found in build log" in line:
build_results += line
build_results += "".join(lines[lines.index(line) + 8 : -8])
break
build_results += ("".join(lines)).strip()
build_results += "\n```\n"
if "failed to concretize" in lines[0]:
build_results += "spack failed to concretize the spec due to a conflict.\nThis is"
build_results += " likely intentional due to a conflict() in the recipe(s).\n"

# TODO: Add support for showing details about the failed specs
# like used deps (cmake version, openssl version, etc.)

build_results += "\n```\n" + failure_summary(fails)
build_results += "\nGenerated by "
git_dir = os.path.dirname(os.path.realpath(__file__))
err, stdout, stderr = run(["git", "-C", git_dir, "config", "--get", "remote.origin.url"])
Expand Down

0 comments on commit 95cd01b

Please sign in to comment.