|
7 | 7 |
|
8 | 8 | import os |
9 | 9 | from datetime import date, timedelta |
| 10 | +from io import StringIO |
10 | 11 | from pathlib import Path |
11 | 12 | from typing import Dict, NotRequired, TypedDict |
12 | 13 |
|
@@ -74,6 +75,11 @@ def write_yaml(path: Path, yaml_dict: dict | list): |
74 | 75 | yaml = ruyaml.YAML() |
75 | 76 | yaml.dump(yaml_dict, file) |
76 | 77 |
|
| 78 | +def to_yaml_string(yaml_dict: dict | list): |
| 79 | + yaml = ruyaml.YAML() |
| 80 | + stream = StringIO() |
| 81 | + yaml.dump(yaml_dict, stream) |
| 82 | + return stream.getvalue() |
77 | 83 |
|
78 | 84 | def write_str(path: Path, content: str): |
79 | 85 | with open(path, "w") as file: |
@@ -190,11 +196,9 @@ def update_actions(dummy_path: Path, actions_path: Path): |
190 | 196 | actions: ActionsYAML = load_yaml(actions_path) |
191 | 197 |
|
192 | 198 | update_refs(steps, actions) |
193 | | - yaml = ruyaml.YAML() |
194 | | - gha_print(yaml.dump(actions), "Generated List") |
| 199 | + gha_print(to_yaml_string(actions), "Generated List") |
195 | 200 | write_yaml(actions_path, actions) |
196 | 201 |
|
197 | | - |
198 | 202 | def create_pattern(actions: ActionsYAML) -> list[str]: |
199 | 203 | """ |
200 | 204 | Create a pattern list of valid action references. |
@@ -228,8 +232,7 @@ def update_patterns(pattern_path: Path, list_path: Path): |
228 | 232 | actions: ActionsYAML = load_yaml(list_path) |
229 | 233 | patterns = create_pattern(actions) |
230 | 234 | comment = f"# This file was generated from {pattern_path} by gateway/gateway.py. DO NOT UPDATE MANUALLY.\n" |
231 | | - yaml = ruyaml.YAML() |
232 | | - patterns_str = comment + yaml.safe_dump(patterns) |
| 235 | + patterns_str = comment + to_yaml_string(patterns) |
233 | 236 | gha_print(patterns_str, "Generated Patterns") |
234 | 237 | write_str(pattern_path, patterns_str) |
235 | 238 |
|
@@ -283,6 +286,5 @@ def clean_actions(actions_path: Path): |
283 | 286 | """ |
284 | 287 | actions: ActionsYAML = load_yaml(actions_path) |
285 | 288 | remove_expired_refs(actions) |
286 | | - yaml = ruyaml.YAML() |
287 | | - gha_print(yaml.safe_dump(actions), "Cleaned Actions") |
| 289 | + gha_print(to_yaml_string(actions), "Cleaned Actions") |
288 | 290 | write_yaml(actions_path, actions) |
0 commit comments