Skip to content

Commit 70e72b4

Browse files
authored
Optimize JSON validation on CI (CleverRaven#55060)
1 parent c3c92d1 commit 70e72b4

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

build-scripts/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
if [ -n "$TEST_STAGE" ]
2121
then
22-
build-scripts/lint-json.sh
22+
build-scripts/validate_json.py
2323
make style-all-json-parallel RELEASE=1
2424

2525
tools/dialogue_validator.py data/json/npcs/* data/json/npcs/*/* data/json/npcs/*/*/*

build-scripts/gha_compile_only.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fi
1919

2020
if [ -n "$TEST_STAGE" ]
2121
then
22-
build-scripts/lint-json.sh
22+
build-scripts/validate_json.py
2323
make style-all-json-parallel RELEASE=1
2424

2525
tools/dialogue_validator.py data/json/npcs/* data/json/npcs/*/* data/json/npcs/*/*/*

build-scripts/lint-json.sh

-1
This file was deleted.

build-scripts/validate_json.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
# Validate that all JSON files are syntactically correct;
4+
# does NOT check indentation styles.
5+
6+
import glob
7+
import json
8+
import sys
9+
10+
11+
def main():
12+
json_files = glob.glob('**/**.json', recursive=True)
13+
errors = 0
14+
total = 0
15+
for file_path in json_files:
16+
if not file_path.startswith("android/app/src/main/assets"):
17+
total += 1
18+
try:
19+
with open(file_path, encoding="utf-8") as fp:
20+
_ = json.load(fp)
21+
except OSError as e:
22+
print("Error opening {}: {}".format(file_path, e))
23+
errors += 1
24+
except json.JSONDecodeError as e:
25+
print("Error parsing {}: {}".format(file_path, e))
26+
errors += 1
27+
if errors == 0:
28+
print("All {} JSON files healthy.".format(total))
29+
return 0
30+
else:
31+
print("Found {} erroneous files among {} JSON files in the repository."
32+
.format(errors, total))
33+
return min(errors, 255)
34+
35+
36+
if __name__ == '__main__':
37+
sys.exit(main())

0 commit comments

Comments
 (0)