-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically create a json file from the yaml files
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 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,25 @@ | ||
name: Update JSON | ||
|
||
on: [push] | ||
jobs: | ||
test: | ||
name: Update JSON | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# Give the default GITHUB_TOKEN write permission to commit and push the | ||
# added or changed files to the repository. | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.11' | ||
- name: install yaml | ||
run: python -m pip install pyyaml | ||
- name: update json file | ||
run: python yaml2json.py | ||
- name: commit if necessary | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
file_pattern: simtools/simtools.json | ||
commit_message: Update JSON from yaml files |
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,21 @@ | ||
import glob | ||
import os | ||
|
||
import yaml | ||
import json | ||
|
||
if __name__ == "__main__": | ||
data = {} | ||
for fname in sorted(glob.glob("simtools/*.yaml")): | ||
if os.path.basename(fname) == "simtools.yaml": | ||
continue | ||
with open(fname) as f: | ||
tool_data = { | ||
list(item.keys())[0]: list(item.values())[0] | ||
for item in yaml.load(f, Loader=yaml.FullLoader) | ||
} | ||
name = tool_data["name"] | ||
del tool_data["name"] | ||
data[name] = tool_data | ||
with open("simtools/simtools.json", "w") as f: | ||
json.dump(data, f, indent=2, sort_keys=True) |