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

feat: add workflow to check version consistency #8

Merged
merged 12 commits into from
Apr 4, 2024
53 changes: 53 additions & 0 deletions .github/workflows/assert_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
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)}]')
Pierlou marked this conversation as resolved.
Show resolved Hide resolved
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)
Pierlou marked this conversation as resolved.
Show resolved Hide resolved

File renamed without changes.
6 changes: 3 additions & 3 deletions exemple-valide.csv
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,date_creation,nom,classification
42,2020-02-27,Brouette,"[""Classification A""]"
44,2020-02-25,Pelle,"[""Classification A"",""Classification B"",""Classification C""]"
45,2020-02-25,Bus,"[""Classification A"",""Classification C""]"
42,2020-02-27,Brouette,Classification A
44,2020-02-25,Pelle,Classification C
45,2020-02-25,Bus,Classification A
8 changes: 4 additions & 4 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
],
"countryCode":"FR",
"homepage":"https://github.com/mon-orga/schema-objets-importants",
"path":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.1/schema.json",
"image":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.1/irve.png",
"path":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.0/schema.json",
"image":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.0/irve.png",
"licenses":[
{
"title":"Etalab Licence Ouverte 2.0",
Expand All @@ -22,7 +22,7 @@
{
"title":"Fichier valide (CSV)",
"name":"exemple-valide-csv",
"path":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.1/exemple-valide.csv"
"path":"https://github.com/mon-orga/schema-objets-importants/raw/v0.1.0/exemple-valide.csv"
}
],
"sources":[
Expand All @@ -33,7 +33,7 @@
],
"created":"2018-06-29",
"lastModified":"2019-05-06",
"version":"0.1.1",
"version":"v0.1.0",
"contributors":[
{
"title":"John Smith",
Expand Down
Loading