| 1 | #!/bin/sh |
| 2 | # hack/seed/run-translations.sh <rastrillo checkout> <commit> |
| 3 | # |
| 4 | # Carries the gallery's translations from rastrillo at the commit. It |
| 5 | # dumps every English string the gallery says, with its id, through |
| 6 | # go run ./hack/seed/english, then runs the translation exporter inside |
| 7 | # a scratch rastrillo worktree at the commit. The exporter matches each |
| 8 | # string byte for byte against the gallery's prose and sample tables and |
| 9 | # the framework's locale catalogs, writes the hits into |
| 10 | # internal/gallery/i18n/, keeps the drafts i18n/drafts.json vouches for, |
| 11 | # and lists the rest in hack/seed/translations-todo.json for drafting. |
| 12 | # |
| 13 | # The worktree and the English dump go under $TMPDIR, which must be |
| 14 | # set: this runs on a shared machine, and /tmp is not scratch there. A |
| 15 | # worktree already at that path belongs to another run and is left |
| 16 | # alone. Once this run has made its own, the trap removes it, the |
| 17 | # copied file and the dump whether the run passed, failed or was |
| 18 | # interrupted. |
| 19 | # |
| 20 | # hack/seed/run-translations.sh ~/src/rastrillo 5bb38c0ab31b9e3f5a698c61d73161cd1246471f |
| 21 | set -eu |
| 22 | |
| 23 | if [ $# -ne 2 ]; then |
| 24 | echo "usage: $0 <rastrillo checkout> <commit>" >&2 |
| 25 | exit 2 |
| 26 | fi |
| 27 | if [ -z "${TMPDIR:-}" ]; then |
| 28 | echo "run-translations.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2 |
| 29 | exit 2 |
| 30 | fi |
| 31 | checkout=$1 |
| 32 | commit=$2 |
| 33 | here=$(cd "$(dirname "$0")" && pwd) |
| 34 | fiesta=$(cd "$here/../.." && pwd) |
| 35 | wt="$TMPDIR/rastrillo-translations" |
| 36 | |
| 37 | if [ -e "$wt" ]; then |
| 38 | echo "run-translations.sh: $wt already exists; another run may be using it. Remove it by hand if not." >&2 |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | scratch=$(mktemp -d "$TMPDIR/fiesta-english.XXXXXX") |
| 43 | # cleanup runs from the EXIT trap. It keeps the run's own exit status, |
| 44 | # and a worktree that could not be removed is reported and makes the |
| 45 | # run fail rather than being hidden; prune runs either way. |
| 46 | added= |
| 47 | cleanup() { |
| 48 | status=$? |
| 49 | rm -rf "$scratch" |
| 50 | if [ -n "$added" ]; then |
| 51 | rm -f "$wt/internal/designsystem/translations_fiestaseed_test.go" |
| 52 | if ! git -C "$checkout" worktree remove --force "$wt"; then |
| 53 | echo "run-translations.sh: could not remove the scratch worktree $wt; remove it by hand" >&2 |
| 54 | if [ "$status" -eq 0 ]; then |
| 55 | status=1 |
| 56 | fi |
| 57 | fi |
| 58 | git -C "$checkout" worktree prune |
| 59 | fi |
| 60 | exit "$status" |
| 61 | } |
| 62 | trap cleanup EXIT |
| 63 | # A signal exits, and the EXIT trap then cleans up. |
| 64 | trap 'exit 130' INT TERM |
| 65 | |
| 66 | (cd "$fiesta" && go run ./hack/seed/english -out "$scratch/english.json") |
| 67 | |
| 68 | git -C "$checkout" worktree add --detach "$wt" "$commit" |
| 69 | added=1 |
| 70 | cp "$here/_rastrillo/translations_fiestaseed_test.go" "$wt/internal/designsystem/" |
| 71 | |
| 72 | cd "$wt" |
| 73 | GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" FIESTA_ENGLISH="$scratch/english.json" go test -tags fiestaseed -run '^TestFiestaTranslations$' ./internal/designsystem/ -count=1 -v |
| 74 | |