diff --git a/.github/workflows/assert_version.py b/.github/workflows/assert_version.py new file mode 100755 index 0000000..496b15e --- /dev/null +++ b/.github/workflows/assert_version.py @@ -0,0 +1,64 @@ +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") + +for schema_path in to_check: + with open(schema_path, "r") as f: + schema = json.load(f) + version = schema["version"] + + errors = check(schema, version) + if errors: + 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]}'" + raise Exception(message) diff --git a/.github/workflows/assert_version.yml b/.github/workflows/assert_version.yml new file mode 100644 index 0000000..2bd821e --- /dev/null +++ b/.github/workflows/assert_version.yml @@ -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@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - run: python .github/workflows/assert_version.py diff --git a/.github/workflows/check_validity.yml b/.github/workflows/check_validity.yml deleted file mode 100644 index 131464f..0000000 --- a/.github/workflows/check_validity.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Vérification du respect des spécifications - -on: - push: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Installation Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: '3.7' - - name: Cache pip - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- - - name: Installation des dépendances - run: pip install -r requirements.txt - - name: Vérification du schéma et des fichiers d'exemples - run: | - frictionless validate datapackage.json diff --git a/.github/workflows/frictionless_tests.yml b/.github/workflows/frictionless_tests.yml new file mode 100644 index 0000000..739ba3c --- /dev/null +++ b/.github/workflows/frictionless_tests.yml @@ -0,0 +1,34 @@ +name: Vérification du respect des spécifications + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Installation des dépendances + run: pip install -r requirements.txt + - name: Vérification du schéma lave-linge et des fichiers d'exemples associés + run: | + frictionless validate --type schema lave-linge/schema.json + frictionless validate --schema lave-linge/schema.json lave-linge/exemple-valide.csv + - name: Vérification du schéma televiseur et des fichiers d'exemples associés + run: | + frictionless validate --type schema televiseur/schema.json + frictionless validate --schema televiseur/schema.json televiseur/exemple-valide.csv + - name: Vérification du datapackage + run: | + frictionless validate datapackage.json \ No newline at end of file