diff --git a/.github/validate_json.py b/.github/validate_json.py new file mode 100644 index 000000000..0c95557bc --- /dev/null +++ b/.github/validate_json.py @@ -0,0 +1,25 @@ +import jstyleson +from pathlib import Path +from pprint import pprint + +errors = [] +for path in sorted(Path('.').glob('**/*.json')): + # because path is an object and not a string + path_str = str(path) + try: + with open(path_str, 'r') as file: + jstyleson.load(file) + print(f"Validation of {path_str} succeeded") + except Exception as exc: + print(f"Validation of {path_str} failed") + pprint(exc) + # https://stackoverflow.com/a/72850269/2278742 + if hasattr(exc, 'pos'): + position_msg = f"{path_str}:{exc.lineno}:{exc.colno}" + print(position_msg) + errors.append({"position": position_msg, "exception": exc}) + +if errors: + print("Summary of errors:") + pprint(errors) + raise Exception("Not all JSON files are valid") diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 29e3db01d..321e715c8 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -145,6 +145,11 @@ jobs: with: submodules: recursive + - name: Validate JSON + run: | + pip install jstyleson + python3 .github/validate_json.py + - name: Dependencies run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh' env: