-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add workflow to check version consistency
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||