72 lines
2.6 KiB
Bash
72 lines
2.6 KiB
Bash
#!/bin/bash
|
|||
|
|
# Starts one Tinker Tickets instance for the UI tests on a fresh database:
|
||
|
|
#
|
||
|
|
# tests/ui/stack.sh <checkout-dir> <port> <db-name>
|
||
|
|
#
|
||
|
|
# Creates the database, writes the checkout's .env (throwaway values only),
|
||
|
|
# applies the checkout's migrations, loads the synthetic seed
|
||
|
|
# data and serves the checkout with PHP's built-in server. The seed and router
|
||
|
|
# always come from this script's directory, so the same data goes into the
|
||
|
|
# base branch's checkout for before/after screenshots.
|
||
|
|
#
|
||
|
|
# Needs a MariaDB on 127.0.0.1 with a 'tinker_ui' user (tests/ui/setup.sh in
|
||
|
|
# CI) and root access to it over the local socket. Logs go to
|
||
|
|
# <checkout>/.ui-stack/server.log.
|
||
|
|
set -euo pipefail
|
||
|
|
CHECKOUT=$(cd "${1:?checkout dir}" && pwd)
|
||
|
|
PORT=${2:?port}
|
||
|
|
DB=${3:?database name}
|
||
|
|
HERE=$(cd "$(dirname "$0")" && pwd)
|
||
|
|
|
||
|
|
case "$DB" in
|
||
|
|
tinker_ui*) ;;
|
||
|
|
*) echo "refusing: database name must start with tinker_ui" >&2; exit 2 ;;
|
||
|
|
esac
|
||
|
|
|
||
|
|
mariadb -e "DROP DATABASE IF EXISTS \`$DB\`; CREATE DATABASE \`$DB\`;
|
||
|
|
GRANT ALL ON \`$DB\`.* TO 'tinker_ui'@'127.0.0.1';"
|
||
|
|
|
||
|
|
if [ -e "$CHECKOUT/.env" ] && ! grep -q "^; tinker-ui-stack" "$CHECKOUT/.env"; then
|
||
|
|
echo "refusing: $CHECKOUT/.env exists and was not written by this script" >&2
|
||
|
|
exit 2
|
||
|
|
fi
|
||
|
|
cat > "$CHECKOUT/.env" <<EOF
|
||
|
|
; tinker-ui-stack: throwaway UI test settings, safe to delete
|
||
|
|
DB_HOST=127.0.0.1
|
||
|
|
DB_USER=tinker_ui
|
||
|
|
DB_PASS=ci-only
|
||
|
|
DB_NAME=$DB
|
||
|
|
LDAP_ENABLED=false
|
||
|
|
TIMEZONE=UTC
|
||
|
|
; One client IP makes every request in a test run; the default limits would
|
||
|
|
; turn later pages into 429s.
|
||
|
|
RATE_LIMIT_DEFAULT=100000
|
||
|
|
RATE_LIMIT_API=100000
|
||
|
|
RATE_LIMIT_IP=100000
|
||
|
|
RATE_LIMIT_IP_API=100000
|
||
|
|
EOF
|
||
|
|
|
||
|
|
# This branch's migration runner, run from inside the checkout so it reads
|
||
|
|
# that checkout's config and migrations: a base branch with an older runner
|
||
|
|
# (before the comment fix) still gets its schema.
|
||
|
|
cp "$HERE/../../migrations/migrate.php" "$CHECKOUT/migrations/.ui-migrate.php"
|
||
|
|
php "$CHECKOUT/migrations/.ui-migrate.php"
|
||
|
|
rm -f "$CHECKOUT/migrations/.ui-migrate.php"
|
||
|
|
DB_NAME=$DB php "$HERE/seed.php"
|
||
|
|
|
||
|
|
mkdir -p "$CHECKOUT/.ui-stack"
|
||
|
|
(cd "$CHECKOUT" && setsid php -S "127.0.0.1:$PORT" -t . "$HERE/router.php" \
|
||
|
|
> "$CHECKOUT/.ui-stack/server.log" 2>&1 &)
|
||
|
|
|
||
|
|
for _ in $(seq 1 30); do
|
||
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' -H 'Remote-User: ci.tester' -H 'Remote-Name: CI Tester' \
|
||
|
|
-H 'Remote-Email: ci@example.invalid' -H 'Remote-Groups: admin' "http://127.0.0.1:$PORT/" || true)
|
||
|
|
if [ "$code" = 200 ]; then
|
||
|
|
echo "Tinker Tickets ($CHECKOUT) on http://127.0.0.1:$PORT, database $DB"
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
sleep 1
|
||
|
|
done
|
||
|
|
echo "::error::Tinker Tickets did not answer on port $PORT (last HTTP ${code:-none})"
|
||
|
|
tail -n 50 "$CHECKOUT/.ui-stack/server.log" || true
|
||
|
|
exit 1
|