Skip to content

Commit

Permalink
fix: fix pattern and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierlou committed Mar 11, 2024
1 parent b503546 commit 8a9fdbb
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/assert_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
import os

pattern = r'v?\d+\.\d+\.\d+'


def check(obj, version, parents=''):
"""
Expand All @@ -12,10 +14,9 @@ def check(obj, version, parents=''):
errors = []
# if field is a string, we check for a potential version
if isinstance(obj, str):
if homepage in obj:
tmp = re.search(pattern, obj)
if tmp and tmp[0] != version:
errors += [(parents, tmp[0])]
tmp = re.search(pattern, obj)
if tmp and tmp[0] != version:
errors += [(parents, tmp[0])]
# if field is a list, we check every item
elif isinstance(obj, list):
for idx, k in enumerate(obj):
Expand All @@ -27,11 +28,13 @@ def check(obj, version, parents=''):
# if field is a dict, we check every value
elif isinstance(obj, dict):
for k in obj:
errors += check(
obj[k],
version,
parents=parents + '.' + k if parents else k
)
# not checking the fields
if k != 'fields':
errors += check(
obj[k],
version,
parents=parents + '.' + k if parents else k
)
return errors


Expand All @@ -46,19 +49,21 @@ def check(obj, version, parents=''):
for r in datapackage['resources']:
to_check.append(r['schema'])

else:
raise Exception('No required file found')

for schema_path in to_check:
with open(schema_path, 'r') as f:
schema = json.load(f)
pattern = r'v\d+.\d+.\d+'
homepage = schema['homepage']
version = schema['version']

errors = check(schema, version)
if errors:
message = (
f"Errors are mismatched within the schema '{schema}', "
f"expected version {version} but:"
f"Versions are mismatched within the schema '{schema['name']}', "
f"expected version '{version}' but:"
)
for e in errors:
message += f'\n- {e[0]} has version {e[1]}'
message += f"\n- {e[0]} has version '{e[1]}'"
raise Exception(message)

0 comments on commit 8a9fdbb

Please sign in to comment.