Download this file
| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | test "$#" -ge 1 |
| 4 | runner=$(realpath "$1") |
| 5 | shift |
| 6 | cd "$(dirname "$0")/.." |
| 7 | worktree=$(pwd) |
| 8 | artifact=internal/host/plan14-console-runner.bin |
| 9 | woodstar_artifact=internal/host/plan14-woodstar-runner.bin |
| 10 | test ! -e "$artifact" |
| 11 | test ! -e "$woodstar_artifact" |
| 12 | scratch=$(mktemp -d) |
| 13 | owned_artifacts=() |
| 14 | trap 'rm -f -- "${owned_artifacts[@]}"; rm -rf -- "$scratch"' EXIT |
| 15 | stage_artifact() { |
| 16 | python3 - "$1" "$2" <<'PYTHON' |
| 17 | import os, shutil, sys |
| 18 | with open(sys.argv[1], "rb") as source, open(sys.argv[2], "xb") as target: |
| 19 | try: |
| 20 | shutil.copyfileobj(source, target) |
| 21 | except BaseException: |
| 22 | os.unlink(sys.argv[2]) |
| 23 | raise |
| 24 | PYTHON |
| 25 | owned_artifacts+=("$2") |
| 26 | } |
| 27 | export GOFLAGS=-buildvcs=false |
| 28 | unset GOCACHE |
| 29 | GOOS=linux GOARCH=arm64 CGO_ENABLED=0 nice -n 10 go build -o "$scratch/console" ./cmd/console |
| 30 | stage_artifact "$scratch/console" "$artifact" |
| 31 | tags=rootrunner,realconsole |
| 32 | sha256sum "$artifact" |
| 33 | if [ -n "${PLAN14_WOODSTAR_SOURCE:-}" ]; then |
| 34 | mkdir "$scratch/woodstar" |
| 35 | git -C "$PLAN14_WOODSTAR_SOURCE" rev-parse HEAD |
| 36 | git -C "$PLAN14_WOODSTAR_SOURCE" archive HEAD go.mod go.sum cmd internal | tar -x -C "$scratch/woodstar" |
| 37 | (cd "$scratch/woodstar" && GOOS=linux GOARCH=arm64 CGO_ENABLED=0 nice -n 10 go build -mod=readonly -o "$scratch/unfurl" ./cmd/unfurl) |
| 38 | stage_artifact "$scratch/unfurl" "$woodstar_artifact" |
| 39 | sha256sum "$woodstar_artifact" |
| 40 | tags=$tags,realwoodstar |
| 41 | fi |
| 42 | nice -n 10 python3 -u "$runner" --worktree "$worktree" --pkg ./internal/host --tags "$tags" "$@" |
| 43 | |