Skip to content

Commit

Permalink
feat: add workflow to check version consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierlou committed Feb 21, 2024
1 parent 3e3fdb2 commit b48d977
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/assert_version.yml
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)

0 comments on commit b48d977

Please sign in to comment.