Skip to content

Commit

Permalink
fix(artifacts_collector): fix build initialization if conditional/bra…
Browse files Browse the repository at this point in the history
…nch step has no artifacts (#825)
  • Loading branch information
miltolstoy authored Nov 9, 2023
1 parent 94ce13c commit 714addc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tests/test_conditional_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,16 @@ def test_add_conditional_to_step(test_env: ConditionalStepsTestEnv, capsys: pyte
test_env._check_conditional_step_artifacts_present(steps_info)
test_env._check_executed_step_artifacts_present(steps_info)
# pylint: enable = protected-access


def test_no_artifacts(test_env: ConditionalStepsTestEnv) -> None:
config_lines: List[str] = [
"from universum.configuration_support import Configuration, Step",
"true_branch_config = Configuration([Step(name='True branch step')])",
"conditional_step = Configuration([Step(name='Conditional step', if_succeeded=true_branch_config)])",
"configs = conditional_step"
]

config: str = "\n".join(config_lines)
test_env.configs_file.write_text(config, "utf-8")
test_env.run()
22 changes: 16 additions & 6 deletions universum/modules/artifact_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def set_and_clean_artifacts(self, project_configs: Configuration, ignore_existin
artifact_list: List[ArtifactInfo] = []
for configuration in project_configs.all():
if configuration.artifacts:
artifact_list.append(self.get_config_artifact(configuration))
self.append_config_artifact_if_present(artifact_list, configuration)
if configuration.report_artifacts:
artifact_list.append(self.get_config_artifact(configuration, is_report_artifact=True))
self.append_config_artifact_if_present(artifact_list, configuration, is_report_artifact=True)
if configuration.is_conditional:
artifact_list.extend(self.get_conditional_step_branches_artifacts(configuration))

Expand All @@ -180,16 +180,26 @@ def get_conditional_step_branches_artifacts(self, conditional_step: Step) -> Lis
if conditional_step.if_failed:
steps_to_process.extend(list(conditional_step.if_failed.all()))

artifacts: List[Optional[ArtifactInfo]] = []
artifacts: List[ArtifactInfo] = []
for step in steps_to_process:
artifacts.append(self.get_config_artifact(step))
artifacts.append(self.get_config_artifact(step, is_report_artifact=True))
self.append_config_artifact_if_present(artifacts, step)
self.append_config_artifact_if_present(artifacts, step, is_report_artifact=True)

defined_artifacts: List[ArtifactInfo] = [artifact for artifact in artifacts if artifact]
return defined_artifacts

def get_config_artifact(self, step: Step, is_report_artifact: bool = False) -> ArtifactInfo:
def append_config_artifact_if_present(self,
artifacts: List[ArtifactInfo],
step: Step,
is_report_artifact: bool = False) -> None:
artifact: Optional[ArtifactInfo] = self.get_config_artifact(step, is_report_artifact)
if artifact:
artifacts.append(artifact)

def get_config_artifact(self, step: Step, is_report_artifact: bool = False) -> Optional[ArtifactInfo]:
artifact: str = step.report_artifacts if is_report_artifact else step.artifacts
if not artifact:
return None
path: str = utils.parse_path(artifact, self.settings.project_root)
return dict(path=path, clean=step.artifact_prebuild_clean)

Expand Down

0 comments on commit 714addc

Please sign in to comment.