Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test/check-scripts: add checks to standardise whitespace #898

Merged
merged 4 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion files/enketo/generate-secrets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ fi
if [ ! -f /etc/secrets/enketo-api-key ]; then
LC_ALL=C tr -dc '[:alnum:]' < /dev/urandom | head -c128 > /etc/secrets/enketo-api-key
fi

1 change: 0 additions & 1 deletion files/prebuild/write-version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh

{ echo "versions:"; echo "$(git rev-parse HEAD) ($(git describe --tags))"; git submodule; } > /tmp/version.txt

1 change: 0 additions & 1 deletion files/service/scripts/process-backlog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

cd /usr/odk
/usr/local/bin/node lib/bin/process-backlog.js >/proc/1/fd/1 2>/proc/1/fd/2

1 change: 0 additions & 1 deletion files/service/scripts/purge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

cd /usr/odk
/usr/local/bin/node lib/bin/purge.js >/proc/1/fd/1 2>/proc/1/fd/2

1 change: 0 additions & 1 deletion files/service/scripts/reap-sessions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

cd /usr/odk
/usr/local/bin/node lib/bin/reap-sessions.js >/proc/1/fd/1 2>/proc/1/fd/2

1 change: 0 additions & 1 deletion files/service/scripts/run-analytics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

cd /usr/odk
/usr/local/bin/node lib/bin/run-analytics.js >/proc/1/fd/1 2>/proc/1/fd/2

1 change: 0 additions & 1 deletion files/service/scripts/start-odk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ echo "using $WORKER_COUNT worker(s) based on available memory ($MEMTOT).."

echo "starting server."
exec npx pm2-runtime ./pm2.config.js

31 changes: 31 additions & 0 deletions test/check-scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@ log() { echo >&2 "[$(basename "$0")] $*"; }

scriptFiles="$(cat <(git grep -El '^#!.*sh\b') <(git ls-files | grep -E '.sh$') | sort -u)"

for script in $scriptFiles; do
log "Checking $script ..."

log " Checking trailing whitespace on lines..."
if grep -E '\s+$' "$script"; then
log " !!! Whitespace found at end of line !!!"
exit 1
fi
log " Passed OK."

log " Checking trailing newline in files..."
if [[ -n "$(tail -c 1 < "$script")" ]]; then
log " !!! Missing final newline !!!"
exit 1
fi
if [[ -z "$(tail -c 2 < "$script")" ]]; then
log " !!! Blank lines at end of file !!!"
exit 1
fi
log " Passed OK."

log " Checking for tab-based indentation..."
if grep $'\t' "$script"; then
log " !!! Tab(s) found."
log " !!!"
log " !!! Please use spaces for indentation."
exit 1
fi
log " Passed OK."
done

log "Running shellcheck..."
echo "$scriptFiles" | xargs \
shellcheck \
Expand Down
2 changes: 1 addition & 1 deletion test/nginx/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wait_for_http_response() {
printf >&2 '❌\n'
log "!!! URL timed out: $url"
exit 1
fi
fi
}

log "Starting test services..."
Expand Down