Skip to content

Crowdin Download

Crowdin Download #105

# This action automates the synchronization of our crowdin translations, so that a human does not need to kick it off from the crowdin UI
# It also formats incoming content because it is often not adherent to our rules post-translation.
# See translations-upload.yml for automation to upload our source content
# See translations-pr-lint.yml for quality control we conduct on ingress of new translations.
name: Crowdin Download
on:
workflow_dispatch: # Allow running when we want to, for events such as urgent translation mistakes or 100% completed languages
schedule:
- cron: '0 5 * * 5' # At 05:00 on Fridays. This guarantees that we have the 72 hour weekend time to review translations.
# Cancel any runs on the same branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
BRANCH_NAME: chore/crowdin
jobs:
synchronize-with-crowdin:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
with:
egress-policy: audit
- name: Checkout
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
token: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
# see all the options at https://github.com/crowdin/github-action
- name: Crowdin PR
uses: crowdin/github-action@08713f00a50548bfe39b37e8f44afb53e7a802d4 # v2.12.0
with:
# do not upload anything - this is a one-way operation download
upload_sources: false
upload_translations: false
# the rest of this controls how the PR comes in with new translations
download_translations: true
localization_branch_name: ${{ env.BRANCH_NAME }}
create_pull_request: true
pull_request_title: '[automated]: crowdin sync'
pull_request_body: 'New Crowdin translations from the [Node.js Crowdin project](https://crowdin.com/project/nodejs-web)'
commit_message: 'chore: synced translations from crowdin'
env:
GITHUB_TOKEN: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
# A numeric ID, found at https://crowdin.com/project/nodejs-web/tools/api
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
# Created from https://crowdin.com/settings#api-key logged in using nodejs-crowdin-bot
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
format_crowdin_pull_request:
needs: synchronize-with-crowdin
runs-on: ubuntu-latest
permissions:
# This permission is required by `stefanzweifel/git-auto-commit-action`
contents: write
steps:
- uses: nodejs/web-team/actions/setup-environment@2c2897a93eb99b4cdca270729100bc0887c758d9
with:
pnpm: true
use-version-file: true
ref: ${{ env.BRANCH_NAME }}
token: ${{ secrets.CROWDIN_GITHUB_BOT_TOKEN }}
fetch-depth: 2
- name: Restore Lint Cache
uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
apps/site/.eslintmdcache
apps/site/.prettiercache
# We want to restore Turborepo Cache and ESlint and Prettier Cache
# The ESLint and Prettier cache's are useful to reduce the overall runtime of ESLint and Prettier
# as they will only run on files that have changed since the last cached run
# this might of course lead to certain files not being checked against the linter, but the chances
# of such situation from happening are very slim as the checksums of both files would need to match
key: cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('apps/site/.eslintmdcache') }}
restore-keys: |
cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-
cache-lint-
- name: Patch version if the files changed
working-directory: packages/i18n
run: |
CHANGED_FILES=$(git diff --name-only HEAD^1 HEAD)
if [ -n "$CHANGED_FILES" ]; then
pnpm version patch --no-git-tag-version
fi
- name: Run ESLint
working-directory: apps/site
run: node --run lint:md -- --fix
- name: Run Prettier
run: node --run prettier:fix
- name: Push Changes back to Pull Request
uses: stefanzweifel/git-auto-commit-action@28e16e81777b558cc906c8750092100bbb34c5e3 # v7.0.0
with:
commit_options: '--no-verify --signoff'
commit_message: 'chore: automated format of translated files'
branch: ${{ env.BRANCH_NAME }}
- name: Save Lint Cache
uses: actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: |
apps/site/.eslintmdcache
apps/site/.prettiercache
key: cache-lint-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('apps/site/.eslintmdcache') }}