Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog-entries/830.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Failed system tests now append the last lines of the relevant stage log to the GitHub Actions job summary [#830](https://github.com/precice/tutorials/pull/830).
43 changes: 43 additions & 0 deletions tools/tests/systemtests/Systemtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"compare": "system-tests-compare.log",
}

FAILURE_LOG_TAIL_LINES = 100


class _SystemtestLogSink:
"""Writes subprocess output incrementally to per-stage log files."""
Expand Down Expand Up @@ -111,6 +113,45 @@ def _success_status_symbol(success: bool) -> str:
return "✅" if success else "❌"


def _read_log_tail(log_path: Path, max_lines: int = FAILURE_LOG_TAIL_LINES) -> str:
lines = log_path.read_text(encoding="utf-8", errors="replace").splitlines()
if not lines:
return "(log file is empty)"
return "\n".join(lines[-max_lines:])


def _append_failure_log_tails_to_summary(results: List[SystemtestResult]) -> None:
summary_path = os.environ.get("GITHUB_STEP_SUMMARY")
if not summary_path:
return

failed_results = [result for result in results if not result.success]
if not failed_results:
return

with open(summary_path, "a", encoding="utf-8") as summary_file:
print("\n## Failed test logs\n", file=summary_file)
for result in failed_results:
print(
f"### {_success_status_symbol(False)} {result.systemtest}\n",
file=summary_file,
)
run_dir = result.systemtest.get_system_test_dir()
for log_name in STAGE_LOG_FILES.values():
log_path = run_dir / log_name
if not log_path.is_file():
continue
tail = _read_log_tail(log_path)
print("<details>", file=summary_file)
print(f"<summary>{log_name} tail</summary>", file=summary_file)
print("", file=summary_file)
print("```text", file=summary_file)
print(tail, file=summary_file)
print("```", file=summary_file)
print("</details>", file=summary_file)
Comment thread
PranjalManhgaye marked this conversation as resolved.
print("", file=summary_file)


def display_systemtestresults_as_table(results: List[SystemtestResult]):
"""
Prints the result in a nice tabluated way to get an easy overview
Expand Down Expand Up @@ -152,6 +193,8 @@ def _get_length_of_name(results: List[SystemtestResult]) -> int:
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
print(row, file=f)

_append_failure_log_tails_to_summary(results)

if "GITHUB_STEP_SUMMARY" in os.environ:
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as f:
print("\n\n", file=f)
Expand Down
Loading