Upgrade image only used for publishing (#7371) #2
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: Sync Crowdin translations | |
permissions: | |
actions: write | |
checks: write | |
contents: write | |
deployments: write | |
pull-requests: write | |
statuses: write | |
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: '14' | |
- 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/[email protected] | |
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 |