Skip to content

Commit

Permalink
refactor: adapt feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierlou committed Feb 29, 2024
1 parent 1db395d commit c94c331
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/assert_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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)}]')
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 = (
"Errors are mismatched within the schema, "
f"expected version {version} but:"
)
for e in errors:
message += f'\n- {e[0]} has version {e[1]}'
raise Exception(message)
35 changes: 1 addition & 34 deletions .github/workflows/assert_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,5 @@ jobs:
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)
- run: python3 .github/workflows/assert_version.py

0 comments on commit c94c331

Please sign in to comment.