1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Add JSON validation as a CI stage

This commit is contained in:
Alexander Wilms
2023-09-15 20:55:48 +00:00
parent 2d6ef9049a
commit f38f2d5b6a
2 changed files with 30 additions and 0 deletions

25
.github/validate_json.py vendored Normal file
View File

@@ -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")

View File

@@ -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: