From 4dc07cb407092efcfc6c2e29e3fc79b1bf800acb Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 9 Apr 2026 15:29:00 +1000 Subject: [PATCH 1/2] ci: add sync-translations workflow for zh-cn Adds a GitHub Actions workflow that automatically translates changed lectures into Simplified Chinese on merged PRs, targeting QuantEcon/lecture-intro.zh-cn via QuantEcon/action-translation@v0.14.1. Supports re-triggering via \translate-resync comment on merged PRs. --- .github/workflows/sync-translations-zh-cn.yml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/sync-translations-zh-cn.yml diff --git a/.github/workflows/sync-translations-zh-cn.yml b/.github/workflows/sync-translations-zh-cn.yml new file mode 100644 index 00000000..47c057d2 --- /dev/null +++ b/.github/workflows/sync-translations-zh-cn.yml @@ -0,0 +1,36 @@ +# Sync Translations — Simplified Chinese +# On merged PR, translate changed lectures into the zh-cn target repo. +# +# Comment \translate-resync on a merged PR to re-trigger sync. +name: Sync Translations (Simplified Chinese) + +on: + pull_request: + types: [closed] + paths: + - 'lectures/**/*.md' + - 'lectures/_toc.yml' + issue_comment: + types: [created] + +jobs: + sync: + if: > + (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '\translate-resync')) + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 2 + + - uses: QuantEcon/action-translation@v0.14.1 + with: + mode: sync + target-repo: QuantEcon/lecture-intro.zh-cn + target-language: zh-cn + source-language: en + docs-folder: lectures + anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }} + github-token: ${{ secrets.QUANTECON_SERVICES_PAT }} From 7869db07a4d063dd3350885362a3c4449da28692 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Thu, 9 Apr 2026 16:31:33 +1000 Subject: [PATCH 2/2] fix: address Copilot review feedback on translation workflow - Gate issue_comment re-sync to OWNER/MEMBER/COLLABORATOR only - Verify comment is on a PR (not a plain issue) - Resolve the merged PR's commit SHA for correct checkout on re-sync - Verify the PR is actually merged before proceeding --- .github/workflows/sync-translations-zh-cn.yml | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync-translations-zh-cn.yml b/.github/workflows/sync-translations-zh-cn.yml index 47c057d2..698e28af 100644 --- a/.github/workflows/sync-translations-zh-cn.yml +++ b/.github/workflows/sync-translations-zh-cn.yml @@ -17,13 +17,40 @@ jobs: sync: if: > (github.event_name == 'pull_request' && github.event.pull_request.merged == true) || - (github.event_name == 'issue_comment' && contains(github.event.comment.body, '\translate-resync')) + ( + github.event_name == 'issue_comment' && + github.event.issue.pull_request && + contains(github.event.comment.body, '\translate-resync') && + ( + github.event.comment.author_association == 'OWNER' || + github.event.comment.author_association == 'MEMBER' || + github.event.comment.author_association == 'COLLABORATOR' + ) + ) runs-on: ubuntu-latest steps: + - name: Resolve merged PR commit for re-sync + if: github.event_name == 'issue_comment' + id: resolve_pr + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + pr_json="$(gh api repos/${{ github.repository }}/pulls/${{ github.event.issue.number }})" + merged="$(jq -r '.merged' <<<"$pr_json")" + merge_commit_sha="$(jq -r '.merge_commit_sha // empty' <<<"$pr_json")" + + if [ "$merged" != "true" ] || [ -z "$merge_commit_sha" ]; then + echo "The referenced pull request is not merged or has no merge commit SHA." + exit 1 + fi + + echo "merge_commit_sha=$merge_commit_sha" >> "$GITHUB_OUTPUT" + - uses: actions/checkout@v6 with: fetch-depth: 2 + ref: ${{ steps.resolve_pr.outputs.merge_commit_sha || github.sha }} - uses: QuantEcon/action-translation@v0.14.1 with: