Skip to content

Commit b5c5eb4

Browse files
committed
chore: validate schema generation in CI
Adds schema generation and validation checks to the docs workflow. CI currently only checks if Pydantic models can be generated from existing spec files, but doesn't validate the schemas themselves or check if spec/ stays in sync with source/. This catches common mistakes like editing source schemas but forgetting to run generate_schemas.py, or committing invalid JSON schemas. Changes: - Run generate_schemas.py in CI to verify generation works - Run validate_specs.py to catch schema syntax errors - Check git diff on spec/ to catch out-of-sync files - Check for untracked files in spec/ to catch new generated files - Add pre-commit hook for local validation - Add source/**, generate_schemas.py, schema_utils.py, and validate_specs.py to workflow trigger paths
1 parent 4362390 commit b5c5eb4

3 files changed

Lines changed: 43 additions & 8 deletions

File tree

.cspell/custom-words.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ shopify
7575
superfences
7676
vulnz
7777
yaml
78-
ymlEDITMSG
78+
yml
79+
EDITMSG

.github/workflows/docs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727
- "source/**"
2828
- "spec/**"
2929
- "generate_schemas.py"
30+
- "schema_utils.py"
3031
- "validate_specs.py"
3132
pull_request:
3233
branches:
@@ -40,6 +41,7 @@ on:
4041
- "source/**"
4142
- "spec/**"
4243
- "generate_schemas.py"
44+
- "schema_utils.py"
4345
- "validate_specs.py"
4446

4547
jobs:
@@ -99,6 +101,11 @@ jobs:
99101
git diff --name-only spec/
100102
exit 1
101103
fi
104+
if git ls-files --others --exclude-standard spec/ | grep -q .; then
105+
echo "Warning: spec/ contains untracked generated files"
106+
git ls-files --others --exclude-standard spec/
107+
exit 1
108+
fi
102109
103110
- name: Install uv
104111
run: |

.pre-commit-hooks/check-schema-sync.sh

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,50 @@
44

55
set -e
66

7-
# Only check if source/ or generate_schemas.py changed
8-
if git diff --cached --name-only | grep -qE "(^source/|^generate_schemas\.py)"; then
7+
# Only check if schema inputs changed
8+
if git diff --cached --name-only | grep -qE "(^source/|^generate_schemas\.py|^schema_utils\.py)"; then
99
echo "Source schemas changed, checking if spec/ needs regeneration..."
1010

11-
# Generate schemas
12-
python generate_schemas.py > /dev/null 2>&1
11+
# Prefer python3, but fall back to python for systems without a python3 shim
12+
if command -v python3 &> /dev/null; then
13+
PYTHON=python3
14+
elif command -v python &> /dev/null; then
15+
PYTHON=python
16+
else
17+
echo "Error: python3 or python not found. Please install Python."
18+
exit 1
19+
fi
20+
21+
# Generate schemas and keep output for debugging
22+
if ! "$PYTHON" generate_schemas.py; then
23+
echo ""
24+
echo "Error: Failed to generate schemas. Please fix errors above."
25+
exit 1
26+
fi
27+
28+
# Check for differences (including untracked files)
29+
if git ls-files --others --exclude-standard spec/ | grep -q .; then
30+
echo ""
31+
echo "Error: spec/ contains untracked generated files"
32+
echo ""
33+
echo "Files that need adding:"
34+
git ls-files --others --exclude-standard spec/
35+
echo ""
36+
echo "Run: $PYTHON generate_schemas.py"
37+
echo "Then stage and commit the updated spec/ files"
38+
exit 1
39+
fi
1340

14-
# Check for differences
41+
# Check for differences in tracked files
1542
if ! git diff --exit-code spec/ > /dev/null 2>&1; then
1643
echo ""
1744
echo "Error: spec/ is out of sync with source/"
1845
echo ""
1946
echo "Files that need updating:"
2047
git diff --name-only spec/
2148
echo ""
22-
echo "Run: python generate_schemas.py"
23-
echo "Then commit the updated spec/ files"
49+
echo "Run: $PYTHON generate_schemas.py"
50+
echo "Then stage and commit the updated spec/ files"
2451
exit 1
2552
fi
2653
fi

0 commit comments

Comments
 (0)