Skip to content

henry/dtra-434/fix: failing test cases on master (#10392) #41

henry/dtra-434/fix: failing test cases on master (#10392)

henry/dtra-434/fix: failing test cases on master (#10392) #41

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 == 'binary-com/deriv-app'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Setup node
uses: actions/setup-node@v2
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/[email protected]
# 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
run: |
branch_name="deriv_app_translations"
echo "Setting up Git identity"
git config --global user.name "DerivFE"
git config --global user.email "[email protected]"
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 --fill --base "master" --head "binary-com:$branch_name"
fi