clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/standalone-relay
tinyrelay / scripts / test-linux.sh
test-linux.sh 2.7K executable
1#!/usr/bin/env bash2set -euo pipefail34remote_host="${LINUX_HOST:?set LINUX_HOST to the SSH name of the Linux Docker host}"5name="${LINUX_NAME:-tinyrelay-${USER:-user}-$$}"6safe_name="$(printf '%s' "$name" | tr -cs 'A-Za-z0-9_.-' '-' | sed 's/^-*//;s/-*$//')"7if [[ -z "$safe_name" ]]; then8 echo "invalid empty LINUX_NAME" >&29 exit 210fi11remote_root="tinyrelay-tests/${safe_name}"12image="tinyrelay-linux-${safe_name}"13packages="${LINUX_PACKAGES:-./internal/auth ./internal/blob ./internal/catalog ./internal/policy ./internal/relay ./internal/replication ./internal/storage ./internal/syncprotocol ./internal/telemetry ./internal/templates ./internal/work}"14stamp="$(date -u +%Y%m%dT%H%M%SZ)"15local_artifacts="${LINUX_ARTIFACTS:-artifacts/linux/${safe_name}/${stamp}}"16mkdir -p "$local_artifacts"17packages_b64="$(printf '%s' "$packages" | base64 | tr -d '\n')"1819echo "syncing worktree to ${remote_host}:${remote_root}"20COPYFILE_DISABLE=1 tar \21 --exclude=.git \22 --exclude=.DS_Store \23 --exclude=.playwright-cli \24 --exclude=output \25 --exclude=artifacts \26 --exclude=node_modules \27 --no-xattrs \28 -cf - . | ssh "$remote_host" "mkdir -p '$remote_root' && tar -xf - -C '$remote_root'"2930echo "running Linux race tests in ${image}"31set +e32ssh "$remote_host" "LINUX_PACKAGES_B64='$packages_b64' sh -s -- '$remote_root' '$image' '$stamp'" <<'REMOTE'33set -eu34remote_root=$135image=$236stamp=$337packages=$(printf '%s' "$LINUX_PACKAGES_B64" | base64 -d)38artifact_dir="$remote_root/artifacts/$stamp"39mkdir -p "$artifact_dir"40{41 date -u +%Y-%m-%dT%H:%M:%SZ42 printf 'host='; hostname43 printf 'kernel='; uname -a44 printf 'cpu='; nproc45 printf 'docker='; docker version --format '{{.Server.Version}}'46} > "$artifact_dir/metadata.txt"47set +e48docker build --target test --build-arg TEST_PACKAGES="$packages" -t "$image" "$remote_root" > "$artifact_dir/docker-build.log" 2>&149build_status=$?50cat "$artifact_dir/docker-build.log"51printf '%s\n' "$build_status" > "$artifact_dir/status"52if [ "$build_status" -eq 0 ]; then53 docker run --rm "$image" sh -c 'export PATH=/usr/local/go/bin:/usr/local/bin:$PATH; /usr/local/go/bin/go version; /usr/local/go/bin/go env GOOS GOARCH GOVERSION; sed -n "s/^.*modernc.org\/sqlite v//p" go.mod | head -1' > "$artifact_dir/runtime.txt"54fi55exit "$build_status"56REMOTE57remote_status=$?58set -e5960scp -q "$remote_host:$remote_root/artifacts/$stamp/metadata.txt" "$local_artifacts/metadata.txt" || true61scp -q "$remote_host:$remote_root/artifacts/$stamp/runtime.txt" "$local_artifacts/runtime.txt" || true62scp -q "$remote_host:$remote_root/artifacts/$stamp/status" "$local_artifacts/status" || true63scp -q "$remote_host:$remote_root/artifacts/$stamp/docker-build.log" "$local_artifacts/docker-build.log" || true64printf 'artifacts: %s\n' "$local_artifacts"65exit "$remote_status"