Skip to content

Commit 4a097d8

Browse files
authored
Merge pull request #1621 from ashish-amarnath/add-shellcheck
🏃 Add and fix shellcheck errors
2 parents 67d5048 + 01585c2 commit 4a097d8

23 files changed

+124
-35
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ clean-release: ## Remove the release folder
300300
verify:
301301
./hack/verify-boilerplate.sh
302302
./hack/verify-doctoc.sh
303+
./hack/verify-shellcheck.sh
303304
$(MAKE) verify-modules
304305
$(MAKE) verify-gen
305306
$(MAKE) verify-modules

hack/utils.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# get_root_path returns the root path of the project source tree
17+
get_root_path() {
18+
git rev-parse --show-toplevel
19+
}
20+
21+
# cd_root_path cds to the root path of the project source tree
22+
cd_root_path() {
23+
cd "$(get_root_path)" || exit
24+
}

hack/verify-shellcheck.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2019 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
OS="unknown"
21+
if [[ "${OSTYPE}" == "linux"* ]]; then
22+
OS="linux"
23+
elif [[ "${OSTYPE}" == "darwin"* ]]; then
24+
OS="darwin"
25+
fi
26+
27+
# shellcheck source=./hack/utils.sh
28+
source "$(dirname "$0")/utils.sh"
29+
ROOT_PATH=$(get_root_path)
30+
31+
# create a temporary directory
32+
TMP_DIR=$(mktemp -d)
33+
34+
# cleanup on exit
35+
cleanup() {
36+
echo "Cleaning up..."
37+
rm -rf "${TMP_DIR}"
38+
}
39+
trap cleanup EXIT
40+
41+
# install shellcheck (x64 only!)
42+
cd "${TMP_DIR}" || exit
43+
VERSION="shellcheck-v0.7.0"
44+
DOWNLOAD_FILE="${VERSION}.${OS}.x86_64.tar.xz"
45+
curl https://storage.googleapis.com/shellcheck/"${DOWNLOAD_FILE}" -O ${DOWNLOAD_FILE}
46+
tar xf "${DOWNLOAD_FILE}"
47+
cd "${VERSION}" || exit
48+
49+
echo "Running shellcheck..."
50+
cd "${ROOT_PATH}" || exit
51+
OUT="${TMP_DIR}/out.log"
52+
IGNORE_FILES=$(find . -name "*.sh" | grep third_party)
53+
echo "Ignoring shellcheck on ${IGNORE_FILES}"
54+
FILES=$(find . -name "*.sh" | grep -v third_party)
55+
while read -r file; do
56+
"${TMP_DIR}/${VERSION}/shellcheck" -x "$file" >> "${OUT}" 2>&1
57+
done <<< "$FILES"
58+
59+
if [[ -s "${OUT}" ]]; then
60+
echo "Found errors:"
61+
cat "${OUT}"
62+
exit 1
63+
fi

scripts/ci-integration.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set -o nounset
1919
set -o pipefail
2020

2121
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22-
# shellcheck source=../hack/ensure-go.sh
22+
# shellcheck source=./hack/ensure-go.sh
2323
source "${REPO_ROOT}/hack/ensure-go.sh"
2424

2525
MAKE="make"
@@ -47,7 +47,7 @@ install_kubectl() {
4747
}
4848

4949
install_kustomize() {
50-
wget https://github.com/kubernetes-sigs/kustomize/releases/download/v${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_${GOOS}_${GOARCH} \
50+
wget "https://github.com/kubernetes-sigs/kustomize/releases/download/v${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_${GOOS}_${GOARCH}" \
5151
--no-verbose -O /usr/local/bin/kustomize
5252
chmod +x /usr/local/bin/kustomize
5353
}

scripts/ci-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ set -o pipefail
2121
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2222
cd "${REPO_ROOT}" || exit 1
2323

24-
# shellcheck source=../hack/ensure-go.sh
24+
# shellcheck source=./hack/ensure-go.sh
2525
source "${REPO_ROOT}/hack/ensure-go.sh"
26-
# shellcheck source=../scripts/fetch_ext_bins.sh
26+
# shellcheck source=./scripts/fetch_ext_bins.sh
2727
source ./scripts/fetch_ext_bins.sh
2828

2929
fetch_tools

test/infrastructure/docker/hack/update-all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -o errexit
1717
set -o nounset
1818
set -o pipefail
1919

20-
# shellcheck source=/dev/null
20+
# shellcheck source=./test/infrastructure/docker/hack/utils.sh
2121
source "$(dirname "$0")/utils.sh"
2222
REPO_PATH=$(get_root_path)
2323

test/infrastructure/docker/hack/update-deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o nounset
1818
set -o errexit
1919
set -o pipefail
2020

21-
# shellcheck source=/dev/null
21+
# shellcheck source=./test/infrastructure/docker/hack/utils.sh
2222
source "$(dirname "$0")/utils.sh"
2323
# cd to the root path
2424
cd_root_path

test/infrastructure/docker/hack/update-gofmt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
# shellcheck source=/dev/null
21+
# shellcheck source=./test/infrastructure/docker/hack/utils.sh
2222
source "$(dirname "$0")/utils.sh"
2323
# cd to the root path
2424
cd_root_path

test/infrastructure/docker/hack/update-goimports.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
# shellcheck source=/dev/null
21+
# shellcheck source=./test/infrastructure/docker/hack/utils.sh
2222
source "$(dirname "$0")/utils.sh"
2323
# cd to the root path
2424
cd_root_path

test/infrastructure/docker/hack/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
# get_root_path returns the root path of the project source tree
1717
get_root_path() {
18-
echo "$(git rev-parse --show-toplevel)"
18+
git rev-parse --show-toplevel
1919
}
2020

2121
# cd_root_path cds to the root path of the project source tree

0 commit comments

Comments
 (0)