diff --git a/.github/workflows/everything.yml b/.github/workflows/everything.yml index 177c55ad6a..435d9851e5 100644 --- a/.github/workflows/everything.yml +++ b/.github/workflows/everything.yml @@ -82,6 +82,9 @@ jobs: - name: Python working-directory: source run: ../gha/scripts/ci/scripts/run-flake8.sh + - name: Shell + working-directory: source + run: ../gha/scripts/ci/scripts/run-shellcheck.sh ####################################### diff --git a/.shellcheck_exclude_paths b/.shellcheck_exclude_paths new file mode 100644 index 0000000000..a0e74e4ee1 --- /dev/null +++ b/.shellcheck_exclude_paths @@ -0,0 +1,53 @@ +scripts/ci/azure/linux-setup.sh +scripts/ci/azure/macos-setup.sh +scripts/ci/azure/run.sh +scripts/ci/circle/postCDashStatus.sh +scripts/ci/circle/run.sh +scripts/ci/gh-actions/check-branch-name.sh +scripts/ci/gh-actions/get-changed-files.sh +scripts/ci/gh-actions/linux-setup.sh +scripts/ci/gh-actions/macos-setup.sh +scripts/ci/gh-actions/run.sh +scripts/ci/gitlab-ci/run.sh +scripts/ci/images-v2/build-base.sh +scripts/ci/images-v2/build-clang-base.sh +scripts/ci/images-v2/build-clang.sh +scripts/ci/images-v2/build-cuda.sh +scripts/ci/images-v2/build-functions.sh +scripts/ci/images-v2/build-gcc-base.sh +scripts/ci/images-v2/build-gcc.sh +scripts/ci/images-v2/build-intel-base.sh +scripts/ci/images-v2/build-intel.sh +scripts/ci/images-v2/build-mpich.sh +scripts/ci/images-v2/build-nvhpc.sh +scripts/ci/images-v2/build.sh +scripts/ci/images/build-emu-power8-image.sh +scripts/ci/images/build-native-images.sh +scripts/ci/images/emu-el7/entrypoint.sh +scripts/ci/images/emu-el7/qemu-binfmt-conf.sh +scripts/ci/images/emu-el7/register.sh +scripts/ci/scripts/github-prs-to-gitlab.sh +scripts/ci/scripts/run-clang-format.sh +scripts/ci/scripts/run-flake8.sh +scripts/ci/setup-run/ci-el8-gcc10.sh +scripts/ci/setup-run/ci-el8-gcc11.sh +scripts/ci/setup-run/ci-el8-gcc9.sh +scripts/ci/setup-run/ci-el8-icc.sh +scripts/ci/setup-run/ci-el8-nvhpc222-mpi.sh +scripts/ci/setup-run/ci-el8-nvhpc222.sh +scripts/ci/setup-run/ci-el8-oneapi.sh +scripts/ci/setup/ci-power8-el7-xl-serial.sh +scripts/dashboard/nightly/aaargh.sh +scripts/dashboard/nightly/cori.sh +scripts/dashboard/nightly/summitdev.sh +scripts/developer/git/setup-aliases +scripts/developer/git/setup-hooks +scripts/developer/git/setup-remotes +scripts/developer/merge-pr-from-release.sh +scripts/developer/setup.sh +scripts/docker/setup-user.sh +scripts/runconf/runconf.sh +scripts/runconf/runconf_olcf.sh +scripts/travis/run-docker.sh +scripts/travis/run-format.sh +scripts/travis/run.sh diff --git a/scripts/ci/images/formatting/Dockerfile b/scripts/ci/images/formatting/Dockerfile index b5a35a7106..9ee5ef0b6c 100644 --- a/scripts/ci/images/formatting/Dockerfile +++ b/scripts/ci/images/formatting/Dockerfile @@ -1,10 +1,15 @@ FROM ubuntu:20.04 -RUN apt-get update && \ - apt-get install -y apt-utils && \ - apt-get install -y curl git flake8 libtinfo5 && \ +RUN apt update && \ + DEBIAN_FRONTEND="noninteractive" apt upgrade -y --no-install-recommends && \ + DEBIAN_FRONTEND="noninteractive" apt install -y --no-install-recommends \ + apt-utils \ + ca-certificates \ + clang-format-7 \ + curl \ + flake8 \ + git \ + libtinfo5 \ + shellcheck \ + && \ apt-get clean - -RUN curl -L https://github.com/llvm/llvm-project/releases/download/llvmorg-7.1.0/clang+llvm-7.1.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz | tar -C /opt -xJv && \ - mv /opt/clang* /opt/llvm-7.1.0 -ENV PATH=/opt/llvm-7.1.0/bin:$PATH diff --git a/scripts/ci/scripts/run-shellcheck.sh b/scripts/ci/scripts/run-shellcheck.sh new file mode 100755 index 0000000000..c987a5bea0 --- /dev/null +++ b/scripts/ci/scripts/run-shellcheck.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# We need the same sort order +export LC_ALL=C +EXCLUDE_SCRIPTS=.shellcheck_exclude_paths + +echo "---------- Begin ENV ----------" +env | sort +echo "---------- End ENV ----------" + +if [ -n "${SOURCE_DIR}" ] +then + cd "${SOURCE_DIR}" || exit +fi + +# Give me a sorted list of the project scripts +found_scripts="$({ + find scripts -regextype posix-extended -iregex '.*\.(sh|bash)' -print; + grep -rnlE -e '#!/(/usr)?/bin/(bash|sh)' -e '#!(/usr)?/bin/env\s+(bash|sh)' scripts; +} | sort -u)" + +echo "[I] Found the following files:" +echo "$found_scripts" + +# Give me the list of scripts without $EXCLUDE_SCRIPTS +if [ -f "$EXCLUDE_SCRIPTS" ] +then + if ! sort -uc "$EXCLUDE_SCRIPTS" + then + echo "[E] file: $EXCLUDE_SCRIPTS is not sorted." + echo " To fix this sort with: LC_ALL=C sort -u $EXCLUDE_SCRIPTS" + exit 1 + fi + + check_scripts=$(comm -2 -3 <(echo "$found_scripts") "$EXCLUDE_SCRIPTS" ) +fi + +echo "[I] Checking the following files:" +echo "$check_scripts" + +if ! xargs -n1 shellcheck <<<"$check_scripts" +then + echo "[E] shellcheck:" + echo " Code format checks failed." + echo " Please run shellcheck on your changes before committing." + exit 2 +fi + +exit 0