mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Add shebang, use elif and only run on linux-clang-test
This commit is contained in:
parent
512816b223
commit
e0089c76ae
16
.github/validate_json.py
vendored
Normal file → Executable file
16
.github/validate_json.py
vendored
Normal file → Executable file
@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from pprint import pprint
|
||||
@ -20,7 +22,7 @@ for path in sorted(Path('.').glob('**/*.json')):
|
||||
with open(path_str, 'r') as file:
|
||||
if VALIDATION_TYPE == 'json':
|
||||
jstyleson.load(file)
|
||||
if VALIDATION_TYPE == 'json5':
|
||||
elif VALIDATION_TYPE == 'json5':
|
||||
json5.load(file)
|
||||
elif VALIDATION_TYPE == 'yaml':
|
||||
file = file.read().replace("\t", " ")
|
||||
@ -33,17 +35,21 @@ for path in sorted(Path('.').glob('**/*.json')):
|
||||
|
||||
error_pos = path_str
|
||||
|
||||
# create error position strings for each type of parser
|
||||
if hasattr(exc, 'pos'):
|
||||
# 'json'
|
||||
# https://stackoverflow.com/a/72850269/2278742
|
||||
error_pos = f"{path_str}:{exc.lineno}:{exc.colno}"
|
||||
print(error_pos)
|
||||
if hasattr(exc, 'problem_mark'):
|
||||
elif VALIDATION_TYPE == 'json5':
|
||||
# 'json5'
|
||||
pos = re.findall(r'\d+', str(exc))
|
||||
error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
|
||||
elif hasattr(exc, 'problem_mark'):
|
||||
# 'yaml'
|
||||
mark = exc.problem_mark
|
||||
error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}"
|
||||
print(error_pos)
|
||||
if VALIDATION_TYPE == 'json5':
|
||||
pos = re.findall(r'\d+', str(exc))
|
||||
error_pos = f"{path_str}:{pos[0]}:{pos[-1]}"
|
||||
|
||||
errors.append({"error_pos": error_pos, "error_msg": exc})
|
||||
|
||||
|
3
.github/workflows/github.yml
vendored
3
.github/workflows/github.yml
vendored
@ -147,7 +147,8 @@ jobs:
|
||||
|
||||
- name: Validate JSON
|
||||
# the Python yaml module doesn't seem to work on mac-arm
|
||||
if: ${{ startsWith(matrix.preset, 'linux') }}
|
||||
# also, running it on multiple presets is redundant and slightly increases already long CI built times
|
||||
if: ${{ startsWith(matrix.preset, 'linux-clang-test') }}
|
||||
run: |
|
||||
pip3 install json5 jstyleson
|
||||
python3 .github/validate_json.py
|
||||
|
Loading…
Reference in New Issue
Block a user