Skip to content

Commit

Permalink
feat(launcher): explicit warning about 'critical' flag ignoring on co… (
Browse files Browse the repository at this point in the history
  • Loading branch information
miltolstoy authored Jun 27, 2023
1 parent 8979ee8 commit 452abeb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/test_conditional_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ConditionalStepsTestEnv(LocalTestEnvironment):
def __init__(self, tmp_path: pathlib.Path, capsys: pytest.CaptureFixture) -> None:
super().__init__(tmp_path, "main")
self.capsys = capsys
self.captured_out: pytest.CaptureResult[AnyStr] = None

def build_conditional_steps_info(self, is_conditional_step_passed: bool) -> StepsInfo:
steps_info: StepsInfo = StepsInfo()
Expand All @@ -45,9 +46,9 @@ def check_success(self, steps_info: StepsInfo) -> None:
self._write_config_file(steps_info)
self.run()

captured: pytest.CaptureResult[AnyStr] = self.capsys.readouterr()
self.captured_out = self.capsys.readouterr()
conditional_succeeded_regexp: str = r"\] conditional.*Success.*\| 5\.2"
assert re.search(conditional_succeeded_regexp, captured.out, re.DOTALL)
assert re.search(conditional_succeeded_regexp, self.captured_out.out, re.DOTALL)

self._check_conditional_step_artifacts_present(steps_info)
self._check_executed_step_artifacts_present(steps_info)
Expand Down Expand Up @@ -228,3 +229,11 @@ def test_conditional_step_with_children(test_env: ConditionalStepsTestEnv) -> No
steps_info: StepsInfo = test_env.build_conditional_steps_info(is_conditional_step_passed=True)
steps_info.conditional_step.children = Configuration([Step(name=" dummy child 1"), Step(name=" dummy child 2")])
test_env.check_fail(steps_info)


def test_conditional_step_critical(test_env: ConditionalStepsTestEnv) -> None:
steps_info: StepsInfo = test_env.build_conditional_steps_info(is_conditional_step_passed=False)
steps_info.conditional_step.critical = True
test_env.check_success(steps_info)
assert test_env.captured_out.out
assert "WARNING" in test_env.captured_out.out
25 changes: 25 additions & 0 deletions universum/modules/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ def process_project_configs(self) -> configuration_support.Configuration:

if self._is_conditional_step_with_children_present(self.project_config):
raise CriticalCiException("Conditional step doesn't support children configuration")
self._warn_if_critical_conditional_steps_present(self.project_config)

return self.project_config

Expand Down Expand Up @@ -455,3 +456,27 @@ def _is_conditional_step_with_children_present(
Launcher._is_conditional_step_with_children_present(step.if_failed):
return True
return False

def _warn_if_critical_conditional_steps_present(
self, configuration: Optional[configuration_support.Configuration]) -> None:
step_names: List[str] = Launcher._get_critical_conditional_step_names_recursively(configuration)
if not step_names:
return
step_names = [f'\t* "{name}"' for name in step_names]
step_names_str: str = "\n".join(step_names)
self.out.log(f"WARNING: 'critical' flag will be ignored for conditional steps: \n{step_names_str}\n "
"Set it to the 'if_failed' branch step instead")

@staticmethod
def _get_critical_conditional_step_names_recursively(
configuration: Optional[configuration_support.Configuration]) -> List[str]:
step_names: List[str] = []
if not configuration:
return step_names
for step in configuration.configs:
if step.is_conditional and step.critical:
step_names.append(step.name)
step_names.extend(Launcher._get_critical_conditional_step_names_recursively(step.children))
step_names.extend(Launcher._get_critical_conditional_step_names_recursively(step.if_succeeded))
step_names.extend(Launcher._get_critical_conditional_step_names_recursively(step.if_failed))
return step_names

0 comments on commit 452abeb

Please sign in to comment.