-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c91c840
commit c759615
Showing
8 changed files
with
135 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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,71 @@ | ||
import logging | ||
import os | ||
|
||
import yaml | ||
|
||
from validate import validate_against_schema | ||
|
||
# Set up basic logging | ||
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') | ||
|
||
|
||
def read_and_merge_configs(base_dir="."): | ||
""" | ||
Reads all config.yml files in the directory structure and merges them. | ||
""" | ||
merged_config = {} | ||
|
||
for root, _, files in os.walk(base_dir): | ||
if "config.yml" in files: | ||
file_path = os.path.join(root, "config.yml") | ||
|
||
try: | ||
with open(file_path, 'r') as stream: | ||
config = yaml.safe_load(stream) | ||
|
||
# Store and remove global properties | ||
global_properties = config.pop("properties", {}) | ||
|
||
# Merge global properties into network-specific properties | ||
for _, network_config in config.get("networks", {}).items(): | ||
local_properties = network_config.get("properties", {}) | ||
network_config["properties"] = {**global_properties, **local_properties} | ||
|
||
# validate configuration | ||
validate_against_schema(config) | ||
|
||
# get source id | ||
source_id = config["source-id"] | ||
# check if source id already exists | ||
if source_id in merged_config: | ||
raise Exception(f"Duplicate source_id: {source_id}") | ||
|
||
logging.info(f"Successfully validated source: {source_id}") | ||
|
||
merged_config[source_id] = config | ||
|
||
except Exception as e: | ||
logging.error(f"Error validating file {file_path}: {e}") | ||
|
||
return merged_config | ||
|
||
|
||
def write_yaml_file(data, file_path=".github/registry.yml"): | ||
""" | ||
Writes data to a YAML file. | ||
""" | ||
try: | ||
with open(file_path, "w") as output_file: | ||
yaml.dump(data, output_file, default_flow_style=False, indent=2) | ||
logging.info(f"Successfully wrote to {file_path}") | ||
except Exception as e: | ||
logging.error(f"Error writing to file {file_path}: {e}") | ||
|
||
|
||
def main(): | ||
merged_config = read_and_merge_configs() | ||
write_yaml_file(merged_config) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
File renamed without changes.
This file contains 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 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 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,35 @@ | ||
name: Merge Source configs and write Source-Registry | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
types: | ||
- closed | ||
paths: | ||
- '**.yml' | ||
|
||
jobs: | ||
merge_yaml: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install required Python packages | ||
run: pip install -r .github/requirements.txt | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Merge Source configs and write Source-Registry | ||
run: python .github/build_registry.py | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Commit and push changes | ||
run: | | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Actions" | ||
git add .github/registry.yml | ||
git commit -m "Update registry.yml" | ||
git push | ||
working-directory: ${{ github.workspace }} |
This file was deleted.
Oops, something went wrong.
This file contains 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,22 @@ | ||
name: Merge Source configs and write Source-Registry | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.yml' | ||
|
||
jobs: | ||
merge_yaml: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install required Python packages | ||
run: pip install -r .github/requirements.txt | ||
working-directory: ${{ github.workspace }} | ||
|
||
- name: Merge Source configs and write Source-Registry | ||
run: python .github/validate_registry.py | ||
working-directory: ${{ github.workspace }} |
This file contains 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