forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (83 loc) · 4.08 KB
/
sync_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
name: Sync Crowdin translations
on:
workflow_dispatch:
push:
branches:
- master
jobs:
sync_crowdin_translations:
if: github.repository == 'binary-com/binary-static'
runs-on: ubuntu-latest
steps:
- name: Cancel previous running workflow
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'
- name: Checkout master branch
uses: actions/checkout@v2
- name: Setup Project and environment
run: |
branch_name="binary_static_translations"
echo "Setting up Git identity"
git config --global user.name "DerivFE"
git config --global user.email "[email protected]"
echo "Installing Crowdin CLI"
sudo npm i -g @crowdin/cli
echo "Installing project dependencies and building the project"
npm install
npm run build
echo "Checking out new branch [$branch_name]"
git checkout -b "$branch_name"
- name: Uploading new strings to Crowdin
run: |
last_messages_hash="$(git hash-object $(git rev-parse --show-toplevel)/src/translations/messages.pot)"
echo "Generating messages.pot"
node ./scripts/render.js -t
current_messages_hash="$(git hash-object $(git rev-parse --show-toplevel)/src/translations/messages.pot)"
echo "- [crowdin]: message.pot hash is: $last_messages_hash"
echo "- [generated]: message.pot hash is: $current_messages_hash"
# We compare the generated messages.pot with the last messages.pot.
# Only send a Slack message and upload it to Crowdin if there were any changes made to messages.pot.
if [ "$last_messages_hash" != "$current_messages_hash" ]; then
echo "Hashes are different, uploading to Crowdin"
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 Binary.com (https://crowdin.com/project/binary-static)."}' ${{ secrets.TRANSLATIONS_SLACK_WEBHOOK }}
fi
else
echo "No new string detected. Skip uploading messages.pot to Crowdin."
fi
- name: Downloading translation files from Crowdin
run: |
echo "Downloading translation files from Crowdin (*.po)"
crowdin download -T ${{ secrets.CROWDIN_API_KEY }}
echo "Updating javascript translation files (*.js)"
node ./scripts/render.js -j
- name: Create and merge translation PR
run: |
branch_name="binary_static_translations"
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."
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 <<< ${{ secrets.PERSONAL_ACCESS_TOKEN }}
gh pr close "$branch_name" || true
gh pr create --fill --base "master" --head "binary-com:$branch_name"
echo "Attempting to merge the PR."
gh pr merge "$branch_name" --admin --squash
echo "**The translation PR has beed merged successfully.**"
fi