Skip to content

Commit 2af577d

Browse files
authored
ci: refactor file diff update (#22229)
1 parent 7d8fe2a commit 2af577d

5 files changed

Lines changed: 40 additions & 490 deletions

File tree

.github/workflows/translation-cron.yml

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,25 @@ jobs:
6969
sudo apt install tree -y
7070
7171
- name: Download files by comparing commits
72+
uses: pingcap/docs-toolkit/actions/file-diff-update@main
73+
with:
74+
config_file: latest_translation_commit.json
75+
working_directory: docs
76+
77+
- name: Show tmp directory structure
7278
run: |
73-
export GH_TOKEN=${{github.token}}
7479
cd docs
75-
npm i
76-
node scripts/filterUpdateFiles.js
77-
tree tmp
78-
cd ..
79-
- name: Copy new files to translator folder
80-
run: |
81-
cp -r docs/tmp docs-toolkit/markdown-translator/markdowns
82-
- name: Copy variables.json to translator folder
83-
run: |
84-
cp docs/variables.json docs-toolkit/markdown-translator/markdowns/variables.json
85-
if [ -f docs/tmp/variables.json ]; then
86-
cp docs/tmp/variables.json docs-toolkit/markdown-translator/markdowns/variables.json
87-
cp docs/tmp/variables.json docs/variables.json
88-
fi
80+
tree tmp || find tmp -type f | head -20
8981
- name: Config and translate
9082
run: |
9183
cd docs-toolkit/markdown-translator
84+
yarn
85+
cd ../..
9286
echo ${{secrets.GCP_KEY}} | base64 --decode >> key.json
9387
export GOOGLE_APPLICATION_CREDENTIALS=key.json
9488
export PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}
9589
export GLOSSARY_ID=${{ secrets.GCP_GLOSSARY_ID }}
96-
yarn
97-
node src/index_ja.js
98-
cd ..
99-
- name: Copy translated files to docs repo
100-
run: |
101-
cp -r docs-toolkit/markdown-translator/output/markdowns/* docs/
90+
node docs-toolkit/markdown-translator/src/index_ja.js --input-dir docs/tmp --output-dir docs/
10291
10392
- name: Git commit and push
10493
run: |

.github/workflows/translation-zh.yaml

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,31 @@ jobs:
3737
- run: |
3838
sudo apt install tree -y
3939
40-
- name: Download files by comparing commits
40+
- name: Download files
41+
uses: pingcap/docs-toolkit/actions/file-diff-update@main
42+
with:
43+
config_file: latest_translation_commit.json
44+
working_directory: docs
45+
filter_by_cloud_toc: 'true'
46+
files: ${{ inputs.file_names }}
47+
48+
- name: Show tmp directory structure
4149
run: |
42-
export GH_TOKEN=${{github.token}}
4350
cd docs
44-
npm i
45-
if [ -n "${{ inputs.file_names }}" ]; then
46-
node scripts/fetchFiles.js --files "${{ inputs.file_names }}"
47-
else
48-
node scripts/filterUpdateFiles.js --cloud
49-
fi
50-
tree tmp
51-
cd ..
52-
- name: Copy new files to translator folder
53-
run: |
54-
cp -r docs/tmp docs-toolkit/markdown-translator/markdowns
55-
- name: Copy variables.json to translator folder
56-
run: |
57-
cp docs/variables.json docs-toolkit/markdown-translator/markdowns/variables.json
58-
if [ -f docs/tmp/variables.json ]; then
59-
cp docs/tmp/variables.json docs-toolkit/markdown-translator/markdowns/variables.json
60-
cp docs/tmp/variables.json docs/variables.json
61-
fi
51+
tree tmp || find tmp -type f | head -20
6252
- name: Config and translate
6353
run: |
6454
cd docs-toolkit/markdown-translator
55+
yarn
56+
cd ../..
57+
echo ${{secrets.GCP_KEY}} | base64 --decode >> key.json
58+
export GOOGLE_APPLICATION_CREDENTIALS=key.json
59+
export PROJECT_ID=${{ secrets.GCP_PROJECT_ID }}
60+
export GLOSSARY_ID=${{ secrets.GCP_GLOSSARY_ID }}
6561
export LANGLINK_ACCESS_KEY=${{ secrets.LANGLINK_ACCESS_KEY }}
6662
export LANGLINK_ACCESS_SECRET=${{ secrets.LANGLINK_ACCESS_SECRET }}
6763
export LANGLINK_USER=${{ secrets.LANGLINK_USER }}
68-
yarn
69-
node src/index.js
70-
cd ..
71-
- name: Copy translated files to docs repo
72-
run: |
73-
cp -r docs-toolkit/markdown-translator/output/markdowns/* docs/
64+
node docs-toolkit/markdown-translator/src/index.js --input-dir docs/tmp --output-dir docs/
7465
7566
- name: Set build ID
7667
id: build_id

scripts/fetchFiles.js

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)