ci/lava: Don't print empty lines when changing sections
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

Make `print_log` section-aware to stop printing newlines whenever a
section changes.
This also caught a bug: the `handle_exception` was sending an exception
type to the `print_log`, now it is fixed.

Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33906>
This commit is contained in:
Guilherme Gallo 2025-03-06 22:10:42 -03:00 committed by Marge Bot
parent 422e65557d
commit 8fcc52b8d7
3 changed files with 11 additions and 4 deletions

View file

@ -83,11 +83,13 @@ class GitlabSection:
)
def __enter__(self):
print(self.start())
if start_log_line := self.start():
print(start_log_line)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print(self.end())
if end_log_line := self.end():
print(end_log_line)
def start(self) -> str:
assert not self.has_finished, "Starting an already finished section"

View file

@ -182,7 +182,8 @@ class LAVAJob:
return lava_lines[:last_line]
def handle_exception(self, exception: Exception):
print_log(exception)
# Print the exception type and message
print_log(f"{type(exception).__name__}: {str(exception)}")
self.cancel()
self.exception = exception

View file

@ -305,8 +305,12 @@ def fix_lava_gitlab_section_log():
yield first_line
def print_log(msg: str, *args) -> None:
is_section_header = msg.startswith("\x1b[0Ksection_")
if is_section_header:
print(msg, *args)
return
# Reset color from timestamp, since `msg` can tint the terminal color
ts = datetime.now(tz=UTC)
ts_str = f"{ts.hour:02}:{ts.minute:02}:{ts.second:02}.{int(ts.microsecond / 1000):03}"