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