Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(structure_handler): initialize conditional steps logic #737

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions universum/configuration_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class Step:
A tag used to mark successful TeamCity builds. This tag can be set independenty
of `fail_tag` value per each step. The value should be set to a strings without spaces as acceptable by
TeamCity as tags. Every tag is added (if matching condition) after executing build step it is set in,
not in the end of all run.
not in the end of all run. Not applicable for conditional steps.
fail_tag
A tag used to mark failed TemCity builds. See `pass_tag` for details.
A tag used to mark failed TemCity builds. See `pass_tag` for details. Not applicable for conditional steps.

Each parameter is optional, and is substituted with a falsy value, if omitted.

Expand Down
34 changes: 17 additions & 17 deletions universum/modules/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,6 @@ def handle_stderr(self, line: str) -> None:
else:
self.out.log_stderr(line)

def add_tag(self, tag: str) -> None:
if not tag:
return

request: Response = self.send_tag(tag)
if request.status_code != 200:
self.out.log_error(request.text)
else:
self.out.log("Tag '" + tag + "' added to build.")

def finalize(self) -> None:
self._error = None
if not self._needs_finalization:
Expand All @@ -282,15 +272,12 @@ def finalize(self) -> None:
text = utils.trim_and_convert_to_unicode(text)
if self.file:
self.file.write(text + "\n")
if not self.configuration.is_conditional:
self.add_tag(self.configuration.fail_tag)
self._error = text
return

self.add_tag(self.configuration.pass_tag)
return
self._error = text

finally:
tag: Optional[str] = self._get_teamcity_build_tag()
if tag:
self._assign_teamcity_build_tag(tag)
self.handle_stdout()
if self.file:
self.file.close()
Expand All @@ -308,6 +295,19 @@ def _handle_postponed_out(self) -> None:
item[0](item[1])
self._postponed_out = []

def _get_teamcity_build_tag(self) -> Optional[str]:
if self.configuration.is_conditional:
return None # conditional steps always succeed, no sense to set a tag
tag: str = self.configuration.fail_tag if self._error else self.configuration.pass_tag
return tag # can be also None if not set for current Configuration

def _assign_teamcity_build_tag(self, tag: str) -> None:
response: Response = self.send_tag(tag)
if response.status_code != 200:
self.out.log_error(response.text)
else:
self.out.log("Tag '" + tag + "' added to build.")


class Launcher(ProjectDirectory, HasOutput, HasStructure, HasErrorState):
artifacts_factory = Dependency(artifact_collector.ArtifactCollector)
Expand Down