diff --git a/.github/workflows/assert_version.yml b/.github/workflows/assert_version.yml new file mode 100644 index 0000000..fc64170 --- /dev/null +++ b/.github/workflows/assert_version.yml @@ -0,0 +1,60 @@ +name: Assert version is the same across schema + +on: + push: + branches: master + pull_request: + branches: master + +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 + + - name: Install dependencies + run: | + pip install json + pip install re + + - 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) + \ No newline at end of file