mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-15 20:03:15 +02:00
Add JSON validation as a CI stage
This commit is contained in:
25
.github/validate_json.py
vendored
Normal file
25
.github/validate_json.py
vendored
Normal 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")
|
5
.github/workflows/github.yml
vendored
5
.github/workflows/github.yml
vendored
@@ -145,6 +145,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Validate JSON
|
||||||
|
run: |
|
||||||
|
pip install jstyleson
|
||||||
|
python3 .github/validate_json.py
|
||||||
|
|
||||||
- name: Dependencies
|
- name: Dependencies
|
||||||
run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
|
run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
|
||||||
env:
|
env:
|
||||||
|
Reference in New Issue
Block a user