Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/scripts/validate_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""Validate that all JSON files under the schema directory are well-formed."""

import json
import sys
from pathlib import Path


def validate_json_files(schema_dir: str) -> int:
"""Validate every *.json file found under schema_dir.

Returns 0 if all files are valid, 1 if any file is invalid.
"""
has_error = False
json_files = sorted(Path(schema_dir).rglob("*.json"))

if not json_files:
print(f"No JSON files found under '{schema_dir}'.")
return 0

for filepath in json_files:
try:
with open(filepath, encoding="utf-8") as f:
json.load(f)
print(f"VALID: {filepath}")
except (json.JSONDecodeError, OSError, UnicodeDecodeError) as exc:
print(f"INVALID: {filepath} — {exc}", file=sys.stderr)
has_error = True

return 1 if has_error else 0


if __name__ == "__main__":
directory = sys.argv[1] if len(sys.argv) > 1 else "schema"
sys.exit(validate_json_files(directory))
20 changes: 20 additions & 0 deletions .github/workflows/validate-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Validate JSON Schema Files

on:
pull_request:
paths:
- 'schema/**'
Comment thread
rajeshsindhu marked this conversation as resolved.
- '.github/scripts/validate_json.py'
- '.github/workflows/validate-json.yml'

jobs:
validate-json:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Validate JSON files in schema directory
run: python3 .github/scripts/validate_json.py schema