cloud-infra: Enable non-voting yamllint job for yaml files
[infra/cicd.git] / jjb / cloud-infra / scripts / cloud-infra-yaml-lint.sh
1 #!/bin/bash
2
3 # ============LICENSE_START=======================================================
4 #  Copyright (C) 2019 The Nordix Foundation. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20
21 # source engine-vars.sh so we can install the correct versions of
22 # pip, ansible, and ansible-lint
23 source $WORKSPACE/engine/config/engine-vars.sh
24
25 # install dependencies
26 sudo apt update > /dev/null 2>&1
27 sudo apt install -y -q=3 gcc libffi-dev libssl-dev lsb-release libpython3-dev \
28     python3-minimal python3-pip python3-yaml virtualenv > /dev/null 2>&1
29
30 # override ENGINE_YAML_LINT_VERSION locally while yamllint patch is still open
31 export ENGINE_YAML_LINT_VERSION=1.19.0
32
33 cd $WORKSPACE
34 echo "Info: Install pip==$ENGINE_PIP_VERSION ansible==$ENGINE_ANSIBLE_VERSION and yamllint==$ENGINE_YAML_LINT_VERSION"
35 echo "----------------------------------------------------"
36
37 # install pip, ansible, and yamllint in venv
38 export ANSIBLE_VENV=$WORKSPACE/.venv
39 virtualenv -p python3 --quiet --no-site-packages ${ANSIBLE_VENV}
40 source ${ANSIBLE_VENV}/bin/activate
41 pip -q install --upgrade pip==$ENGINE_PIP_VERSION
42 pip -q install --upgrade virtualenv pip setuptools shade \
43     ansible==$ENGINE_ANSIBLE_VERSION yamllint==$ENGINE_YAML_LINT_VERSION
44
45 echo "----------------------------------------------------"
46 echo "Info: Done"
47 echo "Info: Run yamllint on yaml files"
48 echo "----------------------------------------------------"
49
50 # set exit_code so we exit ourselves rather than ansible-lint bailing out without
51 # verifying all the yaml files
52 declare -i exit_code=0
53
54 # lint the yaml files
55 cd $WORKSPACE/engine
56 for yaml_file in $(find . -type f -name *.yml | sort); do
57   echo "--> Checking '${yaml_file}' yaml file..."
58   yamllint --format standard --strict ${yaml_file}
59   lint_exit_code=$?
60   if [[ $lint_exit_code != 0 ]]; then
61     exit_code=$lint_exit_code
62   else
63     echo [OK]
64   fi
65   echo
66 done
67 echo "----------------------------------------------------"
68 echo "Info: Done"
69 exit $exit_code
70
71 # vim: set ts=2 sw=2 expandtab: