ci: use shellcheck for .gitlab-ci/container/ directory
authorDavid Heidelberg <david.heidelberg@collabora.com>
Wed, 10 Aug 2022 13:27:31 +0000 (15:27 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 26 Aug 2022 21:20:14 +0000 (21:20 +0000)
It checks our CI shell code in `debian-build-testing` job.

Reviewed-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Signed-off-by: David Heidelberg <david.heidelberg@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17574>

.gitlab-ci/build/gitlab-ci.yml
.gitlab-ci/container/debian/x86_build.sh
.gitlab-ci/image-tags.yml
.gitlab-ci/run-shellcheck.sh [new file with mode: 0755]

index 5109912..b8e6080 100644 (file)
@@ -171,6 +171,7 @@ debian-build-testing:
       -D tools=drm-shim,etnaviv,freedreno,glsl,intel,intel-ui,nir,nouveau,xvmc,lima,panfrost,asahi
   script:
     - .gitlab-ci/lava/lava-pytest.sh
+    - .gitlab-ci/run-shellcheck.sh
     - .gitlab-ci/meson/build.sh
     - .gitlab-ci/run-shader-db.sh
 
index 479f5d1..c03e82a 100644 (file)
@@ -48,6 +48,7 @@ apt-get install -y --no-remove \
       python3-pytest \
       procps \
       spirv-tools \
+      shellcheck \
       strace \
       time \
       zstd
index dc6effe..b438115 100644 (file)
@@ -1,21 +1,21 @@
 variables:
    DEBIAN_X86_BUILD_BASE_IMAGE: "debian/x86_build-base"
-   DEBIAN_BASE_TAG: "2022-08-22-drop-llvm9"
+   DEBIAN_BASE_TAG: "2022-08-25-shellcheck"
 
    DEBIAN_X86_BUILD_IMAGE_PATH: "debian/x86_build"
-   DEBIAN_BUILD_TAG: "2022-08-23-mold"
+   DEBIAN_BUILD_TAG: "2022-08-25-shellcheck"
 
    DEBIAN_X86_BUILD_MINGW_IMAGE_PATH: "debian/x86_build-mingw"
-   DEBIAN_BUILD_MINGW_TAG: "2022-08-17-bump"
+   DEBIAN_BUILD_MINGW_TAG: "2022-08-25-shellcheck"
 
    DEBIAN_X86_TEST_BASE_IMAGE: "debian/x86_test-base"
 
    DEBIAN_X86_TEST_IMAGE_PATH: "debian/x86_test-gl"
-   DEBIAN_X86_TEST_GL_TAG: "2022-08-17-bump"
-   DEBIAN_X86_TEST_VK_TAG: "2022-08-17-bump"
+   DEBIAN_X86_TEST_GL_TAG: "2022-08-25-shellcheck"
+   DEBIAN_X86_TEST_VK_TAG: "2022-08-25-shellcheck"
 
-   FEDORA_X86_BUILD_TAG: "2022-08-23-mold"
-   KERNEL_ROOTFS_TAG: "2022-08-17-bump"
+   FEDORA_X86_BUILD_TAG: "2022-08-25-shellcheck"
+   KERNEL_ROOTFS_TAG: "2022-08-25-shellcheck"
 
    WINDOWS_X64_VS_PATH: "windows/x64_vs"
    WINDOWS_X64_VS_TAG: "2022-08-17-bump"
diff --git a/.gitlab-ci/run-shellcheck.sh b/.gitlab-ci/run-shellcheck.sh
new file mode 100755 (executable)
index 0000000..4be356a
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+
+CHECKPATH=".gitlab-ci/container"  # TODO: expand to cover whole .gitlab-ci/
+
+is_bash() {
+    [[ $1 == *.sh ]] && return 0
+    [[ $1 == */bash-completion/* ]] && return 0
+    [[ $(file -b --mime-type "$1") == text/x-shellscript ]] && return 0
+    return 1
+}
+
+while IFS= read -r -d $'' file; do
+    if is_bash "$file" ; then
+        shellcheck -x -W0 -s bash "$file"
+        rc=$?
+        if [ "${rc}" -eq 0 ]
+        then
+            continue
+        else
+            exit 1
+        fi
+    fi
+done < <(find $CHECKPATH -type f \! -path "./.git/*" -print0)