810f93321138590d4b0c1d8ee394f2d4e3364648
[releng.git] / jjb / kuberef / kuberef-run-linting.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2020 Samsung Electronics
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o nounset
12 set -o pipefail
13 set -o xtrace
14
15 echo "Requirements validation"
16 # shellcheck disable=SC1091
17 source /etc/os-release || source /usr/lib/os-release
18
19 pkgs=""
20 if ! command -v shellcheck; then
21     case ${ID,,} in
22         *suse*|rhel|centos|fedora)
23             pkgs="ShellCheck"
24         ;;
25         ubuntu|debian)
26             pkgs="shellcheck"
27         ;;
28     esac
29 fi
30
31 if ! command -v pip; then
32     pkgs+=" python-pip"
33 fi
34
35 if [ -n "$pkgs" ]; then
36     echo "Requirements installation"
37     case ${ID,,} in
38         *suse*)
39             sudo zypper install --gpg-auto-import-keys refresh
40             sudo -H -E zypper install -y --no-recommends "$pkgs"
41         ;;
42         ubuntu|debian)
43             sudo apt-get update
44             sudo -H -E apt-get -y --no-install-recommends install "$pkgs"
45         ;;
46         rhel|centos|fedora)
47             PKG_MANAGER=$(command -v dnf || command -v yum)
48             if ! sudo "$PKG_MANAGER" repolist | grep "epel/"; then
49                 sudo -H -E "$PKG_MANAGER" -q -y install epel-release
50             fi
51             sudo "$PKG_MANAGER" updateinfo --assumeyes
52             sudo -H -E "${PKG_MANAGER}" -y install "$pkgs"
53         ;;
54     esac
55 fi
56
57 echo "Server tools information:"
58 python -V
59 tox --version
60 shellcheck -V
61
62 echo "Linting process execution"
63 tox -e lint
64 bash -c 'shopt -s globstar; shellcheck -x **/*.sh'