#!/bin/sh # hack/seed/run-translations.sh # # Carries the gallery's translations from rastrillo at the commit. It # dumps every English string the gallery says, with its id, through # go run ./hack/seed/english, then runs the translation exporter inside # a scratch rastrillo worktree at the commit. The exporter matches each # string byte for byte against the gallery's prose and sample tables and # the framework's locale catalogs, writes the hits into # internal/gallery/i18n/, keeps the drafts i18n/drafts.json vouches for, # and lists the rest in hack/seed/translations-todo.json for drafting. # # The worktree and the English dump go 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, the # copied file and the dump whether the run passed, failed or was # interrupted. # # hack/seed/run-translations.sh ~/src/rastrillo 5bb38c0ab31b9e3f5a698c61d73161cd1246471f set -eu if [ $# -ne 2 ]; then echo "usage: $0 " >&2 exit 2 fi if [ -z "${TMPDIR:-}" ]; then echo "run-translations.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2 exit 2 fi checkout=$1 commit=$2 here=$(cd "$(dirname "$0")" && pwd) fiesta=$(cd "$here/../.." && pwd) wt="$TMPDIR/rastrillo-translations" if [ -e "$wt" ]; then echo "run-translations.sh: $wt already exists; another run may be using it. Remove it by hand if not." >&2 exit 1 fi scratch=$(mktemp -d "$TMPDIR/fiesta-english.XXXXXX") # cleanup runs from the EXIT trap. 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. added= cleanup() { status=$? rm -rf "$scratch" if [ -n "$added" ]; then rm -f "$wt/internal/designsystem/translations_fiestaseed_test.go" if ! git -C "$checkout" worktree remove --force "$wt"; then echo "run-translations.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 fi exit "$status" } trap cleanup EXIT # A signal exits, and the EXIT trap then cleans up. trap 'exit 130' INT TERM (cd "$fiesta" && go run ./hack/seed/english -out "$scratch/english.json") git -C "$checkout" worktree add --detach "$wt" "$commit" added=1 cp "$here/_rastrillo/translations_fiestaseed_test.go" "$wt/internal/designsystem/" cd "$wt" GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" FIESTA_ENGLISH="$scratch/english.json" go test -tags fiestaseed -run '^TestFiestaTranslations$' ./internal/designsystem/ -count=1 -v