-
Notifications
You must be signed in to change notification settings - Fork 13
61 lines (49 loc) · 1.78 KB
/
Copy pathvalidate-schemas.yml
File metadata and controls
61 lines (49 loc) · 1.78 KB
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
name: Validate Schemas
on:
push:
branches: [ main, examples/** ]
pull_request:
branches: [ main ]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install ajv-cli
run: npm install -g ajv-cli
- name: Validate schemas
run: |
echo "Validating all schema files..."
# Compile all schemas together so cross-references can be resolved
# The 0-prefixed reference schema loads first alphabetically
set +e
AJV_OUT="$(ajv compile -s "examples/*/types/*.schema.json" --strict=false 2>&1 | grep "^error: " || true)"
AJV_CODE=$?
set -e
if [ "$AJV_CODE" -eq 0 ]; then
echo "OK: all schemas are valid"
exit 0
fi
# If the only failures are "can't resolve reference", treat them as warnings.
# This allows schemas to be validated syntactically even when external $ref targets
# (or custom URI schemes) are intentionally not resolvable in CI.
UNRESOLVED="$(echo "$AJV_OUT" | grep -Ei "can't resolve reference|cannot resolve reference|can not resolve reference" || true)"
OTHER="$(echo "$AJV_OUT" | grep -Eiv "can't resolve reference|cannot resolve reference|can not resolve reference" || true)"
if [ -n "$OTHER" ]; then
echo "$AJV_OUT"
echo "ERROR: schema validation failed"
exit 1
fi
if [ -n "$UNRESOLVED" ]; then
echo "WARN: some $ref targets could not be resolved (allowed):"
echo "$UNRESOLVED"
exit 0
fi
echo "$AJV_OUT"
echo "ERROR: schema validation failed"
exit 1