1+ name : Validate JSON Files
2+
3+ on :
4+ push :
5+ paths :
6+ - ' **/*.json'
7+ pull_request :
8+ paths :
9+ - ' **/*.json'
10+ workflow_dispatch : # Allows manual triggering
11+
12+ jobs :
13+ validate-json :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout repository
18+ uses : actions/checkout@v4
19+
20+ - name : Setup Node.js
21+ uses : actions/setup-node@v4
22+ with :
23+ node-version : ' 18'
24+
25+ - name : Install dependencies
26+ run : npm install -g ajv-cli ajv-formats
27+
28+ - name : Create JSON schema for validation
29+ run : |
30+ cat > schema.json << 'EOL'
31+ {
32+ "$schema": "http://json-schema.org/draft-07/schema#",
33+ "type": "array",
34+ "items": {
35+ "type": "object",
36+ "required": ["version", "new"],
37+ "properties": {
38+ "version": {
39+ "type": "string",
40+ "pattern": "^\\d+\\.\\d+$|^\\d+\\.\\d+\\.\\d+$"
41+ },
42+ "subVersion": {
43+ "type": "string",
44+ "pattern": "^\\d+\\.\\d+\\.\\d+$"
45+ },
46+ "new": {
47+ "type": "array",
48+ "items": {
49+ "type": "object",
50+ "required": ["icon", "title", "subtitle", "body"],
51+ "properties": {
52+ "icon": { "type": "string" },
53+ "title": { "type": "string" },
54+ "subtitle": { "type": "string" },
55+ "body": { "type": "string" }
56+ }
57+ },
58+ "minItems": 1
59+ }
60+ }
61+ },
62+ "minItems": 1
63+ }
64+ EOL
65+
66+ - name : Find and validate data.json files
67+ run : |
68+ echo "Validating JSON files..."
69+ for FILE in $(find Demo -name "data.json"); do
70+ echo "Checking $FILE"
71+ # Check JSON syntax
72+ if ! jq empty "$FILE" 2>/dev/null; then
73+ echo "❌ Invalid JSON syntax in $FILE"
74+ exit 1
75+ fi
76+
77+ # Validate against schema
78+ if ! npx ajv -s schema.json -d "$FILE" --strict=false; then
79+ echo "❌ $FILE does not match the required schema"
80+ exit 1
81+ else
82+ echo "✅ $FILE is valid"
83+ fi
84+ done
85+
86+ echo "All JSON files are valid! 🎉"
0 commit comments