#!/bin/sh # hack/seed/run-prose.sh # # Runs the prose exporter inside a scratch rastrillo worktree at the # seed commit and writes its output into this checkout: the design # system's explanations, examples/prose.json, and the review queue, # hack/seed/prose-review.json. It reads the committed examples.json # and sources.json and nothing else of run.sh's output, and it never # runs TestFiestaSeed: the examples are seeded once, the prose can be # re-read whenever the tables change. # # The worktree goes under $TMPDIR, which must be set: this runs on a # shared machine, and /tmp is not scratch there. A worktree already at # that path belongs to another run and is left alone. Once this run # has made its own, the trap removes it and the copied file whether # the run passed, failed or was interrupted. # # hack/seed/run-prose.sh ~/src/rastrillo e14b745a7c08d0efa3bf221a8b6a5e75de15c46f set -eu if [ $# -ne 2 ]; then echo "usage: $0 " >&2 exit 2 fi if [ -z "${TMPDIR:-}" ]; then echo "run-prose.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2 exit 2 fi checkout=$1 seed=$2 here=$(cd "$(dirname "$0")" && pwd) fiesta=$(cd "$here/../.." && pwd) wt="$TMPDIR/rastrillo-prose" if [ -e "$wt" ]; then echo "run-prose.sh: $wt already exists; another run may be using it. Remove it by hand if not." >&2 exit 1 fi # cleanup runs from the EXIT trap, installed only once the worktree # below is ours. It keeps the run's own exit status, and a worktree # that could not be removed is reported and makes the run fail rather # than being hidden; prune runs either way. cleanup() { status=$? rm -f "$wt/internal/designsystem/prose_fiestaseed_test.go" if ! git -C "$checkout" worktree remove --force "$wt"; then echo "run-prose.sh: could not remove the scratch worktree $wt; remove it by hand" >&2 if [ "$status" -eq 0 ]; then status=1 fi fi git -C "$checkout" worktree prune exit "$status" } git -C "$checkout" worktree add --detach "$wt" "$seed" trap cleanup EXIT # A signal exits, and the EXIT trap then cleans up. trap 'exit 130' INT TERM cp "$here/_rastrillo/prose_fiestaseed_test.go" "$wt/internal/designsystem/" cd "$wt" GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" go test -tags fiestaseed -run '^TestFiestaProse$' ./internal/designsystem/ -count=1 -v