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-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
21set -eu
22
23if [ $# -ne 2 ]; then
24 echo "usage: $0 <rastrillo checkout> <commit>" >&2
25 exit 2
26fi
27if [ -z "${TMPDIR:-}" ]; then
28 echo "run-translations.sh: TMPDIR is unset; set it to scratch space on disk, not /tmp" >&2
29 exit 2
30fi
31checkout=$1
32commit=$2
33here=$(cd "$(dirname "$0")" && pwd)
34fiesta=$(cd "$here/../.." && pwd)
35wt="$TMPDIR/rastrillo-translations"
36
37if [ -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
40fi
41
42scratch=$(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.
46added=
47cleanup() {
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}
62trap cleanup EXIT
63# A signal exits, and the EXIT trap then cleans up.
64trap 'exit 130' INT TERM
65
66(cd "$fiesta" && go run ./hack/seed/english -out "$scratch/english.json")
67
68git -C "$checkout" worktree add --detach "$wt" "$commit"
69added=1
70cp "$here/_rastrillo/translations_fiestaseed_test.go" "$wt/internal/designsystem/"
71
72cd "$wt"
73GOFLAGS=-mod=mod FIESTA_SEED_OUT="$fiesta" FIESTA_ENGLISH="$scratch/english.json" go test -tags fiestaseed -run '^TestFiestaTranslations$' ./internal/designsystem/ -count=1 -v
74