diff --git a/.github/workflows/validate_modified_targets.yml b/.github/workflows/validate_modified_targets.yml index bb2445117..bff13ee59 100644 --- a/.github/workflows/validate_modified_targets.yml +++ b/.github/workflows/validate_modified_targets.yml @@ -47,6 +47,7 @@ jobs: # Safely extract the file from the PR's head and the merge-base commit git show pr:sherlock_project/resources/data.json > data.json.head git show $MERGE_BASE:sherlock_project/resources/data.json > data.json.base + git show $MERGE_BASE:sherlock_project/resources/data.schema.json > data.schema.json.base # CRITICAL FIX: Overwrite the checked-out data.json with the one from the PR # This ensures that pytest runs against the new, updated file. @@ -59,15 +60,25 @@ jobs: python - <<'EOF' import json import sys + from jsonschema import validate, SchemaError, ValidationError try: with open("data.json.base") as f: base = json.load(f) + with open("data.schema.json.base") as f: schema = json.load(f) with open("data.json.head") as f: head = json.load(f) + + validate(instance=head, schema=schema) except FileNotFoundError as e: print(f"Error: Could not find {e.filename}", file=sys.stderr) sys.exit(1) except json.JSONDecodeError as e: print(f"Error: Could not decode JSON from a file - {e}", file=sys.stderr) sys.exit(1) + except jsonschema.exceptions.SchemaError as e: + print(f"Error: Could not locate local JSON schema for validation - {e}", file=sys.stderr) + sys.exit(1) + except jsonschema.exceptions.ValidationError as e: + print(f"Error: Could not validate remote manifest against local schema - {e}", file=sys.stderr) + sys.exit(1) changed = [] for k, v in head.items():