github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/hack/verify-shellcheck.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # CI script to run shellcheck
     4  set -o errexit
     5  set -o nounset
     6  set -o pipefail
     7  
     8  # cd to the repo root
     9  REPO_ROOT=$(git rev-parse --show-toplevel)
    10  cd "${REPO_ROOT}"
    11  
    12  # upstream shellcheck latest stable image as of June 16th, 2020
    13  SHELLCHECK_IMAGE="koalaman/shellcheck-alpine:v0.7.1"
    14  
    15  # Find all shell scripts excluding:
    16  # - Anything git-ignored - No need to lint untracked files.
    17  # - ./_* - No need to lint output directories.
    18  # - ./.git/* - Ignore anything in the git object store.
    19  # - ./vendor* - Vendored code should be fixed upstream instead.
    20  all_shell_scripts=()
    21  while IFS=$'\n' read -r script;
    22    do git check-ignore -q "$script" || all_shell_scripts+=("$script");
    23  done < <(grep -irl '#!.*sh' . --exclude-dir={_\*,.git\*,vendor\*})
    24  
    25  # common arguments we'll pass to shellcheck
    26  SHELLCHECK_OPTIONS=(
    27    # allow following sourced files that are not specified in the command,
    28    # we need this because we specify one file at at time in order to trivially
    29    # detect which files are failing
    30    "--external-sources"
    31    # disabled lint codes
    32    # 2330 - disabled due to https://github.com/koalaman/shellcheck/issues/1162
    33    "--exclude=2230"
    34    # set colorized output
    35    "--color=auto"
    36  )
    37  
    38  CONTAINER_RUNTIME=${CONTAINER_RUNTIME:-docker}
    39  
    40  # actually shellcheck
    41  "${CONTAINER_RUNTIME}" run \
    42    --rm -it -v "${REPO_ROOT}:${REPO_ROOT}" -w "${REPO_ROOT}" \
    43    "${SHELLCHECK_IMAGE}" \
    44    shellcheck "${SHELLCHECK_OPTIONS[@]}" "${all_shell_scripts[@]}"