Merge pull request 'Update merge_yaml.py' (#190) from fenix-admin into main

Reviewed-on: fenix-gitea-admin/iac-teste#190
This commit is contained in:
2025-08-27 19:58:58 +00:00

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
import yaml
from ruamel.yaml import YAML
import sys
import json
from collections.abc import Mapping
@ -23,31 +23,19 @@ def main():
file1 = input_data["file1"]
file2 = input_data["file2"]
yaml = YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
with open(file1, "r") as f1, open(file2, "r") as f2:
try:
yaml1 = yaml.safe_load(f1)
except yaml.YAMLError as e:
print("Erro ao carregar YAML do primeiro ficheiro:")
print(f1.read())
raise e
try:
yaml2 = yaml.safe_load(f2)
except yaml.YAMLError as e:
print("Erro ao carregar YAML do segundo ficheiro:")
print(f2.read())
raise e
yaml1 = yaml.load(f1)
yaml2 = yaml.load(f2)
from io import StringIO
output = StringIO()
yaml.dump(merged, output)
merged = deep_merge_yaml(yaml1, yaml2)
print(json.dumps({
"merged_yaml": yaml.dump(
merged,
sort_keys=False,
default_flow_style=False,
indent=2
)
"merged_yaml": output.getvalue()
}))