|
1 | | -name: Validate GPTP Schema |
| 1 | +name: Validate GPTP Schema (meta only) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | paths: |
6 | 6 | - "schema/gptp.schema.json" |
7 | | - - "docs/examples/**/*.gptp" |
8 | 7 | - ".github/workflows/validate-schema.yml" |
9 | 8 | pull_request: |
10 | 9 | paths: |
11 | 10 | - "schema/gptp.schema.json" |
12 | | - - "docs/examples/**/*.gptp" |
13 | 11 | - ".github/workflows/validate-schema.yml" |
14 | 12 |
|
15 | 13 | jobs: |
16 | 14 | validate: |
17 | | - name: Validate schema and example GPTP files |
| 15 | + name: Meta-validate JSON Schema |
18 | 16 | runs-on: ubuntu-latest |
19 | 17 |
|
20 | 18 | steps: |
|
26 | 24 | with: |
27 | 25 | node-version: "20" |
28 | 26 |
|
29 | | - - name: Install AJV CLI and formats |
30 | | - run: | |
31 | | - npm install --no-save ajv@8 ajv-formats@2 |
| 27 | + - name: Install Ajv (ephemeral) |
| 28 | + run: npm install --no-save ajv@8 ajv-formats@2 |
32 | 29 |
|
33 | 30 | - name: ✅ Meta-validate gptp.schema.json |
34 | 31 | run: | |
|
52 | 49 | console.log("✅ gptp.schema.json is valid"); |
53 | 50 | EOF |
54 | 51 |
|
55 | | - - name: ✅ Validate example .gptp files |
56 | | - run: | |
57 | | - node <<'EOF' |
58 | | - const fs = require('fs'); |
59 | | - const path = require('path'); |
60 | | - const Ajv = require('ajv').default; |
61 | | - const addFormats = require('ajv-formats'); |
62 | | -
|
63 | | - const ajv = new Ajv({ strict: true, allowUnionTypes: true, allErrors: true }); |
64 | | - addFormats(ajv); |
65 | | -
|
66 | | - const schema = JSON.parse(fs.readFileSync('schema/gptp.schema.json', 'utf8')); |
67 | | - const validate = ajv.compile(schema); |
68 | | -
|
69 | | - const exampleDir = 'docs/examples'; |
70 | | - const files = fs.readdirSync(exampleDir).filter(f => f.endsWith('.gptp')); |
71 | | -
|
72 | | - if (files.length === 0) { |
73 | | - console.log("⚠️ No .gptp files found in docs/examples/"); |
74 | | - process.exit(0); |
75 | | - } |
76 | | -
|
77 | | - let failures = 0; |
78 | | -
|
79 | | - for (const file of files) { |
80 | | - const filePath = path.join(exampleDir, file); |
81 | | - try { |
82 | | - const data = JSON.parse(fs.readFileSync(filePath, 'utf8')); |
83 | | -
|
84 | | - const valid = validate(data); |
85 | | - if (!valid) { |
86 | | - console.error(`❌ ${file} failed validation:`); |
87 | | - console.error(JSON.stringify(validate.errors, null, 2)); |
88 | | - failures++; |
89 | | - } else { |
90 | | - console.log(`✅ ${file} passed`); |
91 | | - } |
92 | | - } catch (err) { |
93 | | - console.error(`❌ ${file} could not be read or parsed:`); |
94 | | - console.error(err.message); |
95 | | - failures++; |
96 | | - } |
97 | | - } |
98 | | -
|
99 | | - if (failures > 0) { |
100 | | - console.error(`❌ ${failures} file(s) failed validation`); |
101 | | - process.exit(1); |
102 | | - } |
103 | | - EOF |
104 | | -
|
105 | 52 | - name: Cleanup |
106 | 53 | run: rm -rf node_modules package-lock.json |
0 commit comments