From 6f42795608d9e89c17ed6f462b38203abb72bb26 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 9 Jul 2024 12:27:01 -0700 Subject: [PATCH 1/3] ci_build: Add fail-fast option Adds a new command line argument, `-f`, `--fail-fast` to stuart_ci_build that will cause the script to exit immediately if any ci plugin fails. --- edk2toolext/invocables/edk2_ci_build.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/edk2toolext/invocables/edk2_ci_build.py b/edk2toolext/invocables/edk2_ci_build.py index 76d93f02..cbeb62b6 100644 --- a/edk2toolext/invocables/edk2_ci_build.py +++ b/edk2toolext/invocables/edk2_ci_build.py @@ -88,11 +88,14 @@ def AddCommandLineOptions(self, parser: argparse.ArgumentParser) -> None: """Adds command line arguments to Edk2CiBuild.""" parser.add_argument('-d', '--disable-all', dest="disable", action="store_true", default=False, help="Disable all plugins. Use =run to re-enable specific plugins") + parser.add_argument('-f', '--fail-fast', dest="fail_fast", action="store_true", default=False, + help="Exit on the first plugin failure.") super().AddCommandLineOptions(parser) def RetrieveCommandLineOptions(self, args: argparse.Namespace) -> None: """Retrieve command line options from the argparser.""" self.disable_plugins = args.disable + self.fail_fast = args.fail_fast super().RetrieveCommandLineOptions(args) def GetSettingsClass(self) -> type: @@ -242,7 +245,7 @@ def Go(self) -> int: env, self.plugin_manager, self.helper, tc, plugin_output_stream) except Exception as exp: - exc_type, exc_value, exc_traceback = sys.exc_info() + _, _, exc_traceback = sys.exc_info() logging.critical("EXCEPTION: {0}".format(exp)) exceptionPrint = traceback.format_exception(type(exp), exp, exc_traceback) logging.critical(" ".join(exceptionPrint)) @@ -250,14 +253,18 @@ def Go(self) -> int: exp), "UNEXPECTED EXCEPTION") rc = 1 - if (rc > 0): + if rc is None or rc > 0: failure_num += 1 - if (rc is None): + if rc is None: logging.error( f"--->Test Failed: {Descriptor.Name} {target} returned NoneType") else: logging.error( f"--->Test Failed: {Descriptor.Name} {target} returned {rc}") + if self.fail_fast: + logging.error('Exiting Early due to --fail-fast flag.') + JunitReport.Output(os.path.join(self.GetWorkspaceRoot(), "Build", "TestSuites.xml")) + return failure_num elif (rc < 0): logging.warn(f"--->Test Skipped: in plugin! {Descriptor.Name} {target}") else: From 94426621914cb43705b112d5c94d5900c62a8e0d Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 9 Jul 2024 12:42:40 -0700 Subject: [PATCH 2/3] clean up error reporting logic --- edk2toolext/invocables/edk2_ci_build.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/edk2toolext/invocables/edk2_ci_build.py b/edk2toolext/invocables/edk2_ci_build.py index cbeb62b6..7aa73a1e 100644 --- a/edk2toolext/invocables/edk2_ci_build.py +++ b/edk2toolext/invocables/edk2_ci_build.py @@ -255,12 +255,9 @@ def Go(self) -> int: if rc is None or rc > 0: failure_num += 1 - if rc is None: - logging.error( - f"--->Test Failed: {Descriptor.Name} {target} returned NoneType") - else: - logging.error( - f"--->Test Failed: {Descriptor.Name} {target} returned {rc}") + logging.error( + f"--->Test Failed: {Descriptor.Name} {target} returned \"{rc}\"") + if self.fail_fast: logging.error('Exiting Early due to --fail-fast flag.') JunitReport.Output(os.path.join(self.GetWorkspaceRoot(), "Build", "TestSuites.xml")) From 6acbf787c68589f4d2758bbcb3f916c87a7047fc Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 9 Jul 2024 12:43:45 -0700 Subject: [PATCH 3/3] remove unecessary paranthesis --- edk2toolext/invocables/edk2_ci_build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edk2toolext/invocables/edk2_ci_build.py b/edk2toolext/invocables/edk2_ci_build.py index 7aa73a1e..e4792836 100644 --- a/edk2toolext/invocables/edk2_ci_build.py +++ b/edk2toolext/invocables/edk2_ci_build.py @@ -262,7 +262,7 @@ def Go(self) -> int: logging.error('Exiting Early due to --fail-fast flag.') JunitReport.Output(os.path.join(self.GetWorkspaceRoot(), "Build", "TestSuites.xml")) return failure_num - elif (rc < 0): + elif rc < 0: logging.warn(f"--->Test Skipped: in plugin! {Descriptor.Name} {target}") else: edk2_logging.log_progress(f"--->Test Success: {Descriptor.Name} {target}")