openstack-helm-infra/tools/gate/lint.sh
Andrii Ostapenko 8f24a74bc7 Introduces templates linting
This commit rewrites lint job to make template linting available.
Currently yamllint is run in warning mode against all templates
rendered with default values. Duplicates detected and issues will be
addressed in subsequent commits.

Also all y*ml files are added for linting and corresponding code changes
are made. For non-templates warning rules are disabled to improve
readability. Chart and requirements yamls are also modified in the name
of consistency.

Change-Id: Ife6727c5721a00c65902340d95b7edb0a9c77365
2020-06-11 23:29:42 -05:00

36 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -e
HELM_DATA_YAML=../openstack-helm-infra/roles/build-helm-packages/defaults/main.yml
HELM_VERSION=$(yq -r '.version.helm' ${HELM_DATA_YAML})
GOOGLE_HELM_REPO_URL=$(yq -r '.url.google_helm_repo' ${HELM_DATA_YAML})
LINT_DIR=.yamllint
mkdir ${LINT_DIR}
cp -r * ${LINT_DIR}
rm -rf ${LINT_DIR}/*/templates
rm -rf */charts/helm-toolkit
wget -qO ${LINT_DIR}/helm.tgz ${GOOGLE_HELM_REPO_URL}/helm-${HELM_VERSION}-linux-amd64.tar.gz
tar xzf ${LINT_DIR}/helm.tgz -C ${LINT_DIR} --strip-components=1 linux-amd64/helm
for i in */; do
# avoid helm-toolkit to symlink on itself
[ -d "$i/templates" -a "$i" != "helm-toolkit/" ] || continue
mkdir -p $i/charts
ln -s ../../../openstack-helm-infra/helm-toolkit $i/charts/helm-toolkit
${LINT_DIR}/helm template $i --output-dir ${LINT_DIR} 2>&1 > /dev/null
done
rm -rf */charts/helm-toolkit
find .yamllint -type f -exec sed -i 's/%%%.*/XXX/g' {} +
set +e
shopt -s globstar extglob
# lint all y*mls except for templates with the first config
yamllint -c yamllint.conf ${LINT_DIR}/*{,/!(templates)/**}/*.y*ml yamllint*.conf
result=$?
# lint templates with the second config
yamllint -c yamllint-templates.conf ${LINT_DIR}/*/templates/*.yaml
exit $(($?|$result))