Skip to content

Commit

Permalink
ci_build: Add fail-fast option (#847)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Javagedes authored Jul 9, 2024
1 parent 42d92d8 commit 0587ad6
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions edk2toolext/invocables/edk2_ci_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <PluginName>=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:
Expand Down Expand Up @@ -242,23 +245,24 @@ 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))
tc.SetError("Exception: {0}".format(
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}")
Expand Down

0 comments on commit 0587ad6

Please sign in to comment.