Create translation Batch Pull Request #61
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: Create translation Batch Pull Request | |
# **What it does**: | |
# - Creates one pull request per language after running a series of automated checks, | |
# removing translations that are broken in any known way | |
# **Why we have it**: | |
# - To deploy translations | |
# **Who does it impact**: It automates what would otherwise be manual work, | |
# helping docs engineering focus on higher value work | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '33 18 * * *' # every day at 18:33 UTC at least until automerge is working | |
jobs: | |
create-translation-batch: | |
name: Create translation batch | |
runs-on: ubuntu-latest | |
# A sync's average run time is ~3.2 hours. | |
# This sets a maximum execution time of 300 minutes (5 hours) to prevent the workflow from running longer than necessary. | |
timeout-minutes: 300 | |
strategy: | |
fail-fast: false | |
max-parallel: 1 | |
matrix: | |
include: | |
- language: pt-BR | |
language_code: pt | |
# - language: zh-CN | |
# language_code: cn | |
# - language: ja-JP | |
# language_code: ja | |
# - language: es-ES | |
# language_code: es | |
steps: | |
- name: Set branch name | |
id: set-branch | |
run: | | |
echo "::set-output name=BRANCH_NAME::translation-batch-${{ matrix.language }}-$(date +%Y-%m-%d__%H-%M)" | |
- run: git config --global user.name "docubot" | |
- run: git config --global user.email "[email protected]" | |
- name: Checkout | |
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 | |
with: | |
fetch-depth: 0 | |
lfs: true | |
- run: git checkout -b ${{ steps.set-branch.outputs.BRANCH_NAME }} | |
- name: Remove unwanted git hooks | |
run: rm .git/hooks/post-checkout | |
- name: Install Crowdin CLI | |
run: | | |
wget https://artifacts.crowdin.com/repo/deb/crowdin3.deb -O /tmp/crowdin.deb | |
sudo dpkg -i /tmp/crowdin.deb | |
- name: Upload files to crowdin | |
run: crowdin upload sources --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml' | |
env: | |
# This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string | |
# See "API v2" on https://crowdin.com/project/<your-project>/settings#api | |
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | |
# A personal access token, not to be confused with Crowdin API v1 "API key" | |
# See https://crowdin.com/settings#api-key to generate a token | |
# This token was created by logging into Crowdin with the octoglot user | |
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} | |
- name: Remove all language translations | |
run: | | |
git rm -rf --quiet translations/${{ matrix.language }}/content | |
git rm -rf --quiet translations/${{ matrix.language }}/data | |
- name: Download crowdin translations | |
run: crowdin download --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml' --language=${{ matrix.language }} | |
env: | |
# This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string | |
# See "API v2" on https://crowdin.com/project/<your-project>/settings#api | |
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | |
# A personal access token, not to be confused with Crowdin API v1 "API key" | |
# See https://crowdin.com/settings#api-key to generate a token | |
# This token was created by logging into Crowdin with the octoglot user | |
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} | |
- name: Commit crowdin sync | |
run: | | |
git add . | |
git commit -m "Add crowdin translations" || echo "Nothing to commit" | |
- name: 'Setup node' | |
uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c | |
with: | |
node-version: '16' | |
- run: npm ci | |
- name: Reset files with broken liquid tags | |
run: | | |
node script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }} | |
git add . && git commit -m "run script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }}" || echo "Nothing to commit" | |
# step 5 in docs-engineering/crowdin.md using script from docs-internal#22709 | |
- name: Reset known broken files | |
run: | | |
node script/i18n/reset-known-broken-translation-files.js | |
git add . && git commit -m "run script/i18n/reset-known-broken-translation-files.js" || echo "Nothing to commit" | |
env: | |
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }} | |
# step 6 in docs-engineering/crowdin.md | |
- name: Homogenize frontmatter | |
run: | | |
node script/i18n/homogenize-frontmatter.js | |
git add . && git commit -m "Run script/i18n/homogenize-frontmatter.js" || echo "Nothing to commit" | |
# step 7 in docs-engineering/crowdin.md | |
- name: Fix translation errors | |
run: | | |
node script/i18n/fix-translation-errors.js | |
git add . && git commit -m "Run script/i18n/fix-translation-errors.js" || echo "Nothing to commit" | |
# step 8a in docs-engineering/crowdin.md | |
- name: Check parsing | |
run: | | |
node script/i18n/lint-translation-files.js --check parsing | |
git add . && git commit -m "Run script/i18n/lint-translation-files.js --check parsin" || echo "Nothing to commit" | |
# step 8b in docs-engineering/crowdin.md | |
- name: Check rendering | |
run: | | |
node script/i18n/lint-translation-files.js --check rendering | |
git add . && git commit -m "Run script/i18n/lint-translation-files.js --check rendering" || echo "Nothing to commit" | |
- name: Create Pull Request | |
env: | |
GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }} | |
# We'll try to create the pull request based on the changes we pushed up in the branch. | |
# If there are actually no differences between the branch and `main`, we'll delete it. | |
run: | | |
git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }} | |
gh pr create -t "New translation batch for ${{ matrix.language }}" \ | |
--base=main \ | |
--head=${{ steps.set-branch.outputs.BRANCH_NAME }} \ | |
-b "New batch for ${{ matrix.language }} created by [this workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)" || git push origin :${{ steps.set-branch.outputs.BRANCH_NAME }} | |
# When the maximum execution time is reached for this job, Actions cancels the workflow run. | |
# This emits a notification for the first responder to triage. | |
- name: Send Slack notification if workflow is cancelled | |
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 | |
if: cancelled() | |
with: | |
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} | |
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} | |
color: failure | |
text: 'The new translation batch for ${{ matrix.language }} was cancelled.' | |
# Emit a notification for the first responder to triage if the workflow failed. | |
- name: Send Slack notification if workflow failed | |
uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 | |
if: failure() | |
with: | |
channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} | |
bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} | |
color: failure | |
text: 'The new translation batch for ${{ matrix.language }} failed.' |