|
| 1 | +#!/usr/bin/env bash |
| 2 | +# test-ci.sh — run the suite inside containers, mirroring a CI matrix leg 1:1: |
| 3 | +# same Julia image, same pinned SurrealDB image, same command, same topology. |
| 4 | +# The Julia container shares the surreal container's network namespace |
| 5 | +# (--network container:), so it reaches surreal at localhost:8000 exactly as CI |
| 6 | +# does (Julia on the runner host, surreal in docker with a published port). |
| 7 | +# |
| 8 | +# MODE remote (default) — start surreal, run server-gated suite |
| 9 | +# unit — no server, unit-only run (server tests self-skip) |
| 10 | +# JULIA official julia image tag (default 1.10) |
| 11 | +# SURREAL surrealdb/surrealdb image tag (default v3.1.2) |
| 12 | +# WIRE cbor | json (default cbor) |
| 13 | +# |
| 14 | +# Pins MUST match .github/workflows/test.yml — that workflow is canonical. |
| 15 | +set -euo pipefail |
| 16 | + |
| 17 | +MODE="${1:-remote}" |
| 18 | +JULIA="${JULIA:-1.10}" |
| 19 | +SURREAL="${SURREAL:-v3.1.2}" |
| 20 | +WIRE="${WIRE:-cbor}" |
| 21 | +HOST_PORT="${HOST_PORT:-8000}" |
| 22 | + |
| 23 | +REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 24 | +SURREAL_NAME="surreal-ci-$$" |
| 25 | +DEPOT_VOL="surrealdb-jl-depot-${JULIA}" # persistent depot per julia version → fast reruns |
| 26 | + |
| 27 | +cleanup() { docker rm -f "$SURREAL_NAME" >/dev/null 2>&1 || true; } |
| 28 | +trap cleanup EXIT |
| 29 | + |
| 30 | +NET_ARGS=() |
| 31 | +URL="" |
| 32 | +if [ "$MODE" = "remote" ]; then |
| 33 | + echo "[test-ci] surrealdb/surrealdb:$SURREAL on :$HOST_PORT (wire=$WIRE)" |
| 34 | + docker run -d --rm --name "$SURREAL_NAME" -p "$HOST_PORT:8000" \ |
| 35 | + "surrealdb/surrealdb:$SURREAL" \ |
| 36 | + start --user root --pass root --bind 0.0.0.0:8000 memory >/dev/null |
| 37 | + echo "[test-ci] waiting for surreal..." |
| 38 | + for _ in $(seq 1 30); do |
| 39 | + curl -s -X POST "http://localhost:$HOST_PORT/rpc" \ |
| 40 | + -H 'Content-Type: application/json' \ |
| 41 | + -d '{"id":1,"method":"version","params":[]}' >/dev/null 2>&1 && break |
| 42 | + sleep 1 |
| 43 | + done |
| 44 | + # Share surreal's network namespace → Julia reaches it at localhost:8000. |
| 45 | + NET_ARGS=(--network "container:$SURREAL_NAME") |
| 46 | + URL="ws://localhost:8000" |
| 47 | +fi |
| 48 | + |
| 49 | +echo "[test-ci] julia:$JULIA mode=$MODE" |
| 50 | +docker run --rm "${NET_ARGS[@]}" \ |
| 51 | + -v "$REPO:/work" -w /work \ |
| 52 | + -v "$DEPOT_VOL:/depot" -e JULIA_DEPOT_PATH=/depot \ |
| 53 | + -e SURREALDB_URL="$URL" -e SURREALDB_WIRE="$WIRE" \ |
| 54 | + "julia:$JULIA" \ |
| 55 | + julia --project=test -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate(); include("test/runtests.jl")' |
0 commit comments