mirror of
https://github.com/alibaba/higress.git
synced 2026-05-28 14:47:29 +08:00
polish translate-readme action (#2020)
This commit is contained in:
67
.github/workflows/helm-docs.yaml
vendored
67
.github/workflows/helm-docs.yaml
vendored
@@ -39,7 +39,6 @@ jobs:
|
|||||||
rm -f ./helm-docs
|
rm -f ./helm-docs
|
||||||
|
|
||||||
translate-readme:
|
translate-readme:
|
||||||
if: ${{ ! always() }}
|
|
||||||
needs: helm
|
needs: helm
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
@@ -52,7 +51,26 @@ jobs:
|
|||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y jq
|
sudo apt-get install -y jq
|
||||||
|
|
||||||
|
- name: Compare README.md
|
||||||
|
id: compare_readme
|
||||||
|
run: |
|
||||||
|
cd ./helm/higress
|
||||||
|
BASE_BRANCH=main
|
||||||
|
UPSTREAM_REPO=https://github.com/alibaba/higress.git
|
||||||
|
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
git clone --depth 1 --branch $BASE_BRANCH $UPSTREAM_REPO $TEMP_DIR
|
||||||
|
|
||||||
|
if diff -q "$TEMP_DIR/README.md" README.md > /dev/null; then
|
||||||
|
echo "README.md has no changes in comparison to base branch. Skipping translation."
|
||||||
|
echo "skip_translation=true" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "README.md has changed in comparison to base branch. Proceeding with translation."
|
||||||
|
echo "skip_translation=false" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
|
||||||
- name: Translate README.md to Chinese
|
- name: Translate README.md to Chinese
|
||||||
|
if: env.skip_translation == 'false'
|
||||||
env:
|
env:
|
||||||
API_URL: ${{ secrets.HIGRESS_OPENAI_API_URL }}
|
API_URL: ${{ secrets.HIGRESS_OPENAI_API_URL }}
|
||||||
API_KEY: ${{ secrets.HIGRESS_OPENAI_API_KEY }}
|
API_KEY: ${{ secrets.HIGRESS_OPENAI_API_KEY }}
|
||||||
@@ -79,37 +97,30 @@ jobs:
|
|||||||
-H "Authorization: Bearer $API_KEY" \
|
-H "Authorization: Bearer $API_KEY" \
|
||||||
-d "$PAYLOAD")
|
-d "$PAYLOAD")
|
||||||
|
|
||||||
echo "response: $RESPONSE"
|
echo "Response: $RESPONSE"
|
||||||
|
|
||||||
TRANSLATED_CONTENT=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
|
echo "$RESPONSE" | jq -c -r '.choices[] | .message.content' > README.zh.new.md
|
||||||
|
|
||||||
if [ -z "$TRANSLATED_CONTENT" ]; then
|
if [ -f "README.zh.new.md" ]; then
|
||||||
echo "Translation failed! Response: $RESPONSE"
|
echo "Translation completed and saved to README.zh.new.md."
|
||||||
|
else
|
||||||
|
echo "Translation failed or no content returned!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$TRANSLATED_CONTENT" > README.zh.new.md
|
mv README.zh.new.md README.zh.md
|
||||||
echo "Translation completed and saved to README.zh.new.md."
|
|
||||||
|
|
||||||
- name: Compare README.zh.md
|
- name: Create Pull Request
|
||||||
id: compare
|
if: env.skip_translation == 'false'
|
||||||
run: |
|
uses: peter-evans/create-pull-request@v7
|
||||||
cd ./helm/higress
|
with:
|
||||||
NEW_README_ZH="README.zh.new.md"
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
EXISTING_README_ZH="README.zh.md"
|
commit-message: "Update helm translated README.zh.md"
|
||||||
|
branch: update-helm-readme-zh
|
||||||
|
title: "Update helm translated README.zh.md"
|
||||||
|
body: |
|
||||||
|
This PR updates the translated README.zh.md file.
|
||||||
|
|
||||||
if [ ! -f "$EXISTING_README_ZH" ]; then
|
- Automatically generated by GitHub Actions
|
||||||
echo "Add README.zh.md."
|
labels: translation, automated
|
||||||
mv "$NEW_README_ZH" "$EXISTING_README_ZH"
|
base: main
|
||||||
echo "updated=true" >> $GITHUB_ENV
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! diff -q "$NEW_README_ZH" "$EXISTING_README_ZH"; then
|
|
||||||
echo "Files are different. Updating README.zh.md."
|
|
||||||
mv "$NEW_README_ZH" "$EXISTING_README_ZH"
|
|
||||||
echo "updated=true" >> $GITHUB_ENV
|
|
||||||
else
|
|
||||||
echo "Files are identical. No update needed."
|
|
||||||
echo "updated=false" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user