diff --git a/.github/workflows/i18n-sync.yml b/.github/workflows/i18n-sync.yml index a01f702f755d..c1c3af2c0217 100644 --- a/.github/workflows/i18n-sync.yml +++ b/.github/workflows/i18n-sync.yml @@ -3,18 +3,17 @@ name: Sync translations # Keeps the 49 translations converged with English without blocking it. # Extraction runs without credentials and ships a patch; a trusted job # vets and publishes it to the i18n-sync branch; one credential-less Muse -# runner per pending language translates; a single collect job lands -# everything as one auto-merging pull request. Modeled on omarchy-site's -# translate-news workflow; keep the Muse install pin in step with it. +# runner per pending language translates; a single collect job validates +# everything and land merges it as one pull request. Modeled on +# omarchy-site's translate-news workflow; keep the Muse install pin in step +# with it. # -# Repository settings this needs: the MUSE_API_KEY Actions secret, and an -# I18N_SYNC_TOKEN secret (a fine-grained PAT with contents + pull-requests -# write on this repo) so the bot's pull request triggers checks — PRs -# created with GITHUB_TOKEN do not. Without it, the PR still opens but a -# human must nudge it (close/reopen or push) before auto-merge can pass. -# "Allow auto-merge" must be enabled, with i18n-check as a required status -# check on quattro. Runs where extraction touched executable code never -# auto-merge; they wait for a human review instead. +# Repository settings this needs: the MUSE_API_KEY Actions secret (and an +# optional MUSE_MODEL variable), and an I18N_SYNC_TOKEN secret (a +# fine-grained PAT with contents + pull-requests write on this repo) for +# the bot that opens and merges the pull request. Runs where extraction +# touched executable code are never merged here; they wait for a human +# review instead. on: push: branches: [quattro] @@ -394,7 +393,7 @@ jobs: with: name: collected path: ${{ runner.temp }}/collected - - name: Commit and open the auto-merging pull request + - name: Commit, open and merge the pull request env: GH_TOKEN: ${{ secrets.I18N_SYNC_TOKEN || github.token }} CODE_TOUCHED: ${{ needs.publish-extract.outputs.code_touched }} @@ -428,7 +427,7 @@ jobs: pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls?head=$GITHUB_REPOSITORY_OWNER:i18n-sync&base=quattro&state=open" --jq '.[0].number // empty') if [ -z "$pr" ]; then if [ "$changed" = true ] || [ "$(git rev-list --count origin/quattro..HEAD)" -gt 0 ]; then - pr=$(gh pr create --base quattro --head i18n-sync --title 'Update translations' --body 'Automated translation sync: extracts embedded English into the catalogs and fills pending translations for all 49 languages. Generated by the Sync translations workflow; merges automatically once i18n-check passes.') + pr=$(gh pr create --base quattro --head i18n-sync --title 'Update translations' --body 'Automated translation sync: extracts embedded English into the catalogs and fills pending translations for all 49 languages. Generated by the Sync translations workflow, which validated these files and merges this pull request itself.') pr=$(basename "$pr") fi fi @@ -442,6 +441,13 @@ jobs: gh pr comment "$pr" --body 'This sync includes an automated extraction that changed executable code under `bin/`, `install/` or `shell/`, so auto-merge is off: please review those hunks before merging.' echo "Extraction touched code; PR #$pr waits for human review." else - gh pr merge --auto --squash "$pr" || echo "Auto-merge could not be enabled for #$pr (enable 'Allow auto-merge' in repository settings); the PR is left open for a human." + # Merged here rather than left to auto-merge: collect has already + # run the structural i18n test on these files, and the next run + # rebuilds i18n-sync from quattro, so a pull request still open + # when it starts loses its translations. + if ! gh pr merge --squash "$pr"; then + echo "Could not merge #$pr; its translations stay pending and are redone by the next run." >&2 + exit 1 + fi fi fi diff --git a/docs/i18n.md b/docs/i18n.md index 398da0585ee7..011a077b3840 100644 --- a/docs/i18n.md +++ b/docs/i18n.md @@ -30,9 +30,9 @@ Until a translation catches up, the missing key simply renders in English. The s Individual pull requests only ever add the English side: the string in code plus its English catalog entry (or the English manual chapter). The `i18n-check` workflow validates structure on pull requests — catalogs well-formed, placeholders intact, English menu catalog fresh, and no user-facing English literals embedded directly in `bin/`, `install/` or `shell/` — but deliberately does not require translations. The extractor flags any QML property whose name ends like display text (`text`, `tooltipText`, `activeTooltipText`, `leftLabel`, `placeholderText`, …), every literal on such a line, and bare string-list items such as hero phrases; in `bin/` and `install/`, literals on `omarchy-notification-send` and menu prompt lines. A handful of intentional literals (brand names and fixed phrases) live in `default/i18n/extract-allowlist.json`; for one line rather than one string everywhere, use the `// i18n: ignore` marker. -The `Sync translations` workflow does the converging, modeled on omarchy-site's translate workflow. It runs on pushes to `quattro` that touch English sources, daily, and on demand. `scripts/i18n-sync.py` computes what is pending from `default/i18n/translation-manifest.json`, which records the hash of the English source every catalog key and manual chapter was translated from; a unit is pending when its translation is missing or its English changed since. The workflow first extracts any English that was embedded directly in code — on a credential-less runner that only produces a patch, which another credential-less job applies and validates (the checks load the extracted code, so nothing there may hold a token), and a trusted job path-checks and publishes without running any repository code — then runs one credential-less Muse runner per pending language, collects and validates their patches under per-language path allowlists without credentials, updates the manifest, and lands everything through a final trusted job, again only git and gh, as a single pull request from the `i18n-sync` branch with auto-merge enabled, so it merges itself once `i18n-check` passes. The one exception: when extraction changed executable code under `bin/`, `install/` or `shell/`, auto-merge is turned off, even if an earlier run enabled it, and the pull request waits for a human review. Failed languages simply stay pending and are retried on the next run; English is never blocked. The same script works locally: `python3 scripts/i18n-sync.py pending` shows the queue and `translate --locale da` fills one language. +The `Sync translations` workflow does the converging, modeled on omarchy-site's translate workflow. It runs on pushes to `quattro` that touch English sources, daily, and on demand. `scripts/i18n-sync.py` computes what is pending from `default/i18n/translation-manifest.json`, which records the hash of the English source every catalog key and manual chapter was translated from; a unit is pending when its translation is missing or its English changed since. The workflow first extracts any English that was embedded directly in code — on a credential-less runner that only produces a patch, which another credential-less job applies and validates (the checks load the extracted code, so nothing there may hold a token), and a trusted job path-checks and publishes without running any repository code — then runs one credential-less Muse runner per pending language, collects and validates their patches under per-language path allowlists without credentials, updates the manifest, and lands everything through a final trusted job, again only git and gh, as a single pull request from the `i18n-sync` branch, which it merges straight away: collect has already run the structural i18n test on those files, and the next run rebuilds `i18n-sync` from `quattro`, so a sync pull request left open would lose its translations to it. The one exception: when extraction changed executable code under `bin/`, `install/` or `shell/`, the pull request is not merged, auto-merge is turned off if an earlier run enabled it, and it waits for a human review. Failed languages simply stay pending and are retried on the next run; English is never blocked. The same script works locally: `python3 scripts/i18n-sync.py pending` shows the queue and `translate --locale da` fills one language. -Repository settings this needs: the `MUSE_API_KEY` Actions secret (optional `MUSE_MODEL` variable), an `I18N_SYNC_TOKEN` secret holding a fine-grained PAT with contents and pull-requests write on this repository (pull requests created with the default `GITHUB_TOKEN` do not trigger workflow runs, so their required check would never report; without the PAT the sync pull request still opens but needs a human nudge), "Allow auto-merge" enabled, and `i18n-check` as a required status check on `quattro` so auto-merge actually waits for validation. +Repository settings this needs: the `MUSE_API_KEY` Actions secret (optional `MUSE_MODEL` variable), and an `I18N_SYNC_TOKEN` secret holding a fine-grained PAT with contents and pull-requests write on this repository, for the bot account that opens and merges the sync pull request. ## Translator brief