-
Notifications
You must be signed in to change notification settings - Fork 3
73 lines (63 loc) · 1.9 KB
/
validate-json.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Validate JSON
on:
push:
paths:
- "**.json"
pull_request:
paths:
- "**.json"
jobs:
validate-json:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Create validation script
run: |
cat > validate-json.js << 'EOF'
const fs = require('fs');
const path = require('path');
// Schema for org.json
const orgSchema = {
type: 'array',
items: {
type: 'object',
required: ['id', 'name', 'description', 'org_url', 'logo_url'],
properties: {
id: { type: 'string' },
name: { type: 'string' },
description: { type: 'string' },
org_url: {
type: 'string',
format: 'uri'
},
logo_url: {
type: 'string',
format: 'uri'
}
}
}
};
function validateJson(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
JSON.parse(content); // This will throw if JSON is invalid
console.log(`✅ ${filePath} is valid JSON`);
return true;
} catch (error) {
console.error(`❌ ${filePath} is invalid JSON:`, error.message);
process.exit(1);
}
}
// Find and validate all JSON files
const jsonFiles = fs.readdirSync('.')
.filter(file => file.endsWith('.json'));
jsonFiles.forEach(validateJson);
EOF
- name: Install validation dependencies
run: npm install ajv ajv-formats
- name: Validate JSON files
run: node validate-json.js