Skip to content
Draft
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
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: ./bin/check-images.sh
shellcheck:
timeout-minutes: 2
runs-on: ubutun-latest
steps:
- uses: actions/checkout@v4
- run: sudo apt-get install shellcheck
- run: ./bin/check-scripts.sh
e2e-tests:
timeout-minutes: 120
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions bin/check-images.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -eu
set -o pipefail
shopt -s inherit_errexit

log() {
echo "[check-images] $*"
Expand Down
78 changes: 78 additions & 0 deletions bin/check-scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash -eu
set -o pipefail
shopt -s inherit_errexit

log() { echo >&2 "[$(basename "$0")] $*"; }

expectedShebang=$'#!/bin/bash -eu\nset -o pipefail\nshopt -s inherit_errexit\n'

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."

log " Checking shebang..."
shebang="$(head -n3 "$script")"
if ! diff <(echo "$shebang") <(printf '%s' "$expectedShebang"); then
log " !!!"
log " !!! Missing or unexpected shebang."
log " !!!"
log " !!! To make reasoning about script behaviour easier, please"
log " !!! use the standard shebang and shell config lines:"
log " !!!"
echo
printf '%s' "$expectedShebang"
echo
exit 1
fi
log " Passed OK."

log " Checking for indirect invocations..."
# shellcheck disable=2086
if git grep -E "sh.*$(basename "$script")" $scriptFiles; then
log " !!!"
log " !!! Possible indirect invocation(s) found."
log " !!!"
log " !!! Invoking scripts indirectly means they may be run with an"
log " !!! unexpected shell. Try invoking the script directly and"
log " !!! relying on its shebang."
log " !!!"
exit 1
fi
log " Passed OK."
done

log "Running shellcheck..."
echo "$scriptFiles" | xargs \
shellcheck \
--exclude=SC2038
log " Shellcheck passed OK."

log "All scripts passed OK."
8 changes: 5 additions & 3 deletions e2e-tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash -eu
set -o pipefail
shopt -s inherit_errexit

log() {
echo "[e2e-tester] $*"
Expand Down Expand Up @@ -57,11 +59,11 @@ if [[ ${CI-} = true ]]; then
sudo apt-get install -y wait-for-it

log "Waiting for ODK Central to start..."
wait-for-it $ODK_DOMAIN:$ODK_PORT --strict --timeout=60 -- echo '[e2e-tester] odk-central is UP!'
wait-for-it "$ODK_DOMAIN:$ODK_PORT" --strict --timeout=60 -- echo '[e2e-tester] odk-central is UP!'

log "Creating test users..."
docker compose exec service bash -c "echo $ODK_PASSWORD | node lib/bin/cli.js --email $ODK_USER user-create"
docker compose exec service node lib/bin/cli.js --email $ODK_USER user-promote
docker compose exec service bash -c "echo '$ODK_PASSWORD' | node lib/bin/cli.js --email '$ODK_USER' user-create"
docker compose exec service node lib/bin/cli.js --email "$ODK_USER" user-promote
log "Test user created."
cd client
fi
Expand Down
5 changes: 3 additions & 2 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -eu
set -o pipefail
shopt -s inherit_errexit

# Normally, index.html is housed at the root of the repository for Vite, but
# here we move it to public/, where Vue CLI expects it.
Expand Down Expand Up @@ -27,14 +28,14 @@ for pattern in "$@"; do
# warnings; and warnings from Karma.
set -- -F -e 'WARN LOG:' -e 'ERROR LOG:' -e 'Module Warning' -e 'WARN [web-server]:' "$output"
warnings=$(grep -c "$@")
if (( $warnings > 2)); then
if (( warnings > 2)); then
grep -C5 "$@"
# Reset the text format in case the search results contained formatted text.
tput sgr0
echo
echo "All tests passed, but there were $warnings warnings: see above."
exit 1
elif (( $warnings > 0 )); then
elif (( warnings > 0 )); then
echo "There were $warnings warnings, which is within the accepted threshold."
fi

Expand Down
Loading