Skip to content

Commit 4ef751c

Browse files
committed
ci: optimize the doc translation pipeline to run partial changes
1 parent 4e51cc8 commit 4ef751c

File tree

1 file changed

+58
-6
lines changed

1 file changed

+58
-6
lines changed

.github/workflows/update-docs.yml

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,79 @@ jobs:
3838
uses: actions/checkout@v6
3939
with:
4040
fetch-depth: 0
41+
- name: Detect translation scope
42+
id: translate-scope
43+
shell: bash
44+
run: |
45+
set -euo pipefail
46+
before="${{ github.event.before }}"
47+
sha="${{ github.sha }}"
48+
changed_files=$(git diff --name-only --diff-filter=ACMR "$before" "$sha" -- docs mkdocs.yml || true)
49+
page_list="$(mktemp "${RUNNER_TEMP}/page-files-XXXXXX.txt")"
50+
non_page_found=false
51+
while IFS= read -r file; do
52+
if [ -z "$file" ]; then
53+
continue
54+
fi
55+
if [[ "$file" =~ ^docs/.*\.md$ ]] \
56+
&& [[ ! "$file" =~ ^docs/(ja|ko|zh)/ ]] \
57+
&& [[ ! "$file" =~ ^docs/ref/ ]]; then
58+
if [ -f "$file" ]; then
59+
echo "$file" >> "$page_list"
60+
fi
61+
else
62+
non_page_found=true
63+
fi
64+
done <<< "$changed_files"
65+
66+
if [ -s "$page_list" ] && [ "$non_page_found" = "false" ]; then
67+
echo "mode=partial" >> "$GITHUB_OUTPUT"
68+
echo "page_files=$page_list" >> "$GITHUB_OUTPUT"
69+
else
70+
echo "mode=full" >> "$GITHUB_OUTPUT"
71+
rm -f "$page_list"
72+
fi
4173
- name: Setup uv
4274
uses: astral-sh/setup-uv@v5
4375
with:
4476
enable-cache: true
4577
- name: Install dependencies
4678
run: make sync
47-
- name: Build full docs
48-
run: make build-full-docs
79+
- name: Build translated docs
80+
run: |
81+
if [ "${{ steps.translate-scope.outputs.mode }}" = "partial" ]; then
82+
echo "Translating changed pages only."
83+
while IFS= read -r file; do
84+
if [ -n "$file" ]; then
85+
uv run docs/scripts/translate_docs.py --file "$file"
86+
fi
87+
done < "${{ steps.translate-scope.outputs.page_files }}"
88+
uv run mkdocs build
89+
else
90+
echo "Translating full docs set."
91+
make build-full-docs
92+
fi
93+
94+
- name: Cleanup temp page list
95+
if: steps.translate-scope.outputs.mode == 'partial'
96+
run: |
97+
page_list="${{ steps.translate-scope.outputs.page_files }}"
98+
if [ -n "$page_list" ] && [ -f "$page_list" ]; then
99+
rm -f "$page_list"
100+
fi
49101
50102
- name: Commit changes
51103
id: commit
52104
run: |
53105
git config user.name "github-actions[bot]"
54106
git config user.email "github-actions[bot]@users.noreply.github.com"
55107
git add docs/
56-
if [ -n "$(git status --porcelain)" ]; then
57-
git commit -m "Update all translated document pages"
58-
echo "committed=true" >> "$GITHUB_OUTPUT"
59-
else
108+
if git diff --cached --quiet; then
60109
echo "No changes to commit"
61110
echo "committed=false" >> "$GITHUB_OUTPUT"
111+
else
112+
git commit -m "Update all translated document pages"
113+
echo "committed=true" >> "$GITHUB_OUTPUT"
62114
fi
63115
64116
- name: Create Pull Request

0 commit comments

Comments
 (0)