openstack-helm-infra/tools/gate/lint.sh
Andrii Ostapenko dfb32ccf60 Enable yamllint rules for templates
- braces
- brackets
- colons
- commas
- comments
- comments-indentation
- document-start
- hyphens
- indentation

With corresponding code changes.

Also idempotency fix for lint script.

Change-Id: Ibe5281cbb4ad7970e92f3d1f921abb1efc89dc3b
2020-06-17 13:13:53 -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
rm -rf */charts/helm-toolkit
mkdir ${LINT_DIR}
cp -r * ${LINT_DIR}
rm -rf ${LINT_DIR}/*/templates
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))