-
Notifications
You must be signed in to change notification settings - Fork 23
254 lines (250 loc) · 10.4 KB
/
updateLocalizations.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
on:
workflow_dispatch
jobs:
update_en_localization:
environment: update localizations
runs-on: ubuntu-latest
env:
LOC_BOT_NAME: ${{secrets.LOC_BOT_NAME}}
LOC_BOT_EMAIL: ${{secrets.LOC_BOT_EMAIL}}
GH_TOKEN: ${{secrets.LOC_TOKEN}}
APPROVE_BOT_NAME: ${{secrets.APPROVE_BOT_NAME}}
APPROVE_BOT_EMAIL: ${{secrets.APPROVE_BOT_EMAIL}}
outputs:
branch-name: ${{steps.info.outputs.branch-name}}
pr-name: ${{steps.info.outputs.pr-name}}
steps:
- name: Prepare info
id: info
run: |
echo "branch-name=$(date +"${{ env.BRANCH_PATTERN }}_%F_%H-%M-%S")" >> $GITHUB_OUTPUT
echo "pr-name=$(date +'New translations (%F %T %Z)')" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3
with:
token: ${{secrets.LOC_TOKEN}}
submodules: recursive
persist-credentials: true
- name: Set Loc bot config details
run: |
git config --global user.name $LOC_BOT_NAME
git config --global user.email $LOC_BOT_EMAIL
git config --global core.autocrlf false
git config core.longpaths true
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{secrets.GPG_TOKEN}}
passphrase: ${{secrets.PASS_PHRASE}}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Update submodules
run: |
git checkout -b $BRANCH
git submodule init
git submodule update --remote --recursive
for folder in visuals/*; do
git -C $folder config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
done;
echo "::group::Fetch dev branch"
git submodule foreach --recursive 'git fetch; git checkout dev || echo "No dev branch in $name"'
echo "::endgroup::"
env:
BRANCH: ${{steps.info.outputs.branch-name}}
- name: Copy EN translation
run: |
for file in ./visuals/*/stringResources/en-US/resources.resjson; do
substring="visuals/"
location="${file/$substring/localizations/}"
substring="/stringresources"
newLocation="${location/$substring//stringResources}"
test -f $newLocation || mkdir -p ${newLocation%resources.resjson*}
cp $file $newLocation;
done;
- name: Commit and push changes
run: |
changes="$(git diff)"
if [[ $changes != "" ]]; then
defaultBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git add . && \
git commit -S -m "New translations" && \
git push --set-upstream origin $BRANCH && \
gh pr create -B $defaultBranchName -b "Auto created Pull Request with new translations" -t "$PR_NAME" || \
echo "New pull request to $repoName wasn't created"
else
echo "No changes"
fi
env:
PR_NAME: ${{steps.info.outputs.pr-name}}
BRANCH: ${{steps.info.outputs.branch-name}}
- name: Set Loc bot config details
run: |
git config --global user.name $APPROVE_BOT_NAME
git config --global user.email $APPROVE_BOT_EMAIL
- name: Approve pull request
run: |
pullRequestNumber=$(gh pr list --state=open --head=$BRANCH --json number)
if [[ $pullRequestNumber != "[]" ]]; then
defaultBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
changes="$(git diff origin/$defaultBranchName)"
if [[ $changes != "" ]]; then
gh pr review $BRANCH --approve
echo "Pull request was approved"
gh pr merge $BRANCH -s --auto -t "New translations"
echo "Pull request was merged"
else
gh pr close -d $BRANCH
echo "No changes"
fi
else
echo "No pull request"
fi
env:
GH_TOKEN: ${{secrets.APPROVE_TOKEN}}
BRANCH: ${{steps.info.outputs.branch-name}}
update_other_localizations:
environment: update localizations
runs-on: ubuntu-latest
needs: update_en_localization
env:
LOC_BOT_NAME: ${{secrets.LOC_BOT_NAME}}
LOC_BOT_EMAIL: ${{secrets.LOC_BOT_EMAIL}}
GH_TOKEN: ${{secrets.LOC_TOKEN}}
APPROVE_BOT_NAME: ${{secrets.APPROVE_BOT_NAME}}
APPROVE_BOT_EMAIL: ${{secrets.APPROVE_BOT_EMAIL}}
steps:
- uses: actions/checkout@v3
with:
token: ${{secrets.LOC_TOKEN}}
submodules: recursive
persist-credentials: true
- name: Set Loc bot config details
run: |
git config --global user.name $LOC_BOT_NAME
git config --global user.email $LOC_BOT_EMAIL
git config --global core.autocrlf false
- uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{secrets.GPG_TOKEN}}
passphrase: ${{secrets.PASS_PHRASE}}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Update submodules
run: |
git pull --recurse-submodules
git submodule update --remote --recursive
for folder in visuals/*; do
git -C $folder config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
done;
echo "::group::Fetch dev branch"
git submodule foreach --recursive '\
git fetch; \
git checkout dev || echo "No dev branch in $name"; \
git checkout -b $BRANCH'
echo "::endgroup::"
env:
BRANCH: ${{needs.update_en_localization.outputs.branch-name}}
- name: Copy translations to submodules
run: |
for visualPath in ./localizations/*; do
repoName=$(echo $visualPath| cut -d'/' -f 3)
echo "::group::Copy to $repoName"
for filePath in $visualPath/stringResources/*/resources.resjson; do
if [[ $filePath == *"/en-US/"* ]]; then
continue
fi
substring="localizations/"
newLocation="${filePath/$substring/visuals/}"
dirToCreate=${newLocation%resources.resjson*}
if [ ! -d "$dirToCreate" ]; then
echo "Creating directory: $dirToCreate"
mkdir -p "$dirToCreate"
fi
echo "Copying $filePath to $newLocation"
cp $filePath $newLocation;
done;
echo "::endgroup::"
done;
- name: Delete old Pull Requests
run: |
for folder in visuals/*; do
repoName=$(echo $folder| cut -d'/' -f 2)
echo "::group::Delete old PRs in $repoName"
# List open pull requests and filter by branch pattern
matching_prs=$(gh pr list --repo "$REPO_OWNER/$repoName" -A "@me" --state open --json number,headRefName \
--jq ".[] | select(.headRefName | test(\"$BRANCH_PATTERN\")) | .number")
if [ -z "$matching_prs" ]; then
echo "No open pull requests matching the branch pattern \"$BRANCH_PATTERN\"."
else
for pr in $matching_prs; do
# Close the pull request
gh pr close "$pr" --repo "$REPO_OWNER/$repoName" --delete-branch ||
echo "Can't close Pull Request to $repoName, check an access"
done
fi
echo "::endgroup::"
done
env:
BRANCH_PATTERN: '${{ env.BRANCH_PATTERN }}_.*'
REPO_OWNER: 'microsoft'
- name: Commit and push new changes to submodules
run: |
mainFolder=$PWD
for folder in visuals/*; do
repoName=$(echo $folder| cut -d'/' -f 2)
echo "::group::Commit to $repoName"
cd "$mainFolder/$folder"
changes="$(git diff)"
if [[ $changes == "" ]]; then
echo "No changes for $repoName"
continue
fi
originalBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
if git show-ref --quiet refs/heads/dev; then
originalBranchName=dev
fi
git add . &&
git commit -S -m "New translations" &&
git push --set-upstream origin $BRANCH &&
gh pr create -B $originalBranchName -b "Auto created Pull Request with new translations" -t "$PR_NAME" ||
echo "New pull request to $repoName wasn't created"
echo "::endgroup::"
done;
env:
BRANCH: ${{needs.update_en_localization.outputs.branch-name}}
PR_NAME: ${{needs.update_en_localization.outputs.pr-name}}
- name: Set Loc bot config details
run: |
git config --global user.name $APPROVE_BOT_NAME
git config --global user.email $APPROVE_BOT_EMAIL
- name: Approve pull requests
continue-on-error: true
run: |
mainFolder=$PWD
for folder in visuals/*; do
repoName=$(echo $folder| cut -d'/' -f 2)
echo "::group::Approve and merge to $repoName"
cd "$mainFolder/$folder"
pullRequestNumber=$(gh pr list --state=open --head=$BRANCH --json number)
if [[ $pullRequestNumber == "[]" ]]; then
echo "No pull request for $repoName"
continue
fi
originalBranchName=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
if git show-ref --quiet refs/heads/dev; then
originalBranchName=dev
fi
changes="$(git diff origin/$originalBranchName)"
if [[ $changes == "" ]]; then
gh pr close -d $BRANCH
echo "No changes for $repoName"
continue
fi
gh pr review $BRANCH --approve || echo "Can't approve Pull Request to $repoName"
gh pr merge $BRANCH -s --auto -t "New translations" &&
echo "Pull request to $repoName was merged" || echo "Cann't merge Pull Request to $repoName"
echo "::endgroup::"
done;
env:
GH_TOKEN: ${{secrets.APPROVE_TOKEN}}
BRANCH: ${{needs.update_en_localization.outputs.branch-name}}