From 0587ad664d712f49ccfda1a9457f975bc39f33c2 Mon Sep 17 00:00:00 2001 From: Joey Vagedes Date: Tue, 9 Jul 2024 15:40:25 -0700 Subject: [PATCH] ci_build: Add fail-fast option (#847) 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 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/edk2toolext/invocables/edk2_ci_build.py b/edk2toolext/invocables/edk2_ci_build.py index 76d93f02..e4792836 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,15 +253,16 @@ 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): - logging.error( - f"--->Test Failed: {Descriptor.Name} {target} returned NoneType") - else: - logging.error( - f"--->Test Failed: {Descriptor.Name} {target} returned {rc}") - elif (rc < 0): + 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: edk2_logging.log_progress(f"--->Test Success: {Descriptor.Name} {target}")