85 lines
2.5 KiB
Bash
Executable File
85 lines
2.5 KiB
Bash
Executable File
#! /bin/bash
|
|
|
|
SCRIPTDIR="$(dirname "$0")"
|
|
|
|
# Used to find executable from several likely locations
|
|
# Pass any number of arguments, returns the first one that's
|
|
# an executable file. If a file exists but is not executable,
|
|
# a warning is printed
|
|
# Output is in the form of "WARNING:\nresult" so if exit code is 0 you can safely fetch the last line to find the result
|
|
findBin () {
|
|
#if [ $# -eq 0 ]; exit; fi
|
|
while [ ! $# -eq 0 ]; do
|
|
# Resolve symlinks
|
|
f="$(readlink -m "$1")"
|
|
shift
|
|
if [ ! -f "$f" ]; then continue; fi
|
|
if [ ! -x "$f" ]; then
|
|
echo "WARNING: "$f" exists but is not executable" >&2
|
|
continue
|
|
fi
|
|
echo "$f"
|
|
return
|
|
done
|
|
# nothing found
|
|
return 1
|
|
}
|
|
|
|
if [ -z "$1" ]; then
|
|
output="$(findBin "$SCRIPTDIR"/server "$SCRIPTDIR"/../server)"
|
|
if [ $? -eq 0 ]; then
|
|
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
|
|
export FORGEHOOKENDPOINT="$output"
|
|
else
|
|
# Some warnings, print but use result from last line
|
|
echo "$output" | head -n -1
|
|
export FORGEHOOKENDPOINT="$(echo "$output" | tail -n 1)"
|
|
fi
|
|
else
|
|
echo "ERROR: Could not find webhook endpoint server starting script. Output:"
|
|
echo "$output"
|
|
exit 1
|
|
fi
|
|
else
|
|
export FORGEHOOKENDPOINT="$1"
|
|
fi
|
|
|
|
if [ -z "$2" ]; then
|
|
# First try symlink from script dir
|
|
# Second try compiled version from parent repo (endpoint implementation) in whck submodule
|
|
# Third try compiled version from whck folder in grandparent folder (eg. when called from
|
|
# forge/endpoints.php/spec/test_web.sh to find forge/whck/target/*/whck)
|
|
output="$(findBin \
|
|
"$SCRIPTDIR"/whck \
|
|
"$SCRIPTDIR"/../whck/target/release/whck \
|
|
"$SCRIPTDIR"/../whck/target/debug/whck \
|
|
"$SCRIPTDIR"/../../whck/target/release/whck \
|
|
"$SCRIPTDIR"/../../whck/target/debug/whck \
|
|
)"
|
|
if [ $? -eq 0 ]; then
|
|
if [[ "$(echo "$output" | wc -l)" == "1" ]]; then
|
|
export WHCK="$output"
|
|
else
|
|
# Some warnings, print but use result from last line
|
|
echo "$output" | head -n -1
|
|
export WHCK="$(echo "$output" | tail -n 1)"
|
|
fi
|
|
else
|
|
echo "ERROR: Could not find webhook check program (whck). Output:"
|
|
echo "$output"
|
|
exit 1
|
|
fi
|
|
else
|
|
export WHCK="$2"
|
|
fi
|
|
|
|
ORIGDIR="$(pwd)"
|
|
cd "$SCRIPTDIR"
|
|
|
|
export FORGEHOOK="$(pwd)/tests/mock-forgehook.sh"
|
|
export FORGEHOOKNOTIFY=/bin/true
|
|
|
|
bats tests/web/*.bats
|
|
|
|
cd "$ORIGDIR"
|