Jeremy Ronquillo | 6be909e | 2020-08-24 09:36:13 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2017-present Open Networking Foundation |
| 4 | # |
Andy Bavier | 2c42773 | 2022-02-03 15:16:46 -0700 | [diff] [blame] | 5 | # SPDX-License-Identifier: Apache-2.0 |
Jeremy Ronquillo | 6be909e | 2020-08-24 09:36:13 -0700 | [diff] [blame] | 6 | |
| 7 | # shcheck.sh - check shell scripts with shellcheck |
| 8 | |
| 9 | set +e -u -o pipefail |
| 10 | fail_shellcheck=0 |
| 11 | |
| 12 | # verify that we have shellcheck-lint installed |
| 13 | command -v shellcheck >/dev/null 2>&1 || { echo "shellcheck not found, please install it" >&2; exit 1; } |
| 14 | |
| 15 | # when not running under Jenkins, use current dir as workspace |
| 16 | WORKSPACE=${WORKSPACE:-.} |
| 17 | |
| 18 | echo "=> Linting shell script with $(shellcheck --version)" |
| 19 | |
| 20 | while IFS= read -r -d '' sf |
| 21 | do |
| 22 | echo "==> CHECKING: ${sf}" |
| 23 | shellcheck "${sf}" |
| 24 | rc=$? |
| 25 | if [[ $rc != 0 ]]; then |
| 26 | echo "==> LINTING FAIL: ${sf}" |
| 27 | fail_shellcheck=1 |
| 28 | fi |
| 29 | done < <(find "${WORKSPACE}" \( -name "*.sh" -o -name "*.bash" \) -print0) |
| 30 | |
| 31 | exit ${fail_shellcheck} |
| 32 | |