#!/bin/sh set -eu ROOT=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd) cd "$ROOT" if [ ! -f "$ROOT/.env" ]; then echo "Missing $ROOT/.env. Copy .env.example to .env first." >&2 exit 1 fi set -a # shellcheck source=/dev/null . "$ROOT/.env" set +a if [ "${DATABASE_MODE:-container}" != container ]; then echo "scripts/test.sh requires the isolated local DATABASE_MODE=container setup." >&2 exit 1 fi : "${POSTGRES_USER:?Set POSTGRES_USER in .env}" : "${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}" run_id="$(date -u +%Y%m%d%H%M%S)-$$" image="who-need-help:test-$run_id" container="who-need-help-test-$run_id" runtime_env="$(mktemp "${TMPDIR:-/tmp}/who-need-help-test-env.XXXXXX")" chmod 600 "$runtime_env" cat >"$runtime_env" </dev/null 2>&1; then docker rm -f "$container" >/dev/null 2>&1 || cleanup_status=$? fi if docker image inspect "$image" >/dev/null 2>&1; then if image_tag_is_referenced "$image"; then echo "Refusing to remove referenced test image: $image" >&2 cleanup_status=1 else docker image rm "$image" >/dev/null || cleanup_status=$? fi fi if [ "$status" -eq 0 ] && [ "$cleanup_status" -ne 0 ]; then status=$cleanup_status fi exit "$status" } trap cleanup EXIT HUP INT TERM docker compose -p who_need_help up -d --wait db docker build --target test --tag "$image" . docker run --rm \ --name "$container" \ --network who_need_help_internal \ --env-file "$runtime_env" \ "$image" \ mix test