-
Notifications
You must be signed in to change notification settings - Fork 1
Refactoring/686 output yaml values #687
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
Merged
+372
−201
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2e9c22c
Add code to make workflows render with ruamel-yaml
ArBridgeman 556c1a7
Rename test to avoid duplicate name
ArBridgeman 0735a19
Switch over tbx to use code in util.workflows
ArBridgeman ac1f1a3
Fix template - remove extra whitespace
ArBridgeman 9b5006a
Fix template - have list be vertical not horizontal
ArBridgeman 579e4a8
Apply tbx workflow update but preserve custom PTB
ArBridgeman e48dd73
Add changelog entry and remove pyyaml from direct deps
ArBridgeman 4f37476
Ignore type error
ArBridgeman 57c7bc7
Bump pip in poetry.lock
ArBridgeman 91e40a2
Add file_path to error message
ArBridgeman c3aef07
Update test to split out concerns so clearer for future usage
ArBridgeman 62d0a2a
Update to cleaner text from reviewer
ArBridgeman 142b7ca
Rename module to be clearer; this will likely only be processing and …
ArBridgeman db62fd2
Switch from 'convert' to 'render' as more precise for the operation
ArBridgeman 180b503
Switch from 'TemplateToWorkflow' to 'TemplateRenderer' for PEP-compli…
ArBridgeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ on: | |
| workflow_call: | ||
| secrets: | ||
| PYPI_TOKEN: | ||
| required: true | ||
| required: true | ||
|
|
||
| jobs: | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from dataclasses import dataclass | ||
ArBridgeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| from typing import Any | ||
|
|
||
| from jinja2 import Environment | ||
|
|
||
| jinja_env = Environment( | ||
| variable_start_string="((", variable_end_string="))", autoescape=True | ||
| ) | ||
|
|
||
| import io | ||
| from inspect import cleandoc | ||
|
|
||
| from ruamel.yaml import YAML | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class TemplateRenderer: | ||
| template_str: str | ||
| github_template_dict: dict[str, Any] | ||
|
|
||
| def _render_with_jinja(self, input_str: str) -> str: | ||
| """ | ||
| Render the template with Jinja. | ||
| """ | ||
| jinja_template = jinja_env.from_string(input_str) | ||
| return jinja_template.render(self.github_template_dict) | ||
|
|
||
| def render_to_workflow(self) -> str: | ||
| """ | ||
| Render the template to the contents of a valid GitHub workflow. | ||
| """ | ||
| yaml = YAML() | ||
| yaml.width = 200 | ||
| yaml.preserve_quotes = True | ||
| yaml.sort_base_mapping_type_on_output = False # type: ignore | ||
| yaml.indent(mapping=2, sequence=4, offset=2) | ||
|
|
||
| workflow_string = self._render_with_jinja(self.template_str) | ||
| workflow_dict = yaml.load(workflow_string) | ||
|
|
||
| stream = io.StringIO() | ||
| yaml.dump(workflow_dict, stream) | ||
| workflow_string = stream.getvalue() | ||
| return cleandoc(workflow_string) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from pydantic import ( | ||
| BaseModel, | ||
| ConfigDict, | ||
| ) | ||
|
|
||
| from exasol.toolbox.util.workflows.template_processing import TemplateRenderer | ||
|
|
||
|
|
||
| class Workflow(BaseModel): | ||
| model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True) | ||
|
|
||
| content: str | ||
|
|
||
| @classmethod | ||
| def load_from_template(cls, file_path: Path, github_template_dict: dict[str, Any]): | ||
ArBridgeman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if not file_path.exists(): | ||
| raise FileNotFoundError(file_path) | ||
|
|
||
| try: | ||
| raw_content = file_path.read_text() | ||
| template_renderer = TemplateRenderer( | ||
| template_str=raw_content, github_template_dict=github_template_dict | ||
| ) | ||
| workflow = template_renderer.render_to_workflow() | ||
| return cls(content=workflow) | ||
| except Exception as e: | ||
| raise ValueError(f"Error rendering file: {file_path}") from e | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.