Skip to content

Commit 1dd6af3

Browse files
🏃 Add and fix shellcheck errors
Signed-off-by: Ashish Amarnath <[email protected]>
1 parent 09d4461 commit 1dd6af3

23 files changed

+117
-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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
# shellcheck source=./hack/utils.sh
21+
source "$(dirname "$0")/utils.sh"
22+
ROOT_PATH=$(get_root_path)
23+
24+
# create a temporary directory
25+
TMP_DIR=$(mktemp -d)
26+
27+
# cleanup on exit
28+
cleanup() {
29+
echo "Cleaning up..."
30+
rm -rf "${TMP_DIR}"
31+
}
32+
trap cleanup EXIT
33+
34+
# install shellcheck (Linux-x64 only!)
35+
cd "${TMP_DIR}" || exit
36+
VERSION="shellcheck-v0.6.0"
37+
DOWNLOAD_FILE="${VERSION}.linux.x86_64.tar.xz"
38+
wget https://storage.googleapis.com/shellcheck/"${DOWNLOAD_FILE}"
39+
tar xf "${DOWNLOAD_FILE}"
40+
cd "${VERSION}" || exit
41+
42+
echo "Running shellcheck..."
43+
cd "${ROOT_PATH}" || exit
44+
OUT="${TMP_DIR}/out.log"
45+
IGNORE_FILES=$(find . -name "*.sh" | grep third_party)
46+
echo "Ignoring shellcheck on ${IGNORE_FILES}"
47+
FILES=$(find . -name "*.sh" | grep -v third_party)
48+
while read -r file; do
49+
"${TMP_DIR}/${VERSION}/shellcheck" -x "$file" >> "${OUT}" 2>&1
50+
done <<< "$FILES"
51+
52+
if [[ -s "${OUT}" ]]; then
53+
echo "Found errors:"
54+
cat "${OUT}"
55+
exit 1
56+
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)