]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
ceph-docker-lint: add docker shellcheck 714/head
authorSébastien Han <seb@redhat.com>
Tue, 16 May 2017 14:22:21 +0000 (16:22 +0200)
committerSébastien Han <seb@redhat.com>
Wed, 17 May 2017 14:29:59 +0000 (16:29 +0200)
To run shellcheck with the -x option (Follow 'source' statements even
when the file is not specified as input.  By default, shellcheck will
only follow files specified on the command line (plus /dev/null).  This
option  allows  following any file the script may source.) we need at
least version 0.4.0.
Unfortunately epel only provides a 0.3.X version.

Fortunately, the container image provides the latest version which helps
us running the tests.

Signed-off-by: Sébastien Han <seb@redhat.com>
ceph-docker-lint/build/build

index 76cb7c51b898a5e9d6645e45389e4cca9aa52e87..d18e713f5904d8c112af9eb3926de6068b8da311 100755 (executable)
@@ -21,46 +21,40 @@ function generate_filelist(){
 }
 
 function check(){
+    local file
     while read -r filename; do
-        if [[ -z "$IGNORE_THESE_CODES" ]]
-        then
-            shellcheck "$filename";
-        else
-            shellcheck -e "$IGNORE_THESE_CODES" "$filename";
-        fi
+        pushd "$(dirname "$filename")"
+        file=$(basename "$filename")
+        chcon -t svirt_sandbox_file_t "$file"
+        docker run -v "$(pwd)"/"$file":/"$file" koalaman/shellcheck --external-sources --exclude "$IGNORE_THESE_CODES" /"$file"
+        popd
     done
     return $?
 }
 
 function main() {
-# install some of our dependencies
-if [ "${HUDSON_URL}" = "https://jenkins.ceph.com/" ]
-then
-    sudo yum -y install epel-release
-    sudo yum -y install ShellCheck
-    sudo yum -y install jq
-    pull_request_id=${ghprbPullId:-$2}
-    workspace=${WORKSPACE:-$1}
-else
-    if [[ ! -x $(which jq) ]]
-    then
-        echo 'install jq first'
-        exit 1
-    fi
-    if [[ ! -x $(which shellcheck) ]]
+    # install some of our dependencies
+    if [ "${HUDSON_URL}" = "https://jenkins.ceph.com/" ]
     then
-        echo 'install shellcheck first'
-        exit 1
+        sudo yum -y install epel-release
+        sudo yum -y install docker jq
+        pull_request_id=${ghprbPullId:-$2}
+        workspace=${WORKSPACE:-$1}
+    else
+        if ! command -v docker || ! command -v jq
+        then
+            echo "docker or jq is/are missing, install it/them"
+            exit 1
+        fi
+        pull_request_id=${ghprbPullId:-$2}
+        workspace=${WORKSPACE:-$1}
     fi
-    pull_request_id=${ghprbPullId:-$2}
-    workspace=${WORKSPACE:-$1}
-fi
 
 
-pushd "$workspace/ceph-docker"
-generate_filelist | check
-popd
-exit $?
+    pushd "$workspace/ceph-docker"
+    generate_filelist | check
+    popd
+    exit $?
 }
 
 main "$@"