Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajout du préfixe "v" devant le numéro de version + intégration de "checks" automatisés #58

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/assert_version.py
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import json
import re
import os

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


def check(obj, version, parents=''):
"""
This functions recursively parses all fields in the schema looking for
version names that would not be the same as the one mentionned
in the 'version' field
"""
errors = []
# if field is a string, we check for a potential version
if isinstance(obj, str):
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):
errors += check(
k,
version,
parents=parents + f'[{str(idx)}]'
)
# if field is a dict, we check every value
elif isinstance(obj, dict):
for k in obj:
# not checking the fields
if k != 'fields':
errors += check(
obj[k],
version,
parents=parents + '.' + k if parents else k
)
return errors


to_check = []

if 'schema.json' in os.listdir():
to_check.append('schema.json')

elif 'datapackage.json' in os.listdir():
with open('datapackage.json', 'r') as f:
datapackage = json.load(f)
for r in datapackage['resources']:
to_check.append(r['schema'])

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

message = ''
for schema_path in to_check:
with open(schema_path, 'r') as f:
schema = json.load(f)
homepage = schema['homepage']
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
version = schema['version']

Pierlou marked this conversation as resolved.
Show resolved Hide resolved
errors = check(schema, version)
if errors:
if message:
message += '\n\n'
message += (
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]}'"
if message:
raise Exception(message)
19 changes: 19 additions & 0 deletions .github/workflows/assert_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Vérification de la cohérence 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

- run: python3 .github/workflows/assert_version.py
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion dynamique/schema-dynamique.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"created": "2022-10-28",
"lastModified": "2024-01-16",
"version": "2.3.0",
"version": "v2.3.0",
"contributors": [
{
"title": "Geoffrey Aldebert",
Expand Down
2 changes: 1 addition & 1 deletion statique/schema-statique.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
],
"created": "2018-06-29",
"lastModified": "2022-10-10",
"version": "2.3.0",
"version": "v2.3.0",
"contributors": [
{
"title": "Alexandre Bulté",
Expand Down
Loading