Skip to content

Commit 4fa53b4

Browse files
authored
[chore](workflow) Add shellcheck to check shell scripts (#11744)
1 parent 355b7c0 commit 4fa53b4

30 files changed

Lines changed: 1854 additions & 1327 deletions

.github/actions/action-sh-checker

Submodule action-sh-checker added at edd0e45

.github/workflows/shellcheck.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: ShellCheck
19+
20+
on: [push, pull_request]
21+
22+
jobs:
23+
shellcheck:
24+
name: ShellCheck
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout ${{ github.ref }} ( ${{ github.sha }} )
28+
uses: actions/checkout@v3
29+
with:
30+
submodules: recursive
31+
32+
- name: Run ShellCheck
33+
uses: ./.github/actions/action-sh-checker
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
with:
37+
sh_checker_comment: true
38+
sh_checker_exclude: .git .github ^thirdparty/src ^thirdparty/installed ^ui ^docs/node_modules ^tools/ssb-tools ^tools/tpch-tools ^tools/clickbench-tools ^extension ^output ^fs_brokers/apache_hdfs_broker/output

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@
1919
[submodule ".github/actions/ccache-action"]
2020
path = .github/actions/ccache-action
2121
url = https://github.com/hendrikmuhs/ccache-action
22+
[submodule ".github/actions/action-sh-checker"]
23+
path = .github/actions/action-sh-checker
24+
url = https://github.com/luizm/action-sh-checker

.shellcheckrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
source-path=SCRIPTDIR
19+
source-path=SCRIPTDIR/..
20+
source-path=SCRIPTDIR/../..
21+
source-path=thirdparty
22+
23+
external-sources=true
24+
25+
enable=all
26+
disable=SC2310
27+
disable=SC2312

bin/start_be.sh

Lines changed: 86 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616
# specific language governing permissions and limitations
1717
# under the License.
1818

19-
curdir=$(dirname "$0")
20-
curdir=$(
21-
cd "$curdir"
22-
pwd
23-
)
19+
set -eo pipefail
20+
21+
curdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
2422

25-
OPTS=$(getopt \
26-
-n $0 \
23+
OPTS="$(getopt \
24+
-n "$0" \
2725
-o '' \
2826
-l 'daemon' \
29-
-- "$@")
27+
-- "$@")"
3028

31-
eval set -- "$OPTS"
29+
eval set -- "${OPTS}"
3230

3331
RUN_DAEMON=0
3432
RUN_IN_AWS=0
@@ -53,145 +51,151 @@ while true; do
5351
esac
5452
done
5553

56-
export DORIS_HOME=$(
57-
cd "$curdir/.."
54+
DORIS_HOME="$(
55+
cd "${curdir}/.."
5856
pwd
59-
)
57+
)"
58+
export DORIS_HOME
6059

61-
MAX_MAP_COUNT=`sysctl -n vm.max_map_count`
62-
if [ $MAX_MAP_COUNT -lt 2000000 ]; then
60+
MAX_MAP_COUNT="$(sysctl -n vm.max_map_count)"
61+
if [[ "${MAX_MAP_COUNT}" -lt 2000000 ]]; then
6362
echo "Please set vm.max_map_count to be 2000000. sysctl -w vm.max_map_count=2000000"
6463
exit 1
6564
fi
6665

6766
# add libs to CLASSPATH
68-
for f in $DORIS_HOME/lib/*.jar; do
69-
if [ ! -n "${DORIS_JNI_CLASSPATH_PARAMETER}" ]; then
70-
export DORIS_JNI_CLASSPATH_PARAMETER=$f
71-
else
72-
export DORIS_JNI_CLASSPATH_PARAMETER=$f:${DORIS_JNI_CLASSPATH_PARAMETER}
73-
fi
67+
for f in "${DORIS_HOME}/lib"/*.jar; do
68+
if [[ -z "${DORIS_JNI_CLASSPATH_PARAMETER}" ]]; then
69+
export DORIS_JNI_CLASSPATH_PARAMETER="${f}"
70+
else
71+
export DORIS_JNI_CLASSPATH_PARAMETER="${f}:${DORIS_JNI_CLASSPATH_PARAMETER}"
72+
fi
7473
done
7574
# DORIS_JNI_CLASSPATH_PARAMETER is used to configure additional jar path to jvm. e.g. -Djava.class.path=$DORIS_HOME/lib/java-udf.jar
7675
export DORIS_JNI_CLASSPATH_PARAMETER="-Djava.class.path=${DORIS_JNI_CLASSPATH_PARAMETER}"
7776

7877
jdk_version() {
7978
local result
80-
local java_cmd=$JAVA_HOME/bin/java
79+
local java_cmd="${JAVA_HOME:-.}/bin/java"
8180
local IFS=$'\n'
82-
# remove \r for Cygwin
83-
local lines=$("$java_cmd" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n')
84-
if [[ -z $java_cmd ]]
85-
then
81+
82+
if [[ -z "${java_cmd}" ]]; then
8683
result=no_java
84+
return 1
8785
else
88-
for line in $lines; do
89-
if [[ (-z $result) && ($line = *"version \""*) ]]
90-
then
91-
local ver=$(echo $line | sed -e 's/.*version "\(.*\)"\(.*\)/\1/; 1q')
92-
# on macOS, sed doesn't support '?'
93-
if [[ $ver = "1."* ]]
94-
then
95-
result=$(echo $ver | sed -e 's/1\.\([0-9]*\)\(.*\)/\1/; 1q')
96-
else
97-
result=$(echo $ver | sed -e 's/\([0-9]*\)\(.*\)/\1/; 1q')
98-
fi
99-
fi
100-
done
86+
local version
87+
# remove \r for Cygwin
88+
version="$("${java_cmd}" -Xms32M -Xmx32M -version 2>&1 | tr '\r' '\n' | grep version | awk '{print $3}')"
89+
version="${version//\"/}"
90+
if [[ "${version}" =~ ^1\. ]]; then
91+
result="$(echo "${version}" | awk -F '.' '{print $2}')"
92+
else
93+
result="$(echo "${version}" | awk -F '.' '{print $1}')"
94+
fi
10195
fi
102-
echo "$result"
96+
echo "${result}"
97+
return 0
10398
}
10499

105100
jvm_arch="amd64"
106-
MACHINE_TYPE=$(uname -m)
101+
MACHINE_TYPE="$(uname -m)"
107102
if [[ "${MACHINE_TYPE}" == "aarch64" ]]; then
108103
jvm_arch="aarch64"
109104
fi
110-
java_version=$(jdk_version)
111-
if [[ $java_version -gt 8 ]]; then
112-
export LD_LIBRARY_PATH=$JAVA_HOME/lib/server:$JAVA_HOME/lib:$LD_LIBRARY_PATH
105+
java_version="$(
106+
set -e
107+
jdk_version
108+
)"
109+
if [[ "${java_version}" -gt 8 ]]; then
110+
export LD_LIBRARY_PATH="${JAVA_HOME}/lib/server:${JAVA_HOME}/lib:${LD_LIBRARY_PATH}"
113111
# JAVA_HOME is jdk
114-
elif [[ -d "$JAVA_HOME/jre" ]]; then
115-
export LD_LIBRARY_PATH=$JAVA_HOME/jre/lib/$jvm_arch/server:$JAVA_HOME/jre/lib/$jvm_arch:$LD_LIBRARY_PATH
112+
elif [[ -d "${JAVA_HOME}/jre" ]]; then
113+
export LD_LIBRARY_PATH="${JAVA_HOME}/jre/lib/${jvm_arch}/server:${JAVA_HOME}/jre/lib/${jvm_arch}:${LD_LIBRARY_PATH}"
116114
# JAVA_HOME is jre
117115
else
118-
export LD_LIBRARY_PATH=$JAVA_HOME/lib/$jvm_arch/server:$JAVA_HOME/lib/$jvm_arch:$LD_LIBRARY_PATH
116+
export LD_LIBRARY_PATH="${JAVA_HOME}/lib/${jvm_arch}/server:${JAVA_HOME}/lib/${jvm_arch}:${LD_LIBRARY_PATH}"
119117
fi
120118

121119
# export env variables from be.conf
122120
#
123121
# UDF_RUNTIME_DIR
124122
# LOG_DIR
125123
# PID_DIR
126-
export UDF_RUNTIME_DIR=${DORIS_HOME}/lib/udf-runtime
127-
export LOG_DIR=${DORIS_HOME}/log
128-
export PID_DIR=$(
129-
cd "$curdir"
124+
export UDF_RUNTIME_DIR="${DORIS_HOME}/lib/udf-runtime"
125+
export LOG_DIR="${DORIS_HOME}/log"
126+
PID_DIR="$(
127+
cd "${curdir}"
130128
pwd
131-
)
129+
)"
130+
export PID_DIR
132131

133132
# set odbc conf path
134-
export ODBCSYSINI=$DORIS_HOME/conf
133+
export ODBCSYSINI="${DORIS_HOME}/conf"
135134

136135
# support utf8 for oracle database
137-
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
136+
export NLS_LANG='AMERICAN_AMERICA.AL32UTF8'
138137

139138
#filter known leak for lsan.
140-
export LSAN_OPTIONS=suppressions=${DORIS_HOME}/conf/asan_suppr.conf
141-
142-
while read line; do
143-
envline=$(echo $line | sed 's/[[:blank:]]*=[[:blank:]]*/=/g' | sed 's/^[[:blank:]]*//g' | egrep "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=")
144-
envline=$(eval "echo $envline")
145-
if [[ $envline == *"="* ]]; then
146-
eval 'export "$envline"'
139+
export LSAN_OPTIONS="suppressions=${DORIS_HOME}/conf/asan_suppr.conf"
140+
141+
while read -r line; do
142+
envline="$(echo "${line}" |
143+
sed 's/[[:blank:]]*=[[:blank:]]*/=/g' |
144+
sed 's/^[[:blank:]]*//g' |
145+
grep -E "^[[:upper:]]([[:upper:]]|_|[[:digit:]])*=" ||
146+
true)"
147+
envline="$(eval "echo ${envline}")"
148+
if [[ "${envline}" == *"="* ]]; then
149+
eval 'export "${envline}"'
147150
fi
148-
done < $DORIS_HOME/conf/be.conf
151+
done <"${DORIS_HOME}/conf/be.conf"
149152

150-
if [ -e $DORIS_HOME/bin/palo_env.sh ]; then
151-
source $DORIS_HOME/bin/palo_env.sh
153+
if [[ -e "${DORIS_HOME}/bin/palo_env.sh" ]]; then
154+
# shellcheck disable=1091
155+
source "${DORIS_HOME}/bin/palo_env.sh"
152156
fi
153157

154-
if [ ! -d $LOG_DIR ]; then
155-
mkdir -p $LOG_DIR
158+
if [[ ! -d "${LOG_DIR}" ]]; then
159+
mkdir -p "${LOG_DIR}"
156160
fi
157161

158-
if [ ! -d $UDF_RUNTIME_DIR ]; then
159-
mkdir -p ${UDF_RUNTIME_DIR}
162+
if [[ ! -d "${UDF_RUNTIME_DIR}" ]]; then
163+
mkdir -p "${UDF_RUNTIME_DIR}"
160164
fi
161165

162-
rm -f ${UDF_RUNTIME_DIR}/*
166+
rm -f "${UDF_RUNTIME_DIR}"/*
163167

164-
pidfile=$PID_DIR/be.pid
168+
pidfile="${PID_DIR}/be.pid"
165169

166-
if [ -f $pidfile ]; then
167-
if kill -0 $(cat $pidfile) > /dev/null 2>&1; then
168-
echo "Backend running as process $(cat $pidfile). Stop it first."
170+
if [[ -f "${pidfile}" ]]; then
171+
if kill -0 "$(cat "${pidfile}")" >/dev/null 2>&1; then
172+
echo "Backend running as process $(cat "${pidfile}"). Stop it first."
169173
exit 1
170174
else
171-
rm $pidfile
175+
rm "${pidfile}"
172176
fi
173177
fi
174178

175-
chmod 755 ${DORIS_HOME}/lib/doris_be
176-
echo "start time: "$(date) >> $LOG_DIR/be.out
179+
chmod 755 "${DORIS_HOME}/lib/doris_be"
180+
echo "start time: $(date)" >>"${LOG_DIR}/be.out"
177181

178-
if [ ! -f /bin/limit3 ]; then
179-
LIMIT=
182+
if [[ ! -f '/bin/limit3' ]]; then
183+
LIMIT=''
180184
else
181185
LIMIT="/bin/limit3 -c 0 -n 65536"
182186
fi
183187

184188
## If you are not running in aws cloud, disable this env since https://github.com/aws/aws-sdk-cpp/issues/1410.
185-
if [ ${RUN_IN_AWS} -eq 0 ]; then
189+
if [[ "${RUN_IN_AWS}" -eq 0 ]]; then
186190
export AWS_EC2_METADATA_DISABLED=true
187191
fi
188192

189193
## set hdfs conf
190-
export LIBHDFS3_CONF=${DORIS_HOME}/conf/hdfs-site.xml
194+
export LIBHDFS3_CONF="${DORIS_HOME}/conf/hdfs-site.xml"
191195

192-
if [ ${RUN_DAEMON} -eq 1 ]; then
193-
nohup $LIMIT ${DORIS_HOME}/lib/doris_be "$@" >> $LOG_DIR/be.out 2>&1 < /dev/null &
196+
if [[ "${RUN_DAEMON}" -eq 1 ]]; then
197+
nohup ${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" >>"${LOG_DIR}/be.out" 2>&1 </dev/null &
194198
else
195199
export DORIS_LOG_TO_STDERR=1
196-
$LIMIT ${DORIS_HOME}/lib/doris_be "$@" 2>&1 < /dev/null
200+
${LIMIT:+${LIMIT}} "${DORIS_HOME}/lib/doris_be" "$@" 2>&1 </dev/null
197201
fi

0 commit comments

Comments
 (0)