| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | remote_host="${LINUX_HOST:?set LINUX_HOST to the SSH name of the Linux Docker host}" |
| 5 | name="${LINUX_NAME:-tinyrelay-${USER:-user}-$$}" |
| 6 | safe_name="$(printf '%s' " $name" | tr -cs 'A-Za-z0-9_.-' '-' | sed 's/^-*//;s/-*$//')" |
| 7 | if [[ -z "$safe_name" ]]; then |
| 8 | echo "invalid empty LINUX_NAME" >&2 |
| 9 | exit 2 |
| 10 | fi |
| 11 | remote_root="tinyrelay-tests/${safe_name}" |
| 12 | image="tinyrelay-linux-${safe_name}" |
| 13 | packages="${LINUX_PACKAGES:-./internal/auth ./internal/blob ./internal/catalog ./internal/policy ./internal/relay ./internal/replication ./internal/storage ./internal/syncprotocol ./internal/telemetry ./internal/templates ./internal/work}" |
| 14 | stamp="$(date -u +%Y%m%dT%H%M%SZ)" |
| 15 | local_artifacts="${LINUX_ARTIFACTS:-artifacts/linux/${safe_name}/${stamp}}" |
| 16 | mkdir -p "$local_artifacts" |
| 17 | packages_b64="$(printf '%s' " $packages" | base64 | tr -d '\n')" |
| 18 | |
| 19 | echo "syncing worktree to ${remote_host}:${remote_root}" |
| 20 | COPYFILE_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'" |
| 29 | |
| 30 | echo "running Linux race tests in ${image}" |
| 31 | set +e |
| 32 | ssh "$remote_host" "LINUX_PACKAGES_B64='$packages_b64' sh -s -- '$remote_root' '$image' '$stamp'" <<'REMOTE' |
| 33 | set -eu |
| 34 | remote_root=$1 |
| 35 | image=$2 |
| 36 | stamp=$3 |
| 37 | packages=$(printf '%s' "$LINUX_PACKAGES_B64" | base64 -d) |
| 38 | artifact_dir="$remote_root/artifacts/$stamp" |
| 39 | mkdir -p "$artifact_dir" |
| 40 | { |
| 41 | date -u +%Y-%m-%dT%H:%M:%SZ |
| 42 | printf 'host=' ; hostname |
| 43 | printf 'kernel=' ; uname -a |
| 44 | printf 'cpu=' ; nproc |
| 45 | printf 'docker=' ; docker version --format '{{.Server.Version}}' |
| 46 | } > "$artifact_dir/metadata.txt" |
| 47 | set +e |
| 48 | docker build --target test --build-arg TEST_PACKAGES="$packages" -t "$image" "$remote_root" > "$artifact_dir/docker-build.log" 2>&1 |
| 49 | build_status=$? |
| 50 | cat "$artifact_dir/docker-build.log" |
| 51 | printf '%s\n' "$build_status" > "$artifact_dir/status" |
| 52 | if [ "$build_status" -eq 0 ]; then |
| 53 | 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" |
| 54 | fi |
| 55 | exit "$build_status" |
| 56 | REMOTE |
| 57 | remote_status=$? |
| 58 | set -e |
| 59 | |
| 60 | scp -q "$remote_host:$remote_root/artifacts/$stamp/metadata.txt" "$local_artifacts/metadata.txt" || true |
| 61 | scp -q "$remote_host:$remote_root/artifacts/$stamp/runtime.txt" "$local_artifacts/runtime.txt" || true |
| 62 | scp -q "$remote_host:$remote_root/artifacts/$stamp/status" "$local_artifacts/status" || true |
| 63 | scp -q "$remote_host:$remote_root/artifacts/$stamp/docker-build.log" "$local_artifacts/docker-build.log" || true |
| 64 | printf 'artifacts: %s\n' "$local_artifacts" |
| 65 | exit "$remote_status" |