Skip to content

Commit 57c8c0f

Browse files
committed
Update validate-json.yml
1 parent e11656f commit 57c8c0f

1 file changed

Lines changed: 55 additions & 10 deletions

File tree

.github/workflows/validate-json.yml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,70 @@ jobs:
6363
}
6464
EOL
6565
66-
- name: Find and validate data.json files
66+
- name: Scan for JSON files
67+
id: scan
6768
run: |
68-
echo "Validating JSON files..."
69-
# Use -print0 and read -d '' to handle filenames with spaces properly
69+
echo "Scanning for JSON files..."
70+
# Create a temporary file to store the list of JSON files
71+
touch json_files.txt
72+
73+
# Find all data.json files and group them by language
7074
find Demo -name "data.json" -print0 | while IFS= read -r -d '' FILE; do
71-
echo "Checking $FILE"
75+
# Extract the language from the directory path
76+
LANG_DIR=$(dirname "$FILE")
77+
LANG=$(basename "$LANG_DIR")
78+
echo "$LANG:$FILE" >> json_files.txt
79+
done
80+
81+
echo "Found the following JSON files for validation:"
82+
cat json_files.txt
83+
84+
echo "Scan completed."
85+
86+
- name: Validate JSON syntax per language
87+
run: |
88+
echo "Validating JSON syntax for each language..."
89+
ERROR=0
90+
91+
# Process each file by language
92+
while IFS=':' read -r LANG_DIR FILE || [ -n "$FILE" ]; do
93+
echo "Checking syntax for language: $LANG_DIR - $FILE"
94+
7295
# Check JSON syntax
7396
if ! jq empty "$FILE" 2>/dev/null; then
74-
echo "❌ Invalid JSON syntax in $FILE"
75-
exit 1
97+
echo "❌ Invalid JSON syntax in $LANG_DIR ($FILE)"
98+
ERROR=1
99+
else
100+
echo "✅ JSON syntax is valid for $LANG_DIR"
76101
fi
102+
done < json_files.txt
103+
104+
if [ $ERROR -ne 0 ]; then
105+
echo "JSON syntax validation failed"
106+
exit 1
107+
fi
108+
109+
- name: Validate schema per language
110+
run: |
111+
echo "Validating JSON schema for each language..."
112+
ERROR=0
113+
114+
# Process each file by language
115+
while IFS=':' read -r LANG_DIR FILE || [ -n "$FILE" ]; do
116+
echo "Validating schema for language: $LANG_DIR - $FILE"
77117
78118
# Validate against schema
79119
if ! npx ajv -s schema.json -d "$FILE" --strict=false; then
80-
echo "❌ $FILE does not match the required schema"
81-
exit 1
120+
echo "❌ $LANG_DIR ($FILE) does not match the required schema"
121+
ERROR=1
82122
else
83-
echo "✅ $FILE is valid"
123+
echo "✅ Schema is valid for $LANG_DIR"
84124
fi
85-
done
125+
done < json_files.txt
126+
127+
if [ $ERROR -ne 0 ]; then
128+
echo "JSON schema validation failed"
129+
exit 1
130+
fi
86131
87132
echo "All JSON files are valid! 🎉"

0 commit comments

Comments
 (0)