Skip to content

Commit 74e5ac7

Browse files
authored
Merge pull request #1447 from zhuangqh/add-shellcheck
fix: correct shell script format via shellcheck reports
2 parents dabd3bb + 96f0609 commit 74e5ac7

File tree

16 files changed

+154
-118
lines changed

16 files changed

+154
-118
lines changed

.circleci/Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This Dockerfile is used to build an image which is used in circle CI
2+
# to run the the following check or validation:
3+
# markdownlint
4+
# misspell
5+
# ShellCheck
6+
FROM ubuntu:16.04
7+
8+
RUN apt-get update \
9+
&& apt-get install -y rubygems git curl \
10+
&& gem install rake \
11+
&& gem install bundler \
12+
&& apt-get clean
13+
14+
# install markdownlint
15+
RUN git clone https://github.com/markdownlint/markdownlint.git \
16+
&& cd markdownlint && git checkout v0.4.0 && rake install
17+
18+
# install misspell
19+
RUN git clone https://github.com/client9/misspell.git \
20+
&& cd misspell && curl -L -o ./install-misspell.sh https://git.io/misspell && sh ./install-misspell.sh
21+
22+
RUN mv misspell/bin/misspell /usr/local/bin/
23+
24+
# install shellcheck
25+
RUN apt-get install shellcheck

.circleci/config.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
# Check https://circleci.com/docs/2.0/language-go/ for more details
44
version: 2
55
jobs:
6-
misspell-and-markdown-lint:
6+
markdownlint-misspell-shellcheck:
77
docker:
8-
- image: allencloud/mdlmisspell:v0.1
8+
# this image is build from Dockerfile located in ./.circleci/Dockerfile
9+
- image: allencloud/pouchlint:v0.1
910
working_directory: /go/src/github.com/{{ORG_NAME}}/{{REPO_NAME}}
1011
steps:
1112
- checkout
@@ -15,7 +16,12 @@ jobs:
1516
find ./ -name "*.md" | grep -v vendor | grep -v extra | grep -v commandline | grep -v .github | grep -v swagger | grep -v api | xargs mdl -r ~MD010,~MD013,~MD024,~MD029,~MD033,~MD036
1617
- run:
1718
name: use opensource tool client9/misspell to correct commonly misspelled English words
18-
command: find ./* -name "*" | grep -v extra | grep -v vendor | xargs misspell -error
19+
command: |
20+
find ./* -name "*" | grep -v extra | grep -v vendor | xargs misspell -error
21+
- run:
22+
name: use ShellCheck (https://github.com/koalaman/shellcheck) to check the validateness of shell scripts in pouch repo
23+
command: |
24+
find ./ -name "*.sh" | grep -v vendor | grep -v extra | xargs shellcheck
1925
2026
code-check:
2127
docker:
@@ -52,6 +58,6 @@ workflows:
5258
version: 2
5359
ci:
5460
jobs:
55-
- misspell-and-markdown-lint
61+
- markdownlint-misspell-shellcheck
5662
- code-check
5763
- unit-test

hack/cri-test/test-cri.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
set -o nounset
1818
set -o pipefail
1919

20-
source $(dirname "${BASH_SOURCE[0]}")/test-utils.sh
20+
source "$(dirname "${BASH_SOURCE[0]}")/test-utils.sh"
2121

2222
POUCH_SOCK="/var/run/pouchcri.sock"
2323

@@ -42,8 +42,8 @@ GOPATH=${GOPATH%%:*}
4242
# Install CNI first
4343
mkdir -p /etc/cni/net.d /opt/cni/bin
4444

45-
git clone https://github.com/containernetworking/plugins $GOPATH/src/github.com/containernetworking/plugins
46-
cd $GOPATH/src/github.com/containernetworking/plugins
45+
git clone https://github.com/containernetworking/plugins "$GOPATH/src/github.com/containernetworking/plugins"
46+
cd "$GOPATH/src/github.com/containernetworking/plugins"
4747

4848
./build.sh
4949
cp bin/* /opt/cni/bin
@@ -89,26 +89,26 @@ GINKGO=${GOPATH}/bin/ginkgo
8989
GINKGO_PKG=github.com/onsi/ginkgo/ginkgo
9090

9191
# Install critest
92-
if [ ! -x "$(command -v ${CRITEST})" ]; then
92+
if [ ! -x "$(command -v "${CRITEST}")" ]; then
9393
go get -d ${CRITOOL_PKG}/...
94-
cd ${GOPATH}/src/${CRITOOL_PKG}
94+
cd "${GOPATH}/src/${CRITOOL_PKG}"
9595
git fetch --all
96-
git checkout ${CRITOOL_VERSION}
96+
git checkout "${CRITOOL_VERSION}"
9797
make
9898
fi
99-
which ${CRITEST}
99+
which "${CRITEST}"
100100

101101
# Install ginkgo
102-
if [ ! -x "$(command -v ${GINKGO})" ]; then
102+
if [ ! -x "$(command -v "${GINKGO}")" ]; then
103103
go get -u ${GINKGO_PKG}
104104
fi
105-
which ${GINKGO}
105+
which "${GINKGO}"
106106

107-
mkdir -p ${REPORT_DIR}
108-
test_setup ${REPORT_DIR}
107+
mkdir -p "${REPORT_DIR}"
108+
test_setup "${REPORT_DIR}"
109109

110110
# Run cri validation test
111-
sudo env PATH=${PATH} GOPATH=${GOPATH} ${CRITEST} --runtime-endpoint=${POUCH_SOCK} --ginkgo.focus="${CRI_FOCUS}" --ginkgo.skip="${CRI_SKIP}"
111+
sudo env PATH="${PATH}" GOPATH="${GOPATH}" "${CRITEST}" --runtime-endpoint=${POUCH_SOCK} --ginkgo.focus="${CRI_FOCUS}" --ginkgo.skip="${CRI_SKIP}"
112112
test_exit_code=$?
113113

114114
test_teardown

hack/cri-test/test-utils.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
# limitations under the License.
1616

1717
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18-
. ${ROOT}/versions
18+
. "${ROOT}/versions"
1919
# POUCH_FLAGS are the extra flags to use when start pouchd.
2020
POUCH_FLAGS=${POUCH_FLAGS:-""}
2121
# RESTART_WAIT_PERIOD is the period to wait before restarting pouchd/containerd.
2222
RESTART_WAIT_PERIOD=${RESTART_WAIT_PERIOD:-10}
2323

24-
POUCH_SOCK=/var/run/pouchcri.sock
24+
# POUCH_SOCK=/var/run/pouchcri.sock
2525

2626
pouch_pid=
2727
containerd_pid=
@@ -35,22 +35,22 @@ test_setup() {
3535
echo "containerd is not installed, please run hack/make.sh"
3636
exit 1
3737
fi
38-
containerd_pid_command=`pgrep containerd`
38+
containerd_pid_command=$(pgrep containerd)
3939
containerd_pid=${containerd_pid_command}
4040
if [ ! -n "${containerd_pid}" ]; then
41-
keepalive "/usr/local/bin/containerd" ${RESTART_WAIT_PERIOD} &> ${report_dir}/containerd.log &
41+
keepalive "/usr/local/bin/containerd" "${RESTART_WAIT_PERIOD}" &> "${report_dir}/containerd.log" &
4242
containerd_pid=$!
4343
fi
4444
# Wait for containerd to be running by using the containerd client ctr to check the version
4545
# of the containerd server. Wait an increasing amount of time after each of five attempts
4646
readiness_check "ctr version"
4747

4848
# Start pouchd
49-
pouch_pid_command=`pgrep pouchd`
49+
pouch_pid_command=$(pgrep pouchd)
5050
pouch_pid=${pouch_pid_command}
5151
if [ ! -n "${pouch_pid}" ]; then
5252
keepalive "pouchd --enable-cri --sandbox-image=gcr.io/google_containers/pause-amd64:3.0 ${POUCH_FLAGS}" \
53-
${RESTART_WAIT_PERIOD} &> ${report_dir}/pouch.log &
53+
"${RESTART_WAIT_PERIOD}" &> "${report_dir}/pouch.log" &
5454
pouch_pid=$!
5555
fi
5656
readiness_check "pouch version"
@@ -71,11 +71,11 @@ test_teardown() {
7171
# keepalive process is eventually killed in test_teardown.
7272
keepalive() {
7373
local command=$1
74-
echo ${command}
74+
echo "${command}"
7575
local wait_period=$2
7676
while true; do
7777
${command}
78-
sleep ${wait_period}
78+
sleep "${wait_period}"
7979
done
8080
}
8181

hack/generate-swagger-models.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# Get the absolute path of this file
88
DIR="$( cd "$( dirname "$0" )" && pwd )"
99

10-
swagger generate model -f $DIR/../apis/swagger.yml -t $DIR/../apis -m types
10+
swagger generate model -f "$DIR/../apis/swagger.yml" -t "$DIR/../apis" -m types

hack/install_lxcfs_on_centos.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#
66

77
yes | yum install autotools-dev m4 autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc libtool
8-
yes | yum install fuse-devel.$(uname -p)
9-
yes | yum install pam-devel.$(uname -p)
10-
yes | yum install fuse.$(uname -p)
8+
yes | yum install "fuse-devel.$(uname -p)"
9+
yes | yum install "pam-devel.$(uname -p)"
10+
yes | yum install "fuse.$(uname -p)"
1111

1212
TMP=$(mktemp -d)
13-
trap "rm -rf $TMP" EXIT
13+
trap 'rm -rf "$TMP"' EXIT
1414

15-
cd $TMP &&
15+
cd "$TMP" &&
1616
git clone -b stable-2.0 https://github.com/lxc/lxcfs.git &&
1717
cd lxcfs
1818

0 commit comments

Comments
 (0)