Vérification de la cohérénce des versions dans tous les champs du schéma #6
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Vérification de la cohérénce des versions dans tous les champs du schéma | |
on: | |
push: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.8 | |
- uses: jannekem/run-python-script-action@v1 | |
id: script | |
with: | |
fail-on-error: true | |
script: | | |
import json | |
import re | |
with open('schema.json', 'r') as f: | |
schema = json.load(f) | |
pattern = r'v\d+.\d+.\d+' | |
homepage = schema['homepage'] | |
version = schema['version'] | |
def check(obj, parents=''): | |
errors = [] | |
if isinstance(obj, str): | |
if homepage in obj: | |
tmp = re.search(pattern, obj) | |
if tmp and tmp[0] != version: | |
errors += [(parents, tmp[0])] | |
elif isinstance(obj, list): | |
for idx, k in enumerate(obj): | |
errors += check(k, parents=parents + f'[{str(idx)}]' if parents else f'[{str(idx)}]') | |
elif isinstance(obj, dict): | |
for k in obj: | |
errors += check(obj[k], parents=parents + '.' + k if parents else k) | |
return errors | |
errors = check(schema) | |
if errors: | |
message = f"Errors are mismatched within the schema, expected version {version} but:" | |
for e in errors: | |
message += f'\n- {e[0]} has version {e[1]}' | |
raise ReferenceError(message) |