[WALL] Lubega / WALL-2935 / AvailableMT5AccountsList unit test (#16933) #6325
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@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 "binary-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 |