#!/bin/bash # Starts one Tinker Tickets instance for the UI tests on a fresh database: # # tests/ui/stack.sh # # 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 # /.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" < "$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