Skip to content

Commit a2e664e

Browse files
committed
chore(generate-readme-translations): refactor workflow to simplify README translation process and improve artifact handling
- Remove unnecessary steps for reading and escaping README content. - Update the action version for translation to v1.2.0 for better performance. - Use content_path to directly reference README.md for translation. - Add step to upload each translated file as an artifact. - Introduce a new commit step to handle all translated README files at once.
1 parent 2cc9e68 commit a2e664e

File tree

1 file changed

+27
-33
lines changed

1 file changed

+27
-33
lines changed

.github/workflows/generate-readme-translations.yml

+27-33
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,8 @@ jobs:
3232
ref: main
3333
token: ${{ secrets.GH_TOKEN }}
3434

35-
- name: Read README content
36-
id: readme
37-
run: |
38-
content=$(cat README.md)
39-
# Escape quotes first
40-
content="${content//\"/\\\"}"
41-
# Then handle other special characters
42-
content="${content//'%'/'%25'}"
43-
content="${content//$'\n'/'%0A'}"
44-
content="${content//$'\r'/'%0D'}"
45-
# Escape HTML attributes
46-
content="${content//align=\"/align=\\\"}"
47-
content="${content//width=\"/width=\\\"}"
48-
echo "content=$content" >> $GITHUB_OUTPUT
49-
5035
- name: Translate to ${{ matrix.language.name }}
51-
uses: 0xjord4n/aixion@v1.0.2
36+
uses: 0xjord4n/aixion@v1.2.0
5237
id: aixion
5338
with:
5439
config: >
@@ -64,31 +49,40 @@ jobs:
6449
},
6550
{
6651
"role": "user",
67-
"content": "${{ steps.readme.outputs.content }}"
52+
"content_path": "README.md"
6853
}
6954
],
55+
"save_path": "README_${{ matrix.language.code }}.md",
7056
"model": "gpt-4o"
7157
}
7258
73-
- name: Save translation
74-
run: |
75-
# Create a temporary variable with the translation
76-
translation='${{ steps.aixion.outputs.text }}'
77-
# Escape any quotes and special characters
78-
translation="${translation//\"/\\\"}"
79-
translation="${translation//'%'/'%25'}"
80-
translation="${translation//$'\n'/'%0A'}"
81-
translation="${translation//$'\r'/'%0D'}"
82-
# Write the escaped content to file
83-
echo "$translation" > README_${{ matrix.language.code }}.md
59+
# Upload each translated file as an artifact
60+
- name: Upload translation
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: readme-${{ matrix.language.code }}
64+
path: README_${{ matrix.language.code }}.md
65+
66+
commit:
67+
needs: translation
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
with:
72+
ref: main
73+
token: ${{ secrets.GH_TOKEN }}
8474

85-
- name: List README translations
86-
run: ls README_*.md || echo "No translation files found"
75+
# Download all translation artifacts
76+
- name: Download all translations
77+
uses: actions/download-artifact@v4
78+
with:
79+
pattern: readme-*
80+
merge-multiple: true
8781

88-
- name: Commit translations
82+
- name: Commit all translations
8983
uses: stefanzweifel/git-auto-commit-action@v5
9084
with:
91-
commit_message: "chore: update ${{ matrix.language.name }} translation"
85+
commit_message: "chore: update all README translations"
9286
branch: main
93-
file_pattern: "README_${{ matrix.language.code }}.md"
87+
file_pattern: "README_*.md"
9488
commit_author: "GitHub Action <actions@github.com>"

0 commit comments

Comments
 (0)