#!/usr/bin/env bash set -euo pipefail test "$#" -ge 1 runner=$(realpath "$1") shift cd "$(dirname "$0")/.." worktree=$(pwd) artifact=internal/host/plan14-console-runner.bin woodstar_artifact=internal/host/plan14-woodstar-runner.bin test ! -e "$artifact" test ! -e "$woodstar_artifact" scratch=$(mktemp -d) owned_artifacts=() trap 'rm -f -- "${owned_artifacts[@]}"; rm -rf -- "$scratch"' EXIT stage_artifact() { python3 - "$1" "$2" <<'PYTHON' import os, shutil, sys with open(sys.argv[1], "rb") as source, open(sys.argv[2], "xb") as target: try: shutil.copyfileobj(source, target) except BaseException: os.unlink(sys.argv[2]) raise PYTHON owned_artifacts+=("$2") } export GOFLAGS=-buildvcs=false unset GOCACHE GOOS=linux GOARCH=arm64 CGO_ENABLED=0 nice -n 10 go build -o "$scratch/console" ./cmd/console stage_artifact "$scratch/console" "$artifact" tags=rootrunner,realconsole sha256sum "$artifact" if [ -n "${PLAN14_WOODSTAR_SOURCE:-}" ]; then mkdir "$scratch/woodstar" git -C "$PLAN14_WOODSTAR_SOURCE" rev-parse HEAD git -C "$PLAN14_WOODSTAR_SOURCE" archive HEAD go.mod go.sum cmd internal | tar -x -C "$scratch/woodstar" (cd "$scratch/woodstar" && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 nice -n 10 go build -mod=readonly -o "$scratch/unfurl" ./cmd/unfurl) stage_artifact "$scratch/unfurl" "$woodstar_artifact" sha256sum "$woodstar_artifact" tags=$tags,realwoodstar fi nice -n 10 python3 -u "$runner" --worktree "$worktree" --pkg ./internal/host --tags "$tags" "$@"