11name : Update translations
22
33on :
4+ push :
5+ branches : [main]
6+ paths :
7+ - ' public/locales/en/**'
48 workflow_dispatch :
59
610permissions : write-all
@@ -16,23 +20,76 @@ jobs:
1620 steps :
1721 - uses : actions/checkout@v4
1822 with :
19- fetch-depth : 0
23+ fetch-depth : 2
2024 - name : Extract namespaces
2125 id : extract-namespaces
26+ env :
27+ EVENT_NAME : ${{ github.event_name }}
2228 run : |
23- FILES=$(ls public/locales/en/ | sed 's/\.json$//')
24- NAMESPACES_ARRAY=$(echo "$FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
29+ if [[ "$EVENT_NAME" == "push" ]]; then
30+ MODIFIED_FILES=$(git diff --name-only HEAD^ HEAD | grep -E 'public/locales/en/.+\.json$' || echo "")
31+ NAMESPACES_ARRAY=$(echo "$MODIFIED_FILES" | awk 'NF' | jq -R -c -s '
32+ split("\n") |
33+ map(select(length > 0)) |
34+ map(capture("public/locales/en/(?<namespace>[^/]+)\\.json").namespace)
35+ ')
36+ else
37+ FILES=$(ls public/locales/en/ | sed 's/\.json$//')
38+ NAMESPACES_ARRAY=$(echo "$FILES" | jq -R -s -c 'split("\n") | map(select(length > 0))')
39+ fi
40+
2541 echo "namespaces=$NAMESPACES_ARRAY" >> $GITHUB_OUTPUT
2642
27- translations :
43+ create-pr :
44+ permissions :
45+ pull-requests : write
46+ contents : write
47+ runs-on : ubuntu-latest
2848 needs : prepare-inputs
49+ if : ${{ fromJson(needs.prepare-inputs.outputs.namespaces)[0] != null }}
50+ outputs :
51+ pr_number : ${{ steps.create-pr.outputs.pr_number }}
52+ steps :
53+ - uses : actions/checkout@v4
54+ with :
55+ fetch-depth : 0
56+ - uses : actions/setup-node@v3
57+ with :
58+ node-version : 20
59+ - name : Create pull request
60+ id : create-pr
61+ env :
62+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
63+ run : |
64+ echo "temporary file" > temporary-file.txt
65+
66+ git config user.email ""
67+ git config user.name "Update translations action"
68+ git checkout -b update-translations
69+ git add temporary-file.txt
70+
71+ export COMMIT_MESSAGE="initial commit"
72+ git commit -m "$COMMIT_MESSAGE"
73+ git push --set-upstream origin update-translations --force
74+ gh pr create --title "i18n: update translations" --body "" -a "dgaponov" -a "imsitnikov" -a "vvtimofeev" 2>/dev/null || true
75+ PR_NUMBER=$(gh pr view --json number -q ".number")
76+
77+ echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
78+
79+ translations :
80+ needs :
81+ - prepare-inputs
82+ - create-pr
2983 runs-on : ubuntu-latest
84+ if : ${{ fromJson(needs.prepare-inputs.outputs.namespaces)[0] != null }}
3085 strategy :
86+ max-parallel : 1
3187 matrix :
3288 namespace : ${{ fromJson(needs.prepare-inputs.outputs.namespaces) }}
3389 steps :
3490 - uses : actions/checkout@v4
3591 with :
92+ ref : refs/pull/${{ needs.create-pr.outputs.pr_number }}/head
3693 fetch-depth : 0
3794 - name : Prepare inputs for ${{ matrix.namespace }}
3895 id : prepare-inputs
64121 outputFiles : ${{ steps.prepare-inputs.outputs.output_files }}
65122 languages : ${{ env.LANGUAGES }}
66123 commitMessage : ' i18n: translations for namespace ${{ matrix.namespace }}'
67- pullRequestTitle : ' i18n: translations for namespace ${{ matrix.namespace }}'
124+ pullRequestNumber : ${{ needs.create-pr.outputs.pr_number }}
68125 prompt : |
69126 Please translate the json source file to {targetLanguage}. \
70127 Make the translation sound as natural as possible. \
@@ -75,6 +132,35 @@ jobs:
75132 "actions_openInFigma": "Open in Figma",
76133 "title": "Components",
77134 } \
78- Return only the json, no other text. Remove formatting like markdown ```json```. \
135+ Return only the json, no other text. \
136+ Remove formatting like markdown ```json```. \
137+ Do NOT add ``` tags to the result json. \
79138 Do not translate the library name in the source file if it looks like the name of the library (the exception is Themer, it can be translated). \
80139 For example, don't translate @gravity/uikit or Axios Wrapper - they need to be left in place.
140+
141+ merge-pr :
142+ needs :
143+ - create-pr
144+ - translations
145+ runs-on : ubuntu-latest
146+ if : ${{ needs.create-pr.outputs.pr_number != '' && needs.create-pr.outputs.pr_number != null }}
147+ steps :
148+ - uses : actions/checkout@v4
149+ with :
150+ ref : refs/pull/${{ needs.create-pr.outputs.pr_number }}/head
151+ fetch-depth : 2
152+ - name : Merge PR
153+ env :
154+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
155+ run : |
156+ git checkout update-translations
157+ git config user.email ""
158+ git config user.name "Update translations action"
159+ git checkout -b update-translations
160+ rm -rf temporary-file.txt
161+ git add .
162+
163+ export COMMIT_MESSAGE="remove temporary file"
164+ git commit -m "$COMMIT_MESSAGE"
165+ git push --set-upstream origin update-translations --force
166+ gh pr merge ${{ needs.create-pr.outputs.pr_number }} --auto --squash
0 commit comments