Skip to content

Commit

Permalink
Merge pull request #164 from cjeanner/automation/validate-files
Browse files Browse the repository at this point in the history
Add new CI validation: ensure files exist
  • Loading branch information
abays authored Apr 5, 2024
2 parents 107dd5d + 60430f9 commit 25198d1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
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()
21 changes: 20 additions & 1 deletion .github/workflows/automation-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: # yamllint disable-line rule:truthy
- main
- stable
paths:
- ".ci/automation-schema.yaml"
- ".ci/*"
- "automation/vars/*.yaml"
- "automation/vars/*.yml"

Expand All @@ -27,3 +27,22 @@ 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: Install pyyaml
run: pip install pyyaml

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

0 comments on commit 25198d1

Please sign in to comment.