mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
yamllint: Lint all the YAML files
For now, a list of YAML files' paths is hardcoded (even after globbing) into Makefile.am. Moreover, Azure templates are not checked at all until Azure triggered. With this change, the list of YAMLs is populated automatically on yamllinting. Jinja templates are not parseable by a regular yaml module, to skip such the YAML_TEMPLATE_FILES is utilized. Fixes: https://pagure.io/freeipa/issue/8202 Signed-off-by: Stanislav Levin <slev@altlinux.org> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
committed by
Alexander Bokovoy
parent
b82515562a
commit
fa104daf77
35
Makefile.am
35
Makefile.am
@@ -275,16 +275,33 @@ polint:
|
||||
rpmlint: freeipa.spec
|
||||
rpmlint ./$<
|
||||
|
||||
YAML_FILES = \
|
||||
$(top_srcdir)/.lgtm.yml \
|
||||
$(wildcard $(top_srcdir)/.*.yaml) \
|
||||
$(wildcard $(top_srcdir)/ipatests/prci_definitions/*.yaml)
|
||||
|
||||
# Try to load yml/yaml files via safe_load, which recognizes only standard
|
||||
# YAML tags and cannot construct an arbitrary Python object.
|
||||
# There are Jinja yaml templates, which differ from reqular ones. These
|
||||
# files should be placed on skip list (YAML_TEMPLATE_FILES), otherwise
|
||||
# safe_load fails.
|
||||
.PHONY: yamllint
|
||||
yamllint: $(YAML_FILES)
|
||||
@for YAML in $^; do \
|
||||
$(PYTHON) -c "import yaml; f = open('$${YAML}'); yaml.safe_load(f); f.close()" || exit 1; \
|
||||
done
|
||||
yamllint:
|
||||
YAML_TEMPLATE_FILES="\
|
||||
$(top_srcdir)/ipatests/azure/templates/ipa-test-config-template.yaml \
|
||||
"; \
|
||||
echo "jinja template files:"; \
|
||||
for YAML in $${YAML_TEMPLATE_FILES}; do \
|
||||
echo $${YAML}; \
|
||||
$(PYTHON) -c "import yaml; f = open('$${YAML}'); yaml.safe_load(f); f.close()" >/dev/null 2>&1 \
|
||||
&& { echo Unexpected PASS of parsing yaml: $${YAML}. This file is a regular yaml.; exit 1; }; \
|
||||
done; \
|
||||
YAML_FILES=`find $(top_srcdir) \
|
||||
\( -name '*.yaml' -o \
|
||||
-name '*.yml' \) \
|
||||
$$(printf '! -path %s ' $${YAML_TEMPLATE_FILES})`; \
|
||||
echo -e "\nlint yaml files"; \
|
||||
echo "-----------"; \
|
||||
for YAML in $${YAML_FILES}; do \
|
||||
echo $${YAML}; \
|
||||
$(PYTHON) -c "import yaml; f = open('$${YAML}'); yaml.safe_load(f); f.close()" || { echo Your YAML file: $${YAML} has a wrong syntax or this is a Jinja template. In the latter clause, consider to add your YAML file to the YAML_TEMPLATE_FILES list in Makefile.am.; exit 1; } \
|
||||
done; \
|
||||
echo "-----------"
|
||||
|
||||
# Run pylint for all python files. Finds all python files/packages, skips
|
||||
# folders rpmbuild, freeipa-* and dist. Skip (match, but don't print) .*,
|
||||
|
||||
Reference in New Issue
Block a user