Skip to content

Commit

Permalink
Add new CI validation: ensure files exist
Browse files Browse the repository at this point in the history
Since we now ensure the automation schema is valid, we also want to
ensure linked directories and files exist in the various automation
scenarios.

This new script will load any YAML file nested in the automation/vars
directory, and ensures all the `path` and `src_file` are present.
  • Loading branch information
cjeanner committed Apr 4, 2024
1 parent 107dd5d commit a3011bf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .ci/validate-schema-paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

import glob
import pathlib
import yaml


class TestSchema():
def __init__(self, automation_dir):
cur_path = pathlib.Path(__file__).parent

self.__autodir = automation_dir
self.__src_dir = pathlib.Path(cur_path, '../', self.__autodir)
self.__files = self.__src_dir.glob('*.yaml')

def run(self):
for f in self.__files:
self.__run_file(f)

def __run_file(self, f):
rel = pathlib.Path(self.__autodir, f.name)
print(f'Checking scenario file: {rel}')
with open(f, 'r') as fh:
content = yaml.safe_load(fh)
for scenario in content['vas']:
print(f' Checking scenario: {scenario}')
self.__validate(content['vas'][scenario])

def __validate(self, scenario):
for stage in scenario['stages']:
_path = stage['path']
print(f' Checking path: {_path}', end=' ')
source = pathlib.Path(_path)
assert source.exists(), f'!! {source} does not exist'
assert source.is_dir(), f'!! {source} is not a directory'
print('[OK]')
for val in stage['values']:
f = val['src_file']
_path = source / f
print(f' Checking source file: {_path}', end=' ')
assert _path.is_file(), f'!! {_path} does not exist'
print('[OK]')

if __name__ == '__main__':
test = TestSchema('./automation/vars')
test.run()
16 changes: 16 additions & 0 deletions .github/workflows/automation-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ jobs:

- name: Run yamale
run: yamale -s .ci/automation-schema.yaml automation/vars/

files_exist:
runs-on: ubuntu-latest
needs: # Ensure schema is valid before reading it
- yamale
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Run file checker
run: python3 .ci/validate-schema-paths.py

0 comments on commit a3011bf

Please sign in to comment.