@@ -28,16 +28,48 @@ jobs:
2828 - name : Get changed markdown files
2929 id : changed-files
3030 run : |
31- # Get the list of changed files between the current and previous commit
31+ # Get the list of newly added files between the current and previous commit
3232 # We filter for .md and .mdx files that are inside the language directories
33- files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E '^(en|zh-hans|ja-jp|plugin-dev-en|plugin-dev-zh|plugin-dev-ja)/.*(\.md|\.mdx)$' || true)
34- if [[ -z "$files" ]]; then
35- echo "No markdown files to translate."
33+ # Only include added (A) files, skip modified (M) and deleted (D) files
34+
35+ # Try different approaches to get the diff
36+ if [[ -n "${{ github.event.before }}" ]]; then
37+ echo "Using github.event.before: ${{ github.event.before }}"
38+ files=$(git diff --name-status ${{ github.event.before }} ${{ github.sha }} | grep -E '^A\s+' | cut -f2 | grep -E '^(en|en-us|zh-hans|ja-jp|plugin-dev-en|plugin-dev-zh|plugin-dev-ja|versions)/.*(\.md|\.mdx)$' || true)
39+ else
40+ echo "github.event.before is empty, using HEAD~1"
41+ files=$(git diff --name-status HEAD~1 HEAD | grep -E '^A\s+' | cut -f2 | grep -E '^(en|en-us|zh-hans|ja-jp|plugin-dev-en|plugin-dev-zh|plugin-dev-ja|versions)/.*(\.md|\.mdx)$' || true)
42+ fi
43+
44+ echo "Detected files (Added only):"
45+ echo "$files"
46+
47+ # Filter out files that don't actually exist
48+ existing_files=""
49+ if [[ -n "$files" ]]; then
50+ while IFS= read -r file; do
51+ if [[ -n "$file" && -f "$file" ]]; then
52+ if [[ -z "$existing_files" ]]; then
53+ existing_files="$file"
54+ else
55+ existing_files="$existing_files"$'\n'"$file"
56+ fi
57+ else
58+ echo "Skipping non-existent file: $file"
59+ fi
60+ done <<< "$files"
61+ fi
62+
63+ echo "Final files to translate:"
64+ echo "$existing_files"
65+
66+ if [[ -z "$existing_files" ]]; then
67+ echo "No new markdown files to translate."
3668 echo "files=" >> $GITHUB_OUTPUT
3769 else
3870 # The script expects absolute paths, but we run it from the root, so relative is fine.
3971 echo "files<<EOF" >> $GITHUB_OUTPUT
40- echo "$files " >> $GITHUB_OUTPUT
72+ echo "$existing_files " >> $GITHUB_OUTPUT
4173 echo "EOF" >> $GITHUB_OUTPUT
4274 fi
4375
@@ -49,12 +81,35 @@ jobs:
4981 echo "Files to translate:"
5082 echo "${{ steps.changed-files.outputs.files }}"
5183
52- echo "${{ steps.changed-files.outputs.files }}" | while IFS= read -r file; do
84+ # Create temporary file list
85+ echo "${{ steps.changed-files.outputs.files }}" > /tmp/files_to_translate.txt
86+
87+ # Start all translation processes in parallel
88+ pids=()
89+ while IFS= read -r file; do
5390 if [[ -n "$file" ]]; then
54- echo "Translating $file..."
55- python tools/translate/main.py "$file" "$DIFY_API_KEY"
91+ echo "Starting translation for $file..."
92+ python tools/translate/main.py "$file" "$DIFY_API_KEY" &
93+ pids+=($!)
94+ fi
95+ done < /tmp/files_to_translate.txt
96+
97+ # Wait for all background processes to complete
98+ echo "Waiting for ${#pids[@]} translation processes to complete..."
99+ failed=0
100+ for pid in "${pids[@]}"; do
101+ if ! wait "$pid"; then
102+ echo "Translation process $pid failed"
103+ failed=1
56104 fi
57105 done
106+
107+ if [ $failed -eq 1 ]; then
108+ echo "Some translations failed"
109+ exit 1
110+ fi
111+
112+ echo "All translations completed successfully"
58113
59114 - name : Commit and push changes
60115 run : |
0 commit comments