name: i18n branch # Keeps the `i18n` branch Hosted Weblate works on in step with main, and brings Weblate's commits # back to main through a pull request (issue #112, ADR-0034 amendment of 2026-11-29, # docs/guides/translations-weblate.md §3–4). The branch is an orphan holding only # `pnpm i18n:export` output under i18n/; scripts/i18n-branch.ts merges per key against the last # sync commit (its `I18n-Source:` trailer), so neither direction overwrites the other's unmerged # work. # # - sync (push to main that touches a catalog, or Run workflow › sync): main → `i18n`, pushed with # this job's token. A push from GITHUB_TOKEN starts no other workflow, so it cannot loop. # - weblate-pr (daily, or Run workflow › import): Weblate has no write access to this repository # (no deploy key, no app with contents write: the yank-list ruleset lets every deploy key # bypass it). Hosted Weblate's "GitHub" VCS pushes to its own fork as the `weblate` user (id # 1607653) and opens one pull request into `i18n`. This job fetches that PR's head as git # objects only (never a checkout, never `pull_request_target`, none of its code runs), checks # that it changes nothing but existing `i18n//.json` translation files with plain # nested JSON (`node scripts/i18n-branch.ts check-pr`), and merges it into `i18n` through the # API, pinned to the head it checked. A PR from anyone else, or one that fails the check, is # left open and reported. # - import (after weblate-pr): `i18n` → main as one pull request from `i18n/weblate-import`, after # `pnpm i18n:import` and its catalog tests pass. It needs a GitHub App (the I18N_APP_CLIENT_ID # variable and I18N_APP_PRIVATE_KEY secret, contents and pull requests write on this # repository), because a pull request opened with GITHUB_TOKEN would not run CI. Without the App # it logs what is waiting and changes nothing. A person merges the PR. on: push: branches: [main] paths: - "apps/studio/src/i18n/**" - "packages/astro-renderer/src/status-strings/**" - "scripts/i18n-exchange.ts" - "scripts/i18n-branch.ts" - "scripts/i18n-branch/**" schedule: - cron: "23 4 * * *" workflow_dispatch: inputs: run: description: sync (main → i18n) or import (i18n → a PR to main) type: choice options: [sync, import] required: true permissions: {} concurrency: group: i18n-branch cancel-in-progress: false jobs: sync: name: main → i18n if: github.event_name == 'push' || inputs.run == 'sync' runs-on: ubuntu-latest timeout-minutes: 15 permissions: contents: write steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 cache: pnpm - run: pnpm install --frozen-lockfile - name: Write main's catalogs to i18n and push env: SOURCE: ${{ github.sha }} run: | set -euo pipefail git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" TREE="$RUNNER_TEMP/i18n" for _ in 1 2 3; do rm -rf "$TREE"; git worktree prune; git branch -q -D i18n 2>/dev/null || true # the whole history of the orphan branch: the last sync commit is the merge base if git fetch -q --no-tags origin +refs/heads/i18n:refs/remotes/origin/i18n 2>/dev/null; then git worktree add -q -B i18n "$TREE" origin/i18n else echo "::notice title=i18n branch::origin has no i18n branch yet; creating it" git worktree add -q --orphan -b i18n "$TREE" fi node scripts/i18n-branch.ts sync --dir "$TREE" --ref origin/i18n cd "$TREE" git add -A if git diff --cached --quiet; then echo "i18n already matches $SOURCE" exit 0 fi git commit -q -s -m "chore(i18n): sync the catalogs from main" -m "I18n-Source: $SOURCE" # Weblate may have pushed meanwhile: fetch, merge again, retry. if git push -q origin HEAD:refs/heads/i18n; then exit 0; fi cd "$GITHUB_WORKSPACE" done echo "::error title=i18n branch::the push to i18n was rejected three times" exit 1 weblate-pr: name: Weblate's PR → i18n if: github.event_name == 'schedule' || inputs.run == 'import' runs-on: ubuntu-latest timeout-minutes: 10 permissions: contents: write pull-requests: write env: REPO: ${{ github.repository }} # Hosted Weblate's GitHub user (https://github.com/weblate); its PRs come from its fork. WEBLATE_LOGIN: weblate WEBLATE_ID: "1607653" steps: # main's own scripts; nothing from the PR is checked out. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 - name: Check and merge Weblate's pull requests into i18n env: GH_TOKEN: ${{ github.token }} run: | set -euo pipefail if ! git fetch -q --no-tags origin +refs/heads/i18n:refs/remotes/origin/i18n 2>/dev/null; then echo "::notice title=No i18n branch::run the sync first" exit 0 fi refused=0 # Every open PR into i18n; only Weblate's, from a fork Weblate owns, is considered. gh api --paginate "repos/$REPO/pulls?state=open&base=i18n&per_page=100" \ --jq '.[] | "\(.number) \(.head.sha) \(.user.login) \(.user.id) \(.head.repo.full_name // "")"' \ > "$RUNNER_TEMP/prs.txt" while read -r NUM SHA LOGIN USER_ID HEADREPO; do if [ "$LOGIN" != "$WEBLATE_LOGIN" ] || [ "$USER_ID" != "$WEBLATE_ID" ] || [[ "$HEADREPO" != "$WEBLATE_LOGIN/"* ]]; then echo "::notice title=Not Weblate's::#$NUM by $LOGIN from $HEADREPO is left alone" continue fi # git objects only: the PR's files are read by check-pr, never run or checked out git fetch -q --no-tags origin "+refs/pull/$NUM/head:refs/remotes/weblate/$NUM" if [ "$(git rev-parse "refs/remotes/weblate/$NUM")" != "$SHA" ]; then echo "::warning title=Weblate PR moved::#$NUM changed while it was fetched; next run" continue fi if ! node scripts/i18n-branch.ts check-pr --ref origin/i18n --head "refs/remotes/weblate/$NUM"; then echo "::error title=Weblate PR refused::#$NUM changes more than translation files; not merged" refused=1 continue fi # `sha` pins the merge to the commit just checked: a later push makes it fail. if gh api -X PUT "repos/$REPO/pulls/$NUM/merge" -f sha="$SHA" -f merge_method=merge \ -f commit_title="chore(i18n): translations from Weblate (#$NUM)" > /dev/null; then echo "Merged #$NUM ($SHA) into i18n" else echo "::warning title=Weblate PR not merged::#$NUM could not be merged (conflict with i18n?); Weblate rebases it on its next update" fi done < "$RUNNER_TEMP/prs.txt" exit "$refused" import: name: i18n → PR to main needs: weblate-pr # also when a Weblate PR was refused: what is already on i18n still comes to main if: ${{ !cancelled() && (github.event_name == 'schedule' || inputs.run == 'import') }} runs-on: ubuntu-latest timeout-minutes: 20 permissions: contents: read env: BRANCH: i18n/weblate-import steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 with: node-version: 24 cache: pnpm - run: pnpm install --frozen-lockfile - id: stage name: Merge Weblate's commits into main's catalogs run: | set -euo pipefail if ! git fetch -q --no-tags origin +refs/heads/i18n:refs/remotes/origin/i18n 2>/dev/null; then echo "::notice title=No i18n branch::nothing to import" echo "changed=false" >> "$GITHUB_OUTPUT" exit 0 fi node scripts/i18n-branch.ts stage --ref origin/i18n --summary "$RUNNER_TEMP/pr-body.md" # checks keys and ICU syntax, rewrites the catalogs, runs the catalog tests pnpm i18n:import if [ -z "$(git status --porcelain -- apps packages)" ]; then echo "Weblate has nothing that main lacks" echo "changed=false" >> "$GITHUB_OUTPUT" else git status --short -- apps packages echo "changed=true" >> "$GITHUB_OUTPUT" fi - id: gate name: Is the GitHub App set up? if: steps.stage.outputs.changed == 'true' env: CLIENT_ID: ${{ vars.I18N_APP_CLIENT_ID }} HAS_KEY: ${{ secrets.I18N_APP_PRIVATE_KEY != '' }} run: | if [ -n "$CLIENT_ID" ] && [ "$HAS_KEY" = "true" ]; then echo "enabled=true" >> "$GITHUB_OUTPUT" else { echo "### Weblate translations wait for import" echo cat "$RUNNER_TEMP/pr-body.md" echo echo "Run \`git fetch origin i18n && node scripts/i18n-branch.ts stage && pnpm i18n:import\` and open a PR," echo "or set the I18N_APP_CLIENT_ID variable and I18N_APP_PRIVATE_KEY secret so this job opens it." } >> "$GITHUB_STEP_SUMMARY" echo "::notice title=Weblate translations wait for import::No GitHub App is set up (I18N_APP_CLIENT_ID, I18N_APP_PRIVATE_KEY); see the job summary" echo "enabled=false" >> "$GITHUB_OUTPUT" fi - id: app if: steps.gate.outputs.enabled == 'true' uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 with: client-id: ${{ vars.I18N_APP_CLIENT_ID }} private-key: ${{ secrets.I18N_APP_PRIVATE_KEY }} permission-contents: write permission-pull-requests: write - name: Push i18n/weblate-import and open or update the PR if: steps.gate.outputs.enabled == 'true' env: GH_TOKEN: ${{ steps.app.outputs.token }} SLUG: ${{ steps.app.outputs.app-slug }} REPO: ${{ github.repository }} run: | set -euo pipefail TITLE="chore(i18n): translations from Weblate" gh auth setup-git ID=$(gh api "/users/${SLUG}%5Bbot%5D" --jq .id) git config user.name "${SLUG}[bot]" git config user.email "${ID}+${SLUG}[bot]@users.noreply.github.com" # Rebuilt from main on every run, so nobody pushes to it by hand. git switch -q -c "$BRANCH" git add -A -- apps packages git commit -q -s -m "$TITLE" \ -m "Merged from the i18n branch by scripts/i18n-branch.ts stage and imported with pnpm i18n:import (ADR-0034, #112). No reviewed flag changes." \ -m "Opened by $GITHUB_SERVER_URL/$REPO/actions/runs/$GITHUB_RUN_ID" git push -q --force origin "HEAD:refs/heads/$BRANCH" PR=$(gh api "repos/$REPO/pulls?state=open&head=${REPO%%/*}:$BRANCH" \ --jq '[.[] | select(.head.repo.full_name == env.REPO)][0].number // empty') if [ -n "$PR" ]; then gh api -X PATCH "repos/$REPO/pulls/$PR" -f title="$TITLE" -F "body=@$RUNNER_TEMP/pr-body.md" > /dev/null echo "Updated $GITHUB_SERVER_URL/$REPO/pull/$PR" else gh pr create --repo "$REPO" --base main --head "$BRANCH" --title "$TITLE" --body-file "$RUNNER_TEMP/pr-body.md" fi