-
Notifications
You must be signed in to change notification settings - Fork 713
255 lines (218 loc) · 9.34 KB
/
Copy pathtranslation-zh.yaml
File metadata and controls
255 lines (218 loc) · 9.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
name: Sync TiDB Cloud Docs from EN to ZH
concurrency:
group: translation-zh-cloud-${{ github.event_name }}
cancel-in-progress: true
on:
schedule:
- cron: "0 9 * * 3" # Runs at 17:00 every Wednesday (Beijing time, UTC+8)
workflow_dispatch:
inputs:
file_names:
description: "Specify Cloud files to translate (comma-separated list)"
required: true
type: string
source_files_translation_mode:
description: "Translate specified files incrementally or as full files"
required: true
type: choice
default: incremental
options:
- incremental
- full
env:
SOURCE_REPO: pingcap/docs
SOURCE_BRANCH: release-8.5
TERMS_BRANCH: master
CN_CLOUD_BRANCH: i18n-zh-release-8.5
CLOUD_TOC_FILES: TOC-tidb-cloud.md,TOC-tidb-cloud-starter.md,TOC-tidb-cloud-essential.md,TOC-tidb-cloud-premium.md,TOC-tidb-cloud-releases.md
CLOUD_INDEX_FILES: tidb-cloud/dedicated/_index.md,tidb-cloud/essential/_index.md,tidb-cloud/premium/_index.md,tidb-cloud/releases/_index.md,tidb-cloud/starter/_index.md
AI_TRANSLATOR_REPO: qiancai/ai-pr-translator
AI_TRANSLATOR_REF: main
jobs:
translate:
if: github.repository == 'pingcap/docs'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6
name: Checkout docs target branch
with:
ref: ${{ env.CN_CLOUD_BRANCH }}
path: docs
- uses: actions/checkout@v6
name: Checkout docs source branch
with:
repository: ${{ env.SOURCE_REPO }}
ref: ${{ env.SOURCE_BRANCH }}
path: docs-source
fetch-depth: 0
persist-credentials: false
- uses: actions/checkout@v6
name: Checkout docs terms branch
with:
repository: ${{ env.SOURCE_REPO }}
ref: ${{ env.TERMS_BRANCH }}
path: docs-terms
persist-credentials: false
- uses: actions/checkout@v6
name: Checkout ai-pr-translator
with:
repository: ${{ env.AI_TRANSLATOR_REPO }}
ref: ${{ env.AI_TRANSLATOR_REF }}
path: ai-pr-translator
persist-credentials: false
- uses: actions/setup-python@v6
name: Setup Python
with:
python-version: "3.9"
cache: pip
cache-dependency-path: ai-pr-translator/scripts/requirements.txt
- name: Install Python dependencies
shell: bash
run: |
set -euo pipefail
python -m pip install --upgrade pip
pip install -r ai-pr-translator/scripts/requirements.txt
- name: Resolve commit range
id: commits
shell: bash
working-directory: docs
run: |
set -euo pipefail
readarray -t cursor_values < <(python - <<'PY'
import json
from pathlib import Path
data = json.loads(Path("latest_translation_commit.json").read_text(encoding="utf-8"))
print((data.get("target") or "").strip())
print((data.get("sha") or "").strip())
PY
)
cursor_target="${cursor_values[0]:-}"
base_ref="${cursor_values[1]:-}"
head_ref="$(git -C "${GITHUB_WORKSPACE}/docs-source" rev-parse HEAD)"
if [ -z "${base_ref}" ]; then
echo "latest_translation_commit.json does not contain a source sha" >&2
exit 1
fi
if [ -n "${cursor_target}" ] && [ "${cursor_target}" != "${SOURCE_BRANCH}" ]; then
echo "latest_translation_commit.json target is ${cursor_target}, expected ${SOURCE_BRANCH}" >&2
exit 1
fi
echo "base_ref=${base_ref}" >> "${GITHUB_OUTPUT}"
echo "head_ref=${head_ref}" >> "${GITHUB_OUTPUT}"
- name: Resolve Cloud source file filter
id: source_files
shell: bash
env:
INPUT_FILE_NAMES: ${{ inputs.file_names || '' }}
BASE_REF: ${{ steps.commits.outputs.base_ref }}
HEAD_REF: ${{ steps.commits.outputs.head_ref }}
DOCS_SOURCE_PATH: ${{ github.workspace }}/docs-source
CLOUD_TOC_FILES: ${{ env.CLOUD_TOC_FILES }}
CLOUD_INDEX_FILES: ${{ env.CLOUD_INDEX_FILES }}
run: |
set -euo pipefail
python ai-pr-translator/scripts/resolve_cloud_source_files.py
- name: Run commit sync workflow
id: sync
if: steps.source_files.outputs.has_source_changes == 'true'
continue-on-error: true
shell: bash
env:
GITHUB_TOKEN: ${{ github.token }}
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
OPENAI_BASE_URL: ${{ secrets.AZURE_OPENAI_BASE_URL }}
SOURCE_REPO: ${{ env.SOURCE_REPO }}
TARGET_REPO: ${{ env.SOURCE_REPO }}
SOURCE_BRANCH: ${{ env.SOURCE_BRANCH }}
SOURCE_BASE_REF: ${{ steps.commits.outputs.base_ref }}
SOURCE_HEAD_REF: ${{ steps.commits.outputs.head_ref }}
SOURCE_FOLDER: ""
SOURCE_FILES: ${{ steps.source_files.outputs.files }}
SOURCE_FILES_TRANSLATION_MODE: ${{ inputs.source_files_translation_mode || 'incremental' }}
SOURCE_LANGUAGE: English
TARGET_LANGUAGE: Chinese
IGNORE_RESOURCE_CARD_SECTION: "Yes"
SOURCE_REPO_PATH: ${{ github.workspace }}/docs-source
TARGET_REF: ${{ env.CN_CLOUD_BRANCH }}
PREFER_LOCAL_TARGET_FOR_READ: "true"
TARGET_REPO_PATH: ${{ github.workspace }}/docs
AI_PROVIDER: azure
TERMS_PATH: ${{ github.workspace }}/docs-terms/resources/terms.md
FAIL_ON_TRANSLATION_ERROR: "true"
SKIP_TRANSLATING_CLOUD_DOCS_TO_ZH: "false"
SKIP_TRANSLATING_AI_DOCS_TO_ZH: "true"
run: |
set -euo pipefail
cd ai-pr-translator/scripts
python commit_sync_workflow.py
- name: Prepare translated changes
id: changes
if: always() && steps.source_files.outputs.has_source_changes == 'true'
shell: bash
working-directory: docs
env:
HEAD_REF: ${{ steps.commits.outputs.head_ref }}
SOURCE_BRANCH: ${{ env.SOURCE_BRANCH }}
FAILURE_REPORT: ${{ github.workspace }}/ai-pr-translator/scripts/temp_output/translation-failures.md
run: |
set -euo pipefail
if [ -s "${FAILURE_REPORT}" ]; then
{
echo "failure_summary<<EOF"
cat "${FAILURE_REPORT}"
echo
echo "> Before merging this PR, manually translate the failed files above or rerun this workflow with workflow_dispatch and file_names set to those paths."
echo "EOF"
} >> "${GITHUB_OUTPUT}"
fi
if [ -z "$(git status --porcelain)" ]; then
echo "has_changes=false" >> "${GITHUB_OUTPUT}"
exit 0
fi
if [ "${GITHUB_EVENT_NAME}" = "schedule" ]; then
python -c 'import json, os; from pathlib import Path; Path("latest_translation_commit.json").write_text(json.dumps({"target": os.environ["SOURCE_BRANCH"], "sha": os.environ["HEAD_REF"]}, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")'
else
echo "Skipping latest_translation_commit.json update for ${GITHUB_EVENT_NAME} run."
fi
echo "has_changes=true" >> "${GITHUB_OUTPUT}"
- name: Set build metadata
id: build_meta
if: steps.changes.outputs.has_changes == 'true'
shell: bash
run: |
echo "date=$(TZ=Asia/Shanghai date +'%Y-%m-%d')" >> "${GITHUB_OUTPUT}"
echo "id=$(TZ=Asia/Shanghai date +'%Y%m%d')-$(date +%s)" >> "${GITHUB_OUTPUT}"
- name: Create PR
if: steps.changes.outputs.has_changes == 'true'
uses: peter-evans/create-pull-request@v8
with:
path: docs
token: ${{ github.token }}
branch: zh-translation/cloud-${{ steps.build_meta.outputs.id }}
base: ${{ env.CN_CLOUD_BRANCH }}
title: "${{ env.CN_CLOUD_BRANCH }}: translate Cloud doc changes from ${{ env.SOURCE_REPO }} ${{ env.SOURCE_BRANCH }} on ${{ steps.build_meta.outputs.date }}"
labels: |
translation/no-need
body: |
### What is changed, added or deleted? (Required)
Translate Cloud documentation changes from `pingcap/docs` `${{ env.SOURCE_BRANCH }}` to Chinese via `ai-pr-translator` commit-diff sync.
English commit diff:
https://github.com/${{ env.SOURCE_REPO }}/compare/${{ steps.commits.outputs.base_ref }}...${{ steps.commits.outputs.head_ref }}
### Which TiDB version(s) do your changes apply to? (Required)
- [x] ${{ env.CN_CLOUD_BRANCH }}
### What is the related PR or file link(s)?
- Source repo: `${{ env.SOURCE_REPO }}`
- Source branch: `${{ env.SOURCE_BRANCH }}`
- Cloud TOCs: `${{ env.CLOUD_TOC_FILES }}`
- Source files: `${{ steps.source_files.outputs.files }}`
- Sync outcome: `${{ steps.sync.outcome }}`
${{ steps.changes.outputs.failure_summary }}
### Do your changes match any of the following descriptions?
- [ ] Delete files
- [ ] Change aliases
- [ ] Need modification after applied to another branch
- [ ] Might cause conflicts after applied to another branch
delete-branch: true