Skip to content

chore: test add (#2283) #692

chore: test add (#2283)

chore: test add (#2283) #692

name: GPT Translate per Commit
on:
push:
branches:
- main
paths-ignore:
- ".github**/*"
- "docs/cn/**/*"
- "docs/release-notes/**/*"
- "docs/fragment/**/*"
- "docs/release-stable/**/*"
- "api/**/*"
- "i18n/**/*"
- "src/**/*"
- "static/**/*"
- "types/**/*"
- "README.md"
jobs:
gpt_translate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository with two latest commits
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Get changed files name
id: changed_files
run: |
added_or_modified=$(git diff --diff-filter=d --name-only HEAD^ HEAD | grep '\.md$' | grep -v 'cn')
echo "files=$(echo "$added_or_modified" | sed -e 's/^/.\//' | tr '\n' ' ')" >> $GITHUB_OUTPUT
deleted=$(git diff --diff-filter=D --name-only HEAD^ HEAD | grep '\.md$' | grep -v 'cn')
echo "deleted_files=$(echo "$deleted" | tr '\n' ' ')" >> $GITHUB_OUTPUT
- name: Read prompt from file
id: prompt
run: |
echo 'prompt<<EOF' >> $GITHUB_OUTPUT
cat .github/workflows/prompt.txt >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Run GPT Translate
if: steps.changed_files.outputs.files != ''
uses: 3ru/[email protected]
with:
apikey: ${{ secrets.API_KEY }}
model: ${{ secrets.LLM_MODEL }}
inputFiles: "${{ steps.changed_files.outputs.files }}"
outputFiles: "docs/cn/**/*.md"
languages: "Simplified-Chinese"
prompt: "${{ steps.prompt.outputs.prompt }}"
basePath: ${{ secrets.BASE_URL }}
- name: Delete corresponding Chinese files
if: steps.changed_files.outputs.deleted_files != ''
run: |
for file in ${{ steps.changed_files.outputs.deleted_files }}; do
cn_file="docs/cn/$file"
if [ -f "$cn_file" ]; then
echo "Deleting $cn_file"
git rm "$cn_file"
fi
done
- name: Commit deleted translations
if: steps.changed_files.outputs.deleted_files != ''
run: |
git config user.name "github-actions"
git config user.email "[email protected]"
git commit -m "chore(i18n): remove translated docs for deleted English sources" || echo "Nothing to commit"
git push