rastrillo / fiesta Public

Clone
git clone https://amadan.net/rastrillo/fiesta

Plain git — no account needed to clone.

Download

Download this file

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
19set -eu
20
21if [ $# -ne 2 ]; then
22 echo "usage: $0 <rastrillo checkout> <seed commit>" >&2
23 exit 2
24fi
25if [ -z "${TMPDIR:-}" ]; then
26 echo "run-prose.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2
27 exit 2
28fi
29checkout=$1
30seed=$2
31here=$(cd "$(dirname "$0")" && pwd)
32fiesta=$(cd "$here/../.." && pwd)
33wt="$TMPDIR/rastrillo-prose"
34
35if [ -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
38fi
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.
44cleanup() {
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
57git -C "$checkout" worktree add --detach "$wt" "$seed"
58trap cleanup EXIT
59# A signal exits, and the EXIT trap then cleans up.
60trap 'exit 130' INT TERM
61
62cp "$here/_rastrillo/prose_fiestaseed_test.go" "$wt/internal/designsystem/"
63
64cd "$wt"
65GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" go test -tags fiestaseed -run '^TestFiestaProse$' ./internal/designsystem/ -count=1 -v
66