diff --git a/.github/scripts/logs.py b/.github/scripts/logs.py index 819e7f7..0616ce1 100755 --- a/.github/scripts/logs.py +++ b/.github/scripts/logs.py @@ -9,16 +9,21 @@ log_group_name = sys.argv[3] log_stream_name = sys.argv[2] + +def split_message(s, length): + for i in range(0, len(s), length): + yield s[i:i + length] + + +log_event = [] with open(sys.argv[1]) as file: message = file.read() - if len(message.encode("utf-8")) > 262144: - message_list = message.split("\n") - mid_point = len(message_list) // 2 - first_half = "\n".join(message_list[0: mid_point]) - second_half = "\n".join(message_list[mid_point:]) - log_event = [{'timestamp': timestamp, 'message': first_half}, {'timestamp': timestamp, 'message': second_half}] + main_message = message.split("::debug::stdout:")[0] + if len(main_message.encode("utf-8")) > 262144: + for chunk in split_message(main_message, 262100): + log_event.append({'timestamp': timestamp, 'message': chunk}) else: - log_event = [{'timestamp': timestamp, 'message': message}] + log_event = [{'timestamp': timestamp, 'message': main_message}] client.create_log_stream(logGroupName=log_group_name, logStreamName=log_stream_name) response = client.put_log_events(logGroupName=log_group_name, @@ -30,6 +35,5 @@ fragment = f"logsV2:log-groups/log-group/{log_group_name}/log-events/{encoded_stream_name}" url = f"{base_url}?region=eu-west-2#{fragment}" - with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: print(f"log-url={url}", file=fh)