Skip to content

Commit

Permalink
ci(json-schema-check): improve readibility and output helpful debug i…
Browse files Browse the repository at this point in the history
…nfo (#285)

Signed-off-by: M. Fatih Cırıt <[email protected]>
  • Loading branch information
xmfcx authored Feb 21, 2024
1 parent 48faad7 commit 39f6110
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
10 changes: 4 additions & 6 deletions json-schema-check/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ description: ""
runs:
using: composite
steps:
- name: Install JSON Schema packages
run: |
pip3 install -U check-jsonschema
- name: Install dependencies
run: pip install check-jsonschema colorama
shell: bash

- name: Check configuration files
run: |
find -wholename '*/schema/*.schema.json' -printf '%p: ' -execdir bash -c 'check-jsonschema --schemafile "$1" ../config/"${1:2:-12}"*.param.yaml' bash '{}' +
- name: Validate schemas
run: python ${GITHUB_ACTION_PATH}/validate_json_schemas.py
shell: bash
49 changes: 49 additions & 0 deletions json-schema-check/validate_json_schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import subprocess
import glob
import colorama

colorama.init(autoreset=True, strip=False)

def main():
validation_failed = False

for schema_path in glob.glob('./**/schema/*.schema.json', recursive=True):
schema_file = os.path.relpath(schema_path, './')
base_name = os.path.basename(schema_file).replace('.schema.json', '')
config_dir = os.path.dirname(schema_file).replace('schema', 'config')

str_indentation = ' ' * 4
config_files = glob.glob(f'{config_dir}/{base_name}*.param.yaml')
if not config_files:
print(colorama.Fore.YELLOW + f'{str_indentation}No configuration files found for schema {schema_file}.')
continue

for config_file in config_files:
print(
colorama.Style.BRIGHT + '🔍 Validating: ' +
colorama.Style.RESET_ALL +
colorama.Fore.CYAN + f'{config_file} ' +
colorama.Style.RESET_ALL + '🆚 ' +
colorama.Fore.BLUE + f'{schema_file}' +
colorama.Style.RESET_ALL,
end=' '
)
result = subprocess.run(['check-jsonschema', '--schemafile', schema_file, config_file], capture_output=True)
if result.returncode != 0:
print(colorama.Fore.RED + '❌ Failed')
for line in result.stdout.decode('utf-8').split('\n'):
if line:
print(colorama.Fore.RED + str_indentation + line)
validation_failed = True
else:
print(colorama.Fore.GREEN + '✅ Passed')

if validation_failed:
print(colorama.Style.BRIGHT + colorama.Fore.RED + '❗ Validation failed for one or more files.')
exit(1)
else:
print(colorama.Style.BRIGHT + colorama.Fore.GREEN + '✔️ All validations passed successfully.')

if __name__ == "__main__":
main()

0 comments on commit 39f6110

Please sign in to comment.