-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
M. Fatih Cırıt
committed
Feb 20, 2024
1 parent
c8ecf5f
commit 502878a
Showing
2 changed files
with
51 additions
and
44 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
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,48 @@ | ||
import os | ||
import subprocess | ||
import glob | ||
import colorama | ||
|
||
# Initialize colorama to auto-reset colors | ||
colorama.init(autoreset=True) | ||
|
||
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') | ||
|
||
config_files = glob.glob(f'{config_dir}/{base_name}*.param.yaml') | ||
if not config_files: | ||
print(colorama.Fore.YELLOW + f'No configuration files found for schema {schema_file}.') | ||
continue | ||
|
||
for config_file in config_files: | ||
# Customized print statement with different colors | ||
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') | ||
print(colorama.Fore.RED + result.stdout.decode('utf-8')) | ||
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() |