diff --git a/.github/workflows/sync-translations-zh-cn.yml b/.github/workflows/sync-translations-zh-cn.yml new file mode 100644 index 00000000..698e28af --- /dev/null +++ b/.github/workflows/sync-translations-zh-cn.yml @@ -0,0 +1,63 @@ +# 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' && + 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: + 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 }}