Skip to content

Commit 68a1ec7

Browse files
authored
enable shell check and fix linting (#1177)
1 parent d87bcb9 commit 68a1ec7

12 files changed

+60
-51
lines changed

.github/workflows/pull_request.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
name: Soundness
1010
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
1111
with:
12-
shell_check_enabled: false
1312
format_check_enabled: false
1413
license_header_check_project_name: "Swift Distributed Actors"
1514
# We need to move to 6.0 here but have to fix the new warnings first

IntegrationTests/tests_01_cluster/shared.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ RED='\033[0;31m'
1717
RST='\033[0m'
1818

1919
function echoerr() {
20-
echo "${RED}$@${RST}" 1>&2;
20+
echo "${RED}$*${RST}" 1>&2;
2121
}
2222

2323
function _killall() {
2424
set +e
2525
local killall_app_name="$1"
2626
echo "> KILLALL: $killall_app_name"
27-
ps aux | grep ${killall_app_name} | awk '{ print $2 }' | xargs kill -9 # ignore-unacceptable-language
27+
pkill -f "${killall_app_name}"
2828
set -e
2929
}
3030

@@ -33,22 +33,22 @@ function wait_log_exists() {
3333
_expected_line="$2"
3434
if [[ "$#" -eq 3 ]]; then
3535
_max_spins="$3"
36-
max_spins=$(expr ${_max_spins} + 0)
36+
max_spins=$(("${_max_spins}" + 0))
3737
else
3838
max_spins=20
3939
fi
4040
spin=1 # spin counter
41-
while [[ $(cat ${_log_file} | grep "${_expected_line}" | wc -l) -ne 1 ]]; do
41+
while [[ $(grep -c "${_expected_line}" < "${_log_file}") -ne 1 ]]; do
4242
echo "---------------------------------------------------------------------------------------------------------"
43-
cat ${_log_file}
43+
cat "${_log_file}"
4444
echo "========================================================================================================="
4545

4646
sleep 1
4747
spin=$((spin+1))
4848
if [[ ${spin} -eq ${max_spins} ]]; then
4949
echoerr "Never saw enough '${_expected_line}' in logs."
50-
cat ${_log_file}
51-
exit -1
50+
cat "${_log_file}"
51+
exit 255
5252
fi
5353
done
5454

IntegrationTests/tests_01_cluster/test_01_suspend_causes_unreachable_unsuspend_causes_reachable.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,52 @@
1616
set -e
1717
#set -x # verbose
1818

19+
# shellcheck disable=SC2155
1920
declare -r my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20-
declare -r root_path="$my_path/.."
2121

2222
declare -r app_name='it_Clustered_swim_suspension_reachability'
2323

24-
source ${my_path}/shared.sh
24+
25+
# shellcheck source=IntegrationTests/tests_01_cluster/shared.sh
26+
source "${my_path}"/shared.sh
2527

2628
declare -r first_logs=/tmp/sact_first.out
2729
declare -r second_logs=/tmp/sact_second.out
2830
rm -f ${first_logs}
2931
rm -f ${second_logs}
3032

3133
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_suspension_reachability 7337 > ${first_logs} 2>&1 &
32-
declare -r first_pid=$(echo $!)
34+
# shellcheck disable=SC2155
35+
declare -r first_pid=$($!)
3336
wait_log_exists ${first_logs} 'Binding to: ' 200 # since it might be compiling again...
3437

3538
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_suspension_reachability 8228 127.0.0.1 7337 > ${second_logs} 2>&1 &
36-
declare -r second_pid=$(echo $!)
39+
# shellcheck disable=SC2155
40+
declare -r second_pid=$($!)
3741
wait_log_exists ${second_logs} 'Binding to: ' 200 # since it might be compiling again...
3842

3943
echo "Waiting nodes to become .up..."
4044
wait_log_exists ${first_logs} 'Event: membershipChange(sact://System@127.0.0.1:8228 :: \[joining\] -> \[ up\])' 50
4145
echo 'Second member seen .up, good...'
4246

4347
# suspend the second process, causing unreachability
44-
kill -SIGSTOP ${second_pid} # ignore-unacceptable-language
48+
kill -SIGSTOP "${second_pid}" # ignore-unacceptable-language
4549
jobs
4650

4751
wait_log_exists ${first_logs} 'Event: reachabilityChange(DistributedCluster.Cluster.ReachabilityChange.*127.0.0.1:8228, status: up, reachability: unreachable' 50
4852
echo 'Second member seen .unreachable, good...'
4953

5054
# resume it in the background
51-
kill -SIGCONT ${second_pid} # ignore-unacceptable-language
55+
kill -SIGCONT "${second_pid}" # ignore-unacceptable-language
5256

5357
# it should become reachable again
54-
declare -r expected_second_member_unreachable=
5558
wait_log_exists ${first_logs} 'Event: reachabilityChange(DistributedCluster.Cluster.ReachabilityChange.*127.0.0.1:8228, status: up, reachability: reachable' 50
5659
echo 'Second member seen .unreachable, good...'
5760

5861

5962
# === cleanup ----------------------------------------------------------------------------------------------------------
6063

61-
kill -9 ${first_pid} # ignore-unacceptable-language
62-
kill -9 ${second_pid} # ignore-unacceptable-language
64+
kill -9 "${first_pid}" # ignore-unacceptable-language
65+
kill -9 "${second_pid}" # ignore-unacceptable-language
6366

6467
_killall ${app_name} # ignore-unacceptable-language

IntegrationTests/tests_01_cluster/test_02_ungraceful_shutdown_recovery.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
set -e
1717
#set -x # verbose
1818

19+
# shellcheck disable=SC2155
1920
declare -r my_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
20-
declare -r root_path="$my_path/.."
2121

2222
declare -r app_name='it_Clustered_swim_ungraceful_shutdown'
2323

24-
source ${my_path}/shared.sh
24+
25+
# shellcheck source=IntegrationTests/tests_01_cluster/shared.sh
26+
source "${my_path}"/shared.sh
2527

2628
declare -r first_logs=/tmp/sact_first.out
2729
declare -r second_logs=/tmp/sact_second.out
@@ -33,15 +35,18 @@ rm -f ${killed_logs}
3335
rm -f ${replacement_logs}
3436

3537
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_ungraceful_shutdown Frist 7337 > ${first_logs} 2>&1 &
36-
declare -r first_pid=$(echo $!)
38+
# shellcheck disable=SC2155
39+
declare -r first_pid=$($!)
3740
wait_log_exists ${first_logs} 'Binding to: ' 200 # since it might be compiling again...
3841

3942
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_ungraceful_shutdown Second 8228 127.0.0.1 7337 > ${second_logs} 2>&1 &
40-
declare -r second_pid=$(echo $!)
43+
# shellcheck disable=SC2155
44+
declare -r second_pid=$($!)
4145
wait_log_exists ${second_logs} 'Binding to: ' 200 # since it might be compiling again...
4246

4347
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_ungraceful_shutdown Killed 9119 127.0.0.1 7337 > ${killed_logs} 2>&1 & # ignore-unacceptable-language
44-
declare -r killed_pid=$(echo $!) # ignore-unacceptable-language
48+
# shellcheck disable=SC2155
49+
declare -r killed_pid=$($!) # ignore-unacceptable-language
4550
wait_log_exists ${killed_logs} 'Binding to: ' 200 # since it might be compiling again...
4651

4752
echo "Waiting nodes to become .up..."
@@ -53,11 +58,12 @@ sleep 1
5358

5459
# SIGKILL the third member, causing ungraceful shutdown
5560
echo "Killing PID ${killed_pid}" # ignore-unacceptable-language
56-
kill -9 ${killed_pid} # ignore-unacceptable-language
61+
kill -9 "${killed_pid}" # ignore-unacceptable-language
5762

5863
# Immediately restart the third process
5964
stdbuf -i0 -o0 -e0 swift run it_Clustered_swim_ungraceful_shutdown Replacement 9119 127.0.0.1 7337 >> ${replacement_logs} 2>&1 &
60-
declare -r replacement_pid=$(echo $!)
65+
# shellcheck disable=SC2155
66+
declare -r replacement_pid=$($!)
6167
wait_log_exists ${replacement_logs} 'Binding to: ' 200 # just to be safe...
6268

6369
# The original third node should go .down while the replacement becomes .up
@@ -68,8 +74,8 @@ echo 'Replacement member .up, good...'
6874

6975
# === cleanup ----------------------------------------------------------------------------------------------------------
7076

71-
kill -9 ${first_pid} # ignore-unacceptable-language
72-
kill -9 ${second_pid} # ignore-unacceptable-language
73-
kill -9 ${replacement_pid} # ignore-unacceptable-language
77+
kill -9 "${first_pid}" # ignore-unacceptable-language
78+
kill -9 "${second_pid}" # ignore-unacceptable-language
79+
kill -9 "${replacement_pid}" # ignore-unacceptable-language
7480

7581
_killall ${app_name}

scripts/dev/diff_update_license_header_year.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ set -e
1818
# Diffs with main and updates any files that differ from it.
1919
# Useful to keep copyright years up to date.
2020

21-
diff main --name-only | while IFS= read file; do
21+
diff main --name-only | while IFS= read -r file; do
2222
echo "Update copyright year in: ${file}"
23-
sed -i .bak 's/2018 Apple Inc./2019 Apple Inc./g' ${file};
23+
sed -i .bak 's/2018 Apple Inc./2019 Apple Inc./g' "${file}";
2424
rm "${file}.bak"
2525
done

scripts/dev/find_test_failures.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ failures_count=0
2222
failures=()
2323

2424
IFS=$'\n'
25-
fails=$(cat $logs | grep -n "' failed (")
25+
fails=$(grep -n "' failed (" < "$logs")
2626
for fail in $fails; do
2727
printf "\033[0;31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\033[0m\n"
28-
printf "\033[0;31m$fail\033[0m\n"
28+
printf "\033[0;31m%s\033[0m\n" "$fail"
2929

3030
failures+=( "$fail" )
31-
test_name=$(echo $fail | awk '{ print $3 }')
32-
logs_stop_line=$(echo $fail | awk '{ print $1 }' | awk 'BEGIN { FS = ":" } ; { print $1 }')
33-
logs_start_line=$(cat $logs | grep -n "$test_name started at" | awk 'BEGIN { FS = ":" } { print $1 }')
31+
test_name=$(echo "$fail" | awk '{ print $3 }')
32+
logs_stop_line=$(echo "$fail" | awk '{ print $1 }' | awk 'BEGIN { FS = ":" } ; { print $1 }')
33+
logs_start_line=$(grep -n "$test_name started at" < "$logs" | awk 'BEGIN { FS = ":" } { print $1 }')
3434

35-
tail -n +${logs_start_line} $logs | head -n $(expr $logs_stop_line - $logs_start_line)
35+
tail -n +"${logs_start_line}" "$logs" | head -n "$(("$logs_stop_line" - "$logs_start_line"))"
3636
failures_count+=1
3737
done
3838

@@ -41,11 +41,11 @@ if [[ "$failures_count" -ne 0 ]]; then
4141
printf "\033[0;31mFAILED TESTS: \033[0m\n"
4242

4343
for failure in "${failures[@]}" ; do
44-
printf "\033[0;31m - $failure \033[0m\n"
44+
printf "\033[0;31m - %s \033[0m\n" "$failure"
4545

4646
done
4747

4848
printf "\033[0;31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\033[0m\n"
4949

50-
exit -1
50+
exit 255
5151
fi

scripts/dev/sact_backtrace_atos.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ BIN=$1
5555
PID=$2
5656
# PID=$(ps aux | grep "SampleLetItCrash" | grep -v "grep" | awk '{print $2}')
5757

58-
while read line
58+
while read -r line
5959
do
6060
address="$(echo "$line" | awk '{ print $3 }')"
61-
source_pos=$(atos -p $PID -o $BIN -fullPath $address 2> /dev/null)
61+
source_pos=$(atos -p "$PID" -o "$BIN" -fullPath "$address" 2> /dev/null)
6262

6363
echo -n "$line" | awk 'BEGIN{} { printf "%s\t%s\t%s\t atos:", $1, $2, $3 }'
6464
echo -e "$CYAN$source_pos$NC"

scripts/dev/sact_backtrace_demangle.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
CYAN='\033[0;36m'
4242
NC='\033[0m' # No Color
4343

44-
while read line
44+
while read -r line
4545
do
4646
mangled=$(echo "$line" | awk '{ print $4 }')
4747
de_mangled=$(echo "$mangled" | swift demangle)

scripts/dev/until_failure.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
##
1414
##===----------------------------------------------------------------------===##
1515

16-
while $@; do :; done
16+
while "$@"; do :; done

scripts/dump_actors.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
##===----------------------------------------------------------------------===##
1515

1616
# The output of this is important for InspectKit so change it very carefully and adjust InspectKit whenever this script changes
17+
# shellcheck disable=SC2009
1718
ps aux | grep distributed-actors | grep xctest | head -n1 | awk '{print $2}' | xargs swift-inspect dump-concurrency | grep DistributedCluster | sort

0 commit comments

Comments
 (0)