Skip to content

Commit

Permalink
Fix/handle all shellcheck findings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bast <[email protected]>
  • Loading branch information
dbast committed Nov 29, 2024
1 parent 0049fb8 commit a43e791
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 32 deletions.
1 change: 0 additions & 1 deletion cancel/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ cd "$(dirname "$0")" || exit

set -uxo pipefail
tilt ci > tilt.log &
TILT_PID=$!

sleep 1
timeout 30 tail -f tilt.log | grep -q "uibutton.tilt.dev/sleep:update:cancel created"
Expand Down
1 change: 1 addition & 0 deletions cancel/test/trigger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

YAML=$(tilt get uibutton "sleep:update:cancel" -o yaml)
TIME=$(date '+%FT%T.000000Z')
# shellcheck disable=SC2001
NEW_YAML=$(echo "$YAML" | sed "s/lastClickedAt.*/lastClickedAt: $TIME/g")

# Currently, kubectl doesn't support subresource APIs.
Expand Down
16 changes: 8 additions & 8 deletions get_obj/test/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

cd "$(dirname "$0")"
cd "$(dirname "$0")" || exit

# Spinning up initial test deployment
tilt ci -f setup.Tiltfile
Expand All @@ -17,7 +17,7 @@ RESULT=$?
if [[ $RESULT -ne 0 ]];then
echo "ERROR: App failed to start"
cat tilt.log
exit $RESULT
exit "$RESULT"
fi

echo "Verifying remote development is using the correct image built from Dockerfile.dev"
Expand All @@ -36,7 +36,7 @@ RESULT=$?
if [[ $RESULT -ne 0 ]];then
echo "ERROR: File sync doesn't work"
cat tilt.log
exit $RESULT
exit "$RESULT"
fi

echo "Verifying that port forwarding was enabled"
Expand All @@ -45,23 +45,23 @@ RESULT=$?
if [[ $RESULT -ne 0 ]];then
echo "ERROR: Port forwarding wasn't enabled"
cat tilt.log
exit $RESULT
exit "$RESULT"
fi

echo "Verifying that livenessProbe was removed"
RESULT=$(kubectl get deployment/example-nodejs -o yaml | grep "livenessProbe" | wc -l)
RESULT=$(kubectl get deployment/example-nodejs -o yaml | grep -c "livenessProbe")
if [[ $RESULT -ne 0 ]];then
echo "ERROR: livenessProbe wasn't removed"
kubectl get deployment/example-nodejs -o yaml
exit $RESULT
exit "$RESULT"
fi

echo "Verifying that readinessProbe was removed"
RESULT=$(kubectl get deployment/example-nodejs -o yaml | grep "readinessProbe" | wc -l)
RESULT=$(kubectl get deployment/example-nodejs -o yaml | grep -c "readinessProbe")
if [[ $RESULT -ne 0 ]];then
echo "ERROR: readinessProbe wasn't removed"
kubectl get deployment/example-nodejs -o yaml
exit $RESULT
exit "$RESULT"
fi

cat tilt.log
Expand Down
2 changes: 1 addition & 1 deletion kubefwd/run-kubefwd-internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
set -euo pipefail

flags=()
while read namespace; do
while read -r namespace; do
if [[ "$namespace" == "" ]]; then
continue
fi
Expand Down
1 change: 1 addition & 0 deletions kubefwd/sudo-kubefwd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ chmod a+rw "$TRIGGER"
"$DIR/watch-namespaces.sh" "$TRIGGER" &
WATCH_PID="$!"

# shellcheck disable=SC2317
function cleanup {
set -x
set +e
Expand Down
1 change: 1 addition & 0 deletions ngrok/ngrok-reconcile-uiresource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ links="$(tilt get uiresource -o jsonpath='{range .status.endpointLinks[*]}{.url}
for link in $links;
do
host="localhost"
# shellcheck disable=SC2001
port="$(echo "$link" | sed -e "s|^http://$host:\([0-9]*\).*|\1|")"
if [[ "$port" != "$link" ]]; then
ports+=("$port")
Expand Down
3 changes: 3 additions & 0 deletions pypiserver/src/build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

if [[ $# -eq 1 ]]; then
printf "Specify path to the package"
exit 1
Expand All @@ -12,4 +14,5 @@ if [[ $# -eq 2 ]]; then
cmd="${cmd} upload -r ${2}"
fi

# shellcheck disable=SC2086
python3 ${cmd}
3 changes: 2 additions & 1 deletion restart_process/test/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM alpine
# distro with bash required as start.sh contains bash specific code
FROM debian:bookworm-slim

RUN echo 0 > restart_count.txt

Expand Down
4 changes: 3 additions & 1 deletion restart_process/test/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash
# bash shebang required as we are using bash specific features: pipefail + trap

set -euo pipefail
RESTART_COUNT="$(cat restart_count.txt)"
echo "RESTART_COUNT: $RESTART_COUNT"
Expand Down
5 changes: 2 additions & 3 deletions restart_process/test/trigger_custom_deploy_live_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ set -u
touch start.sh
# seconds
TIMEOUT=10
for ((i=0;i<=$TIMEOUT;++i)) do
tilt logs | grep -v test_update | grep -q "RESTART_COUNT: 1"
if [[ $? -eq 0 ]]; then
for ((i=0;i<=TIMEOUT;++i)) do
if tilt logs | grep -v test_update | grep -q "RESTART_COUNT: 1"; then
echo restart detected
exit 0
fi
Expand Down
1 change: 1 addition & 0 deletions syncback/krsync-callback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ fi

# $K8S_OBJECT is intentionally not quoted here so -n/-c flags can be
# parsed by kubectl
# shellcheck disable=SC2086
exec kubectl exec -i $K8S_OBJECT -- "$@"

17 changes: 11 additions & 6 deletions syncback/krsync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,31 @@ install_rsync_tilt() {
set +e # disable exit on error
# $K8S_OBJECT is intentionally not quoted here so -n/-c flags can be
# parsed by kubectl
# shellcheck disable=SC2086
kubectl exec $K8S_OBJECT -- ls "$RSYNC_TILT_PATH" > /dev/null 2>&1
exit_code="$?"
set -e
if [[ "$exit_code" != "0" ]]; then
# shellcheck disable=SC2002
echo "installing tilt's rsync"
cat "$KRSYNC_TAR_PATH" | kubectl exec -i $K8S_OBJECT -- tar -xf - -C $(dirname $RSYNC_TILT_PATH)
# shellcheck disable=SC2086,SC2002
cat "$KRSYNC_TAR_PATH" | kubectl exec -i $K8S_OBJECT -- tar -xf - -C "$(dirname $RSYNC_TILT_PATH)"
fi
}

find_rsync_path() {
local rsync_path=--rsync-path=$RSYNC_TILT_PATH
# see if we already have a compatible rsync on the container
# shellcheck disable=SC2086,SC2181
rsync_output=$(kubectl exec $K8S_OBJECT -- rsync --version 2> /dev/null)
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
detected_rsync_version=$(echo "$rsync_output" | head -1 | awk '{ print $3 }')
if [[ "$detected_rsync_version" > 3 ]]; then
# bash cannot compare versions, like 3.3.0 with 3. So we use sort -V:
if [[ $(printf "%s\n%s\n" "$detected_rsync_version" "3" | sort -V | head -n 1) == "3" ]]; then
rsync_path=
fi
fi
echo $rsync_path
echo "$rsync_path"
}

# Quote/set to the entire first argument, which could contain
Expand All @@ -58,6 +62,7 @@ export RSYNC_TILT_PATH="$2"
export KRSYNC_TAR_PATH="${0%/*}/rsync.tilt.tar"
shift
shift
export RSYNC_PATH=$(find_rsync_path)
RSYNC_PATH=$(find_rsync_path)
export RSYNC_PATH
install_rsync_tilt
exec rsync $RSYNC_PATH --blocking-io --rsh "$krsync_callback_path" "$@"
exec rsync "$RSYNC_PATH" --blocking-io --rsh "$krsync_callback_path" "$@"
18 changes: 9 additions & 9 deletions syncback/test/test.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash

cd "$(dirname "$0")"
cd "$(dirname "$0")" || exit

set -ex
tilt ci $@
tilt ci "$@"
syncback_dir=$(cat syncback-dir.txt)
test -f $syncback_dir/python/main.py
test ! -f $syncback_dir/python/example.txt
test -f $syncback_dir/ruby/main.rb
test ! -f $syncback_dir/ruby/example.txt
test -f $syncback_dir/rsync/rsync.txt
test ! -f $syncback_dir/rsync/example.txt
test -f "$syncback_dir"/python/main.py
test ! -f "$syncback_dir"/python/example.txt
test -f "$syncback_dir"/ruby/main.rb
test ! -f "$syncback_dir"/ruby/example.txt
test -f "$syncback_dir"/rsync/rsync.txt
test ! -f "$syncback_dir"/rsync/example.txt
# Test that rsync was copied for containers that needed it
kubectl exec -n syncback-test -c python deploy/syncback-containers -- sh -c "[ -f /bin/rsync.tilt ]"
kubectl exec -n syncback-test -c ruby deploy/syncback-containers -- sh -c "[ -f /bin/rsync.tilt ]"
Expand All @@ -20,4 +20,4 @@ kubectl exec -n syncback-test -c rsync deploy/syncback-containers -- sh -c "[ !
test -f syncback-button.txt -a "$(cat syncback-button.txt)" = syncback-containers

tilt down --delete-namespaces
rm -rf $syncback_dir syncback-dir.txt syncback-button.txt
rm -rf "$syncback_dir" syncback-dir.txt syncback-button.txt
6 changes: 5 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

# `git ls-files` instead of `find` to ensure we skip stuff like .git and ./git_resource/test/.git-sources
files = subprocess.check_output(["git", "ls-files", "**/test.sh"]).decode('utf-8').splitlines()
tests = []
for f in files:

# don't re-execute itself
Expand All @@ -82,5 +83,8 @@
print("dry run: %s" % f)
continue

print("running %s" % f)
tests.append(f)

for count, f in enumerate(tests):
print("running %d/%d: %s" % (count + 1, len(tests), f))
subprocess.check_call([f])
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# find all scripts named 'test.sh' and run them
# fail immediately if any fail

cd "$(dirname "$0")"
cd "$(dirname "$0")" || exit
exec python3 ./test.py

0 comments on commit a43e791

Please sign in to comment.