Skip to content

Commit deda1e0

Browse files
authored
fix: expand shellcheck converage to scripts without .sh suffix (#2369)
Fix existing errors for those files
1 parent 69b1140 commit deda1e0

File tree

12 files changed

+58
-20
lines changed

12 files changed

+58
-20
lines changed

.github/workflows/ci-auto.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ on:
66
- reopened
77
- synchronize
88
jobs:
9-
lint:
9+
lint-docs:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
13+
- run: make lint-docs
14+
lint-code:
1015
runs-on: ubuntu-latest
1116
steps:
1217
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
1318
- run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
14-
- run: go install mvdan.cc/sh/v3/cmd/shfmt@latest
15-
- run: make lint
19+
- run: make lint-code
1620
templates-test:
1721
runs-on: ubuntu-latest
1822
steps:

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ fmt: ## Format the source files
5757
hack/shfmt --write
5858

5959
.PHONY: lint
60-
lint: lint-docs ## Check the source files for syntax and format issues
60+
lint: lint-docs lint-code
61+
# Convenience target to run all lints. This is not run during presubmits, add new checks in lint-docs or lint-code.
62+
63+
.PHONY: lint-code
64+
lint-code: ## Check the source files for syntax and format issues
6165
hack/shfmt --diff
62-
hack/shellcheck --format gcc --severity error $(shell find $(MAKEFILE_DIR) -type f -name '*.sh' -not -path '*/nodeadm/vendor/*')
66+
hack/shellcheck --format gcc --severity error
6367
hack/lint-space-errors.sh
6468

6569
.PHONY: test

hack/findshell.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Finds shell scripts to run presubmits against.
4+
5+
has_shell_shebang() {
6+
local file="$1"
7+
8+
if grep -I -q -z -E '^#!.*(/|env )(bash|sh)' "$file"; then
9+
return 0
10+
fi
11+
12+
return 1
13+
}
14+
15+
dir=$1
16+
find "$dir" -type f -print0 | while IFS= read -r -d '' file; do
17+
18+
if [[ "$file" == *"nodeadm/vendor"* ]]; then
19+
continue
20+
fi
21+
22+
if [[ "$file" == *".git/hooks"* ]]; then
23+
continue
24+
fi
25+
26+
if [[ "$file" == *.sh ]] || has_shell_shebang "$file"; then
27+
echo "$file"
28+
fi
29+
done

hack/shellcheck

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#!/usr/bin/env bash
2-
# shellcheck wrapper
2+
# wrapper for shellcheck
33

44
set -o nounset
55

66
WORKDIR=$(realpath .)
7+
FILES=$(hack/findshell.sh ${WORKDIR})
78
SHELLCHECK_COMMAND=$(which shellcheck 2> /dev/null)
89
if [ -z "$SHELLCHECK_COMMAND" ]; then
910
SHELLCHECK_COMMAND="docker run --rm -v $WORKDIR:$WORKDIR -w $WORKDIR koalaman/shellcheck:stable"
1011
fi
11-
$SHELLCHECK_COMMAND $@
12+
$SHELLCHECK_COMMAND $* $FILES

hack/shfmt

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

1616
FILES=$(${SHFMT_COMMAND} --find --language-dialect auto "${WORKDIR}" | grep -v "nodeadm/vendor/")
1717

18-
${SHFMT_COMMAND} ${FLAGS} $@ ${FILES}
18+
${SHFMT_COMMAND} ${FLAGS} "$@" ${FILES}

templates/shared/runtime/bin/setup-local-disks

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,14 @@ fi
269269
case "${DISK_SETUP}" in
270270
"raid0")
271271
maybe_raid 0
272-
echo "Successfully setup RAID-0 consisting of ${EPHEMERAL_DISKS[@]}"
272+
echo "Successfully setup RAID-0 consisting of " "${EPHEMERAL_DISKS[@]}"
273273
;;
274274
"raid10")
275275
maybe_raid 10
276-
echo "Successfully setup RAID-10 consisting of ${EPHEMERAL_DISKS[@]}"
276+
echo "Successfully setup RAID-10 consisting of " "${EPHEMERAL_DISKS[@]}"
277277
;;
278278
"mount")
279279
maybe_mount
280-
echo "Successfully setup disk mounts consisting of ${EPHEMERAL_DISKS[@]}"
280+
echo "Successfully setup disk mounts consisting of " "${EPHEMERAL_DISKS[@]}"
281281
;;
282282
esac

templates/test/mocks/aws

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ SCRIPTPATH="$(
55
pwd -P
66
)"
77

8-
echo >&2 "mocking 'aws $@'"
8+
echo >&2 "mocking 'aws $*'"
99

1010
AWS_MOCK_FAIL=${AWS_MOCK_FAIL:-false}
1111
if [ "$AWS_MOCK_FAIL" = "true" ]; then
12-
echo >&2 "failing mocked 'aws $@'"
12+
echo >&2 "failing mocked 'aws $*'"
1313
exit 1
1414
fi
1515

@@ -38,14 +38,14 @@ fi
3838
if [[ $1 == "eks" ]]; then
3939
if [[ $2 == "describe-cluster" ]]; then
4040
# Assuming all the cluster name for the test cases would be "ipv4-cluster"
41-
if [[ $(echo $@ | grep "ipv4-cluster") ]]; then
41+
if [[ $(echo "$@" | grep "ipv4-cluster") ]]; then
4242
if [[ -f "${SCRIPTPATH}/describe-cluster/ipv4-cluster.txt" ]]; then
4343
cat "${SCRIPTPATH}/describe-cluster/ipv4-cluster.txt"
4444
exit 0
4545
fi
4646
fi
4747
# Assuming all the cluster name for the test cases would be "ipv6-cluster"
48-
if [[ $(echo $@ | grep "ipv6-cluster") ]]; then
48+
if [[ $(echo "$@" | grep "ipv6-cluster") ]]; then
4949
if [[ -f "${SCRIPTPATH}/describe-cluster/ipv6-cluster.txt" ]]; then
5050
cat "${SCRIPTPATH}/describe-cluster/ipv6-cluster.txt"
5151
exit 0

templates/test/mocks/iptables-save

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22

3-
echo >&2 "mocking 'iptables-save $@'"
3+
echo >&2 "mocking 'iptables-save $*'"

templates/test/mocks/kubelet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
echo >&2 "mocking 'kubelet $@'"
3+
echo >&2 "mocking 'kubelet $*'"
44

55
# The only use of kubelet directly is to get the Kubernetes version,
66
# so we'll set a default here to avoid test failures, and you can

templates/test/mocks/mount

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
echo >&2 "mocking 'mount $@'"
3+
echo >&2 "mocking 'mount $*'"
44

55
echo 'sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
66
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

0 commit comments

Comments
 (0)