From 2a33dbb5a752bed94e80d47aab83b6f204d3bd34 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 18 Feb 2021 10:06:36 +1100 Subject: [PATCH] ci: Include context from failed build logs in the CI job log This is faster to look up than browsing or downloading artifacts, and will often contain the root cause. Context includes the last 25 lines of the log, and any lines contaiing 'error:' or 'warning:' --- tools/build_apps.py | 19 +++++++++++++++++++ tools/ci/mypy_ignore_list.txt | 1 - 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tools/build_apps.py b/tools/build_apps.py index e613bb5b78..52c81f05fe 100755 --- a/tools/build_apps.py +++ b/tools/build_apps.py @@ -7,11 +7,19 @@ import argparse import logging +import os.path +import re import sys from find_build_apps import BUILD_SYSTEMS, BuildError, BuildItem, setup_logging from find_build_apps.common import SIZE_JSON_FN, rmdir +# This RE will match GCC errors and many other fatal build errors and warnings as well +LOG_ERROR_WARNING = re.compile(r'(error|warning):', re.IGNORECASE) + +# Log this many trailing lines from a failed build log, also +LOG_DEBUG_LINES = 25 + def main(): # type: () -> None parser = argparse.ArgumentParser(description='ESP-IDF app builder') @@ -120,6 +128,17 @@ def main(): # type: () -> None build_system_class.build(build_info) except BuildError as e: logging.error(str(e)) + if build_info.build_log_path: + log_filename = os.path.basename(build_info.build_log_path) + with open(build_info.build_log_path, 'r') as f: + lines = [line.rstrip() for line in f.readlines() if line.rstrip()] # non-empty lines + logging.debug('Error and warning lines from {}:'.format(log_filename)) + for line in lines: + if LOG_ERROR_WARNING.search(line): + logging.warning('>>> {}'.format(line)) + logging.debug('Last {} lines of {}:'.format(LOG_DEBUG_LINES, log_filename)) + for line in lines[-LOG_DEBUG_LINES:]: + logging.debug('>>> {}'.format(line)) if args.keep_going: failed_builds.append(build_info) else: diff --git a/tools/ci/mypy_ignore_list.txt b/tools/ci/mypy_ignore_list.txt index dbe2d682eb..0a77e48b4d 100644 --- a/tools/ci/mypy_ignore_list.txt +++ b/tools/ci/mypy_ignore_list.txt @@ -153,7 +153,6 @@ examples/wifi/iperf/iperf_test.py tools/ble/lib_ble_client.py tools/ble/lib_gap.py tools/ble/lib_gatt.py -tools/build_apps.py tools/check_python_dependencies.py tools/check_term.py tools/ci/check_artifacts_expire_time.py