cloud-infra: Enable non-voting yamllint job for yaml files 17/3217/2
authorFatih Degirmenci <fdegir@gmail.com>
Tue, 17 Dec 2019 16:33:19 +0000 (17:33 +0100)
committerFatih Degirmenci <fdegir@gmail.com>
Tue, 17 Dec 2019 16:36:31 +0000 (17:36 +0100)
Change-Id: Ifcee6c7f33f1ba95fcac54f9b9dc57e5fbd6fef2

jjb/cloud-infra/cloud-infra-engine-verify-lint.yaml
jjb/cloud-infra/cloud-infra-macros.yaml
jjb/cloud-infra/scripts/cloud-infra-ansible-lint.sh
jjb/cloud-infra/scripts/cloud-infra-yaml-lint.sh [new file with mode: 0644]

index f6b4a5442cf8a649252e95f43bd0891e1a9f5f6f..01f3c42ef6112dadc7bd40b7ca71e937e89c337d 100644 (file)
           failed: false
           unstable: false
           notbuilt: false
+      - yaml-lint:
+          successful: true
+          failed: true
+          unstable: true
+          notbuilt: true
       - shellcheck:
           successful: true
           failed: true
index 6d90afe06e32db67ec59d384c402b5cee8bff2c4..17a2fb973e08c10695bc350877f1cd30f4915bae 100644 (file)
       - shell:
           !include-raw: ./scripts/cloud-infra-ansible-lint.sh
 
+- builder:
+    name: 'cloud-infra-yaml-lint-macro'
+    builders:
+      - shell:
+          !include-raw: ./scripts/cloud-infra-yaml-lint.sh
+
 - builder:
     name: 'cloud-infra-shellcheck-macro'
     builders:
index 1de5601d7826592289edd4717d6edba5fbd707f0..03f32ee63eea51737a6fced1c30d6758d0f31914 100644 (file)
@@ -27,7 +27,7 @@ sudo apt update > /dev/null 2>&1
 sudo apt install -y -q=3 gcc libffi-dev libssl-dev lsb-release libpython3-dev \
     python3-minimal python3-pip python3-yaml virtualenv > /dev/null 2>&1
 
-# override ENGINE_ANSIBLE_LINT_VERSION locally before bumping it in engine
+# override ENGINE_ANSIBLE_LINT_VERSION locally while ansible-lint patch is still open
 export ENGINE_ANSIBLE_LINT_VERSION=4.1.0
 
 cd $WORKSPACE
diff --git a/jjb/cloud-infra/scripts/cloud-infra-yaml-lint.sh b/jjb/cloud-infra/scripts/cloud-infra-yaml-lint.sh
new file mode 100644 (file)
index 0000000..c0f2577
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/bash
+
+# ============LICENSE_START=======================================================
+#  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+# ============LICENSE_END=========================================================
+
+# source engine-vars.sh so we can install the correct versions of
+# pip, ansible, and ansible-lint
+source $WORKSPACE/engine/config/engine-vars.sh
+
+# install dependencies
+sudo apt update > /dev/null 2>&1
+sudo apt install -y -q=3 gcc libffi-dev libssl-dev lsb-release libpython3-dev \
+    python3-minimal python3-pip python3-yaml virtualenv > /dev/null 2>&1
+
+# override ENGINE_YAML_LINT_VERSION locally while yamllint patch is still open
+export ENGINE_YAML_LINT_VERSION=1.19.0
+
+cd $WORKSPACE
+echo "Info: Install pip==$ENGINE_PIP_VERSION ansible==$ENGINE_ANSIBLE_VERSION and yamllint==$ENGINE_YAML_LINT_VERSION"
+echo "----------------------------------------------------"
+
+# install pip, ansible, and yamllint in venv
+export ANSIBLE_VENV=$WORKSPACE/.venv
+virtualenv -p python3 --quiet --no-site-packages ${ANSIBLE_VENV}
+source ${ANSIBLE_VENV}/bin/activate
+pip -q install --upgrade pip==$ENGINE_PIP_VERSION
+pip -q install --upgrade virtualenv pip setuptools shade \
+    ansible==$ENGINE_ANSIBLE_VERSION yamllint==$ENGINE_YAML_LINT_VERSION
+
+echo "----------------------------------------------------"
+echo "Info: Done"
+echo "Info: Run yamllint on yaml files"
+echo "----------------------------------------------------"
+
+# set exit_code so we exit ourselves rather than ansible-lint bailing out without
+# verifying all the yaml files
+declare -i exit_code=0
+
+# lint the yaml files
+cd $WORKSPACE/engine
+for yaml_file in $(find . -type f -name *.yml | sort); do
+  echo "--> Checking '${yaml_file}' yaml file..."
+  yamllint --format standard --strict ${yaml_file}
+  lint_exit_code=$?
+  if [[ $lint_exit_code != 0 ]]; then
+    exit_code=$lint_exit_code
+  else
+    echo [OK]
+  fi
+  echo
+done
+echo "----------------------------------------------------"
+echo "Info: Done"
+exit $exit_code
+
+# vim: set ts=2 sw=2 expandtab: