ci/validate: Also validate Zuul YAML config

This commit is contained in:
Timothée Ravier 2024-03-01 19:51:34 +01:00
parent 44ba47cd29
commit 97c49fdb16

View file

@ -22,17 +22,16 @@ def validate_shell(rootfd, name):
for root, dirs, files, rootfd in os.fwalk('.'): for root, dirs, files, rootfd in os.fwalk('.'):
# Skip .git, repo, cache, tmp, logs, fedora-comps # Skip .git, repo, cache, tmp, logs, fedora-comps
for d in ['.git', 'repo', 'cache', 'tmp', 'logs', 'fedora-comps', 'ci']: for d in ['.git', 'repo', 'cache', 'tmp', 'logs', 'fedora-comps']:
if d in dirs: if d in dirs:
dirs.remove(d) dirs.remove(d)
for name in files: for name in files:
if name == ".zuul.yaml":
continue
if name.endswith(('.yaml', '.yml')): if name.endswith(('.yaml', '.yml')):
print("Validating:", name) print("Validating:", name)
with open(os.open(name, dir_fd=rootfd, flags=os.O_RDONLY)) as f: with open(os.open(name, dir_fd=rootfd, flags=os.O_RDONLY)) as f:
yaml.safe_load(f) yaml.safe_load(f)
result = subprocess.run(['grep', '-RniEv', '^( )*[a-z#/-]|^$|^#', name], encoding='UTF-8') result = subprocess.run(['grep', '-RniEv', '^( )*[a-z#/-]|^$|^#', name], encoding='UTF-8',
preexec_fn=lambda: os.fchdir(rootfd))
if result.returncode == 0: if result.returncode == 0:
raise Exception("Found likely invalid indentation in YAML file: {}".format(name)) raise Exception("Found likely invalid indentation in YAML file: {}".format(name))
validated +=1 validated +=1
@ -47,7 +46,7 @@ for root, dirs, files, rootfd in os.fwalk('.'):
if not stbuf.st_mode & stat.S_IXUSR: if not stbuf.st_mode & stat.S_IXUSR:
continue continue
mimetype = subprocess.check_output(['file', '-b', '--mime-type', name], encoding='UTF-8', mimetype = subprocess.check_output(['file', '-b', '--mime-type', name], encoding='UTF-8',
preexec_fn=lambda: os.fchdir(rootfd)).strip() preexec_fn=lambda: os.fchdir(rootfd)).strip()
if mimetype == 'text/x-shellscript': if mimetype == 'text/x-shellscript':
print("Validating:", name) print("Validating:", name)
validate_shell(rootfd, name) validate_shell(rootfd, name)