| 1 | #!/bin/sh |
| 2 | # hack/seed/run-prose.sh <rastrillo checkout> <seed commit> |
| 3 | # |
| 4 | # Runs the prose exporter inside a scratch rastrillo worktree at the |
| 5 | # seed commit and writes its output into this checkout: the design |
| 6 | # system's explanations, examples/prose.json, and the review queue, |
| 7 | # hack/seed/prose-review.json. It reads the committed examples.json |
| 8 | # and sources.json and nothing else of run.sh's output, and it never |
| 9 | # runs TestFiestaSeed: the examples are seeded once, the prose can be |
| 10 | # re-read whenever the tables change. |
| 11 | # |
| 12 | # The worktree goes under $TMPDIR, which must be set: this runs on a |
| 13 | # shared machine, and /tmp is not scratch there. A worktree already at |
| 14 | # that path belongs to another run and is left alone. Once this run |
| 15 | # has made its own, the trap removes it and the copied file whether |
| 16 | # the run passed, failed or was interrupted. |
| 17 | # |
| 18 | # hack/seed/run-prose.sh ~/src/rastrillo e14b745a7c08d0efa3bf221a8b6a5e75de15c46f |
| 19 | set -eu |
| 20 | |
| 21 | if [ $# -ne 2 ]; then |
| 22 | echo "usage: $0 <rastrillo checkout> <seed commit>" >&2 |
| 23 | exit 2 |
| 24 | fi |
| 25 | if [ -z "${TMPDIR:-}" ]; then |
| 26 | echo "run-prose.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2 |
| 27 | exit 2 |
| 28 | fi |
| 29 | checkout=$1 |
| 30 | seed=$2 |
| 31 | here=$(cd "$(dirname "$0")" && pwd) |
| 32 | fiesta=$(cd "$here/../.." && pwd) |
| 33 | wt="$TMPDIR/rastrillo-prose" |
| 34 | |
| 35 | if [ -e "$wt" ]; then |
| 36 | echo "run-prose.sh: $wt already exists; another run may be using it. Remove it by hand if not." >&2 |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | # cleanup runs from the EXIT trap, installed only once the worktree |
| 41 | # below is ours. It keeps the run's own exit status, and a worktree |
| 42 | # that could not be removed is reported and makes the run fail rather |
| 43 | # than being hidden; prune runs either way. |
| 44 | cleanup() { |
| 45 | status=$? |
| 46 | rm -f "$wt/internal/designsystem/prose_fiestaseed_test.go" |
| 47 | if ! git -C "$checkout" worktree remove --force "$wt"; then |
| 48 | echo "run-prose.sh: could not remove the scratch worktree $wt; remove it by hand" >&2 |
| 49 | if [ "$status" -eq 0 ]; then |
| 50 | status=1 |
| 51 | fi |
| 52 | fi |
| 53 | git -C "$checkout" worktree prune |
| 54 | exit "$status" |
| 55 | } |
| 56 | |
| 57 | git -C "$checkout" worktree add --detach "$wt" "$seed" |
| 58 | trap cleanup EXIT |
| 59 | # A signal exits, and the EXIT trap then cleans up. |
| 60 | trap 'exit 130' INT TERM |
| 61 | |
| 62 | cp "$here/_rastrillo/prose_fiestaseed_test.go" "$wt/internal/designsystem/" |
| 63 | |
| 64 | cd "$wt" |
| 65 | GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" go test -tags fiestaseed -run '^TestFiestaProse$' ./internal/designsystem/ -count=1 -v |
| 66 | |