feat/metadata-schema-validation #165

Merged
unkinben merged 4 commits from feat/metadata-schema-validation into master 2026-05-17 12:34:33 +10:00
3 changed files with 39 additions and 0 deletions
Showing only changes of commit db5a829429 - Show all commits
+1
View File
@@ -47,6 +47,7 @@ repos:
name: Validate RPM package metadata
files: ^rpms/[^/]+/metadata\.yaml$
args: [--schemafile, schema/metadata.json]
language_version: python3.11
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.7
+2
View File
@@ -6,4 +6,6 @@ requires-python = ">=3.11"
[dependency-groups]
dev = [
"pytest>=8",
"jsonschema>=4",
"pyyaml>=6",
]
+36
View File
@@ -0,0 +1,36 @@
"""Validate every rpms/*/metadata.yaml against schema/metadata.json."""
import json
from pathlib import Path
import jsonschema
import pytest
import yaml
REPO_ROOT = Path(__file__).parent.parent
SCHEMA_FILE = REPO_ROOT / "schema" / "metadata.json"
RPMS_DIR = REPO_ROOT / "rpms"
@pytest.fixture(scope="session")
def schema():
with open(SCHEMA_FILE) as f:
return json.load(f)
def metadata_files():
return sorted(RPMS_DIR.glob("*/metadata.yaml"))
@pytest.mark.parametrize("metadata_file", metadata_files(), ids=lambda p: p.parent.name)
def test_metadata_valid(metadata_file, schema):
with open(metadata_file) as f:
data = yaml.safe_load(f)
validator = jsonschema.Draft7Validator(schema)
errors = sorted(validator.iter_errors(data), key=str)
assert not errors, "\n".join(
f" {'.'.join(str(p) for p in e.absolute_path) or '(root)'}: {e.message}"
for e in errors
)