forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (133 loc) · 7.56 KB
/
push_and_pull_crowdin_translations.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
name: Push and pull Crowdin translations
permissions:
actions: write
checks: write
contents: write
deployments: write
pull-requests: write
statuses: write
on:
workflow_dispatch:
push:
branches:
- master
jobs:
push_and_pull_crowdin_translations:
if: github.repository == 'deriv-com/deriv-app'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Setup node
uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8
with:
node-version: ${{ matrix.node-version }}
# We checkout the master branch so we can run the translations
# script on the latest changes.
- name: Checkout master branch
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Import GPG key
id: import-gpg
uses: deriv-com/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
# In this step we're doing a couple things:
# - We generate a new messages.json
# - We hash the newly generated messages.json and compare it with the messages.json on Crowdin.
# - We download the latest translation files from Crowdin, if there are new files, we create a PR.
- name: Generate and push to Crowdin
env:
GIT_AUTHOR_NAME: ${{ steps.import-gpg.outputs.name }}
GIT_AUTHOR_EMAIL: ${{ steps.import-gpg.outputs.email }}
GIT_COMMITTER_NAME: ${{ steps.import-gpg.outputs.name }}
GIT_COMMITTER_EMAIL: ${{ steps.import-gpg.outputs.email }}
run: |
branch_name="deriv_app_translations"
echo "Installing Crowdin CLI and bootstrapping project"
sudo npm i -g @crowdin/cli
npm run bootstrap
echo "Checking out new branch [$branch_name]"
git checkout -b "$branch_name"
echo "Running the translation script (extract-translations.js)"
cd $(git rev-parse --show-toplevel)/packages/translations/scripts
node extract-translations.js
new_messages_json_hash="$(git hash-object $(git rev-parse --show-toplevel)/packages/translations/crowdin/messages.json)"
echo "- [generated]: message.json hash is $new_messages_json_hash"
echo "Downloading messages.json from Crowdin for comparison"
cd $(git rev-parse --show-toplevel)/packages/translations
crowdin download sources -T ${{ secrets.CROWDIN_API_KEY }}
crowdin_messages_json_hash="$(git hash-object messages.json)"
echo "- [crowdin]: message.json hash is $crowdin_messages_json_hash"
rm messages.json
echo "Running the translation script (extract-translations.js) in p2p"
cd $(git rev-parse --show-toplevel)/packages/p2p/scripts
node extract-translations.js
new_p2p_messages_json_hash="$(git hash-object $(git rev-parse --show-toplevel)/packages/p2p/crowdin/messages.json)"
echo "- [generated]: message.json hash is $new_p2p_messages_json_hash"
echo "Downloading messages.json from Crowdin for comparison"
cd $(git rev-parse --show-toplevel)/packages/p2p
crowdin download sources -T ${{ secrets.CROWDIN_API_KEY }}
crowdin_p2p_messages_json_hash="$(git hash-object messages.json)"
echo "- [crowdin]: message.json hash is $crowdin_p2p_messages_json_hash"
rm messages.json
# We compare the generated messages.json with the messages.json from Crowdin.
# Only send a Slack message and upload it to Crowdin if there were any changes made to messages.json.
if [ "$crowdin_messages_json_hash" != "$new_messages_json_hash" ]; then
echo "Hashes are different, uploading to Crowdin"
echo "- [crowdin]: $crowdin_messages_json_hash";
echo "- [generated]: $new_messages_json_hash";
# Upload to Crowdin.
cd $(git rev-parse --show-toplevel)/packages/translations
echo "Uploading new strings to Crowdin"
crowdin upload sources -T ${{ secrets.CROWDIN_API_KEY }}
# Send a message to Slack (granted we have a webhook secret).
# This check also allows a repo admin to disable the Slack message by removing the secret.
if [ -n "${{ secrets.TRANSLATIONS_SLACK_WEBHOOK }}" ]; then
echo "Sending message to Slack (#team_translations)"
curl -X POST -H 'Content-type: application/json' --data '{"text":"There are new or updated strings available for Deriv.app (https://crowdin.com/project/deriv-app)."}' ${{ secrets.TRANSLATIONS_SLACK_WEBHOOK }}
fi
fi
# We compare the generated messages.json with the messages.json from Crowdin in p2p.
# Only send a Slack message and upload it to Crowdin if there were any changes made to messages.json.
if [ "$crowdin_p2p_messages_json_hash" != "$new_p2p_messages_json_hash" ]; then
echo "Hashes are different, uploading to Crowdin"
echo "- [crowdin]: $crowdin_p2p_messages_json_hash";
echo "- [generated]: $new_p2p_messages_json_hash";
# Upload to Crowdin.
cd $(git rev-parse --show-toplevel)/packages/p2p
echo "Uploading new strings to Crowdin"
crowdin upload sources -T ${{ secrets.CROWDIN_API_KEY }}
# Send a message to Slack (granted we have a webhook secret).
# This check also allows a repo admin to disable the Slack message by removing the secret.
if [ -n "${{ secrets.TRANSLATIONS_SLACK_WEBHOOK }}" ]; then
echo "Sending message to Slack (#team_translations)"
curl -X POST -H 'Content-type: application/json' --data '{"text":"There are new or updated strings available for DP2P (https://crowdin.com/project/deriv-app)."}' ${{ secrets.TRANSLATIONS_SLACK_WEBHOOK }}
fi
fi
# Download latest translations from Crowdin
cd $(git rev-parse --show-toplevel)/packages/translations
echo "Attempting to download updated translations from Crowdin"
crowdin download -T ${{ secrets.CROWDIN_API_KEY }}
# Download latest translations from Crowdin in p2p
cd $(git rev-parse --show-toplevel)/packages/p2p
echo "Attempting to download updated translations from Crowdin"
crowdin download -T ${{ secrets.CROWDIN_API_KEY }}
if [ -z "$(git status --porcelain)" ]; then
echo "Found no new translation files that need to be merged with master. Not creating a PR."
else
echo "Found updated translation files that need to be merged with master. Creating a PR."
# Commit the newly downloaded files
cd $(git rev-parse --show-toplevel)
git add .
git commit -m "translations: 📚 sync translations with crowdin"
# Force push to this branch in case a previous run created it.
git push --set-upstream origin "$branch_name" -f
sudo apt install gh
gh auth login --with-token <<< ${{ github.token }}
gh pr close "$branch_name" || true
gh pr create --base "master" --title "Sync Crowdin Translations 📚" --head "deriv-com:$branch_name" --body "This is an automated Pull Request designed to synchronize our project's translations with Crowdin. It pushes new strings for translation and pulls completed translations, ensuring our project remains multilingual and up-to-date."
fi