diff --git a/openstack_governance/_check_schema.py b/openstack_governance/_check_schema.py new file mode 100644 index 000000000..eb479eec9 --- /dev/null +++ b/openstack_governance/_check_schema.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""Verify that all data files match the schema.""" + +import argparse +import pkgutil + +import jsonschema + +from openstack_governance import yamltools + + +_yaml = yamltools.YAML() + +_PROJECTS_SCHEMA = _yaml.load( + pkgutil.get_data('openstack_governance', + 'projects_schema.yaml').decode('utf-8') +) + + +def main(): + parser = argparse.ArgumentParser() + parser.parse_args() + + errors = [] + + with open('reference/projects.yaml', 'r', encoding='utf-8') as f: + all_projects = _yaml.load(f.read()) + + validator = jsonschema.Draft4Validator(_PROJECTS_SCHEMA) + + errors = False + for e in validator.iter_errors(all_projects): + errors = True + print(e) + + return 1 if errors else 0 diff --git a/openstack_governance/projects_schema.yaml b/openstack_governance/projects_schema.yaml new file mode 100644 index 000000000..9773c6faf --- /dev/null +++ b/openstack_governance/projects_schema.yaml @@ -0,0 +1,95 @@ +--- +$schema: "http://json-schema.org/schema#" +$id: "https://opendev.org/openstack/releases/src/branch/master/README.rst" + + +additionalProperties: + # Do not allow any properties not defined here. This lets us catch + # typos. + additionalProperties: false + required: + - ptl + - deliverables + properties: + ptl: + type: "object" + required: + - name + - email + additionalProperties: false + properties: + name: + type: "string" + irc: + type: "string" + email: + type: "string" + format: "email" + appointed: + type: "array" + items: + type: "string" + irc-channel: + type: "string" + service: + type: "string" + url: + type: "string" + liaisons: + type: "array" + uniqueItems: true + items: + type: "string" + mission: + type: "string" + deliverables: + type: "object" + additionalProperties: + type: "object" + required: + - repos + additionalProperties: false + properties: + repos: + type: "array" + items: + type: "string" + pattern: "^[^/]+/[^/]+$" + minItems: 1 + uniqueItems: true + tags: + type: "array" + items: + type: "string" + release-management: + type: "string" + enum: + - none + - deprecated + - external + tags: + type: "array" + items: + type: "string" + extra-atcs: + type: "array" + items: + type: "object" + required: + - name + - email + - expires-in + additionalProperties: false + properties: + name: + type: "string" + email: + type: "string" + format: "email" + expires-in: + type: "string" + pattern: >- + ^(January |February |March |April |May |June |July |August + |September |October |November |December )2[0-9]{3}$ + comment: + type: "string" diff --git a/requirements.txt b/requirements.txt index 077beb729..8dddd4d07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ PyYAML>=3.1.0 six>=1.9.0 yamlordereddictloader mwclient==0.8.1 -ruamel.yaml \ No newline at end of file +ruamel.yaml +jsonschema>=2.6.0 diff --git a/setup.cfg b/setup.cfg index e7a78b9f3..b569f516d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,4 +22,8 @@ warning-is-error = 1 warnerrors = True [flake8] -ignore = E501,E226,H405 \ No newline at end of file +ignore = E501,E226,H405 + +[entry_points] +console_scripts = + osg-check-schema = openstack_governance._check_schema:main diff --git a/tox.ini b/tox.ini index c9d365f0b..b7c1daacf 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,7 @@ commands = basepython = python3 whitelist_externals = bash commands = + osg-check-schema bash -c "find {toxinidir} \ \( -name .tox -prune \) \ -o -type f -name '*.yaml' \