|
| 1 | +name: Create translation Batch Pull Request |
| 2 | + |
| 3 | +# **What it does**: |
| 4 | +# - Creates one pull request per language after running a series of automated checks, |
| 5 | +# removing translations that are broken in any known way |
| 6 | +# **Why we have it**: |
| 7 | +# - To deploy translations |
| 8 | +# **Who does it impact**: It automates what would otherwise be manual work, |
| 9 | +# helping docs engineering focus on higher value work |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_dispatch: |
| 13 | + schedule: |
| 14 | + - cron: '33 18 * * *' # every day at 18:33 UTC at least until automerge is working |
| 15 | + |
| 16 | +jobs: |
| 17 | + create-translation-batch: |
| 18 | + name: Create translation batch |
| 19 | + runs-on: ubuntu-latest |
| 20 | + # A sync's average run time is ~3.2 hours. |
| 21 | + # This sets a maximum execution time of 300 minutes (5 hours) to prevent the workflow from running longer than necessary. |
| 22 | + timeout-minutes: 300 |
| 23 | + strategy: |
| 24 | + fail-fast: false |
| 25 | + max-parallel: 1 |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - language: pt-BR |
| 29 | + language_code: pt |
| 30 | + # - language: zh-CN |
| 31 | + # language_code: cn |
| 32 | + # - language: ja-JP |
| 33 | + # language_code: ja |
| 34 | + # - language: es-ES |
| 35 | + # language_code: es |
| 36 | + steps: |
| 37 | + - name: Set branch name |
| 38 | + id: set-branch |
| 39 | + run: | |
| 40 | + echo "::set-output name=BRANCH_NAME::translation-batch-${{ matrix.language }}-$(date +%Y-%m-%d__%H-%M)" |
| 41 | +
|
| 42 | + - run: git config --global user.name "docubot" |
| 43 | + - run: git config --global user.email "67483024+docubot@users.noreply.github.com" |
| 44 | + |
| 45 | + - name: Checkout |
| 46 | + uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 |
| 47 | + with: |
| 48 | + fetch-depth: 0 |
| 49 | + lfs: true |
| 50 | + |
| 51 | + - run: git checkout -b ${{ steps.set-branch.outputs.BRANCH_NAME }} |
| 52 | + |
| 53 | + - name: Remove unwanted git hooks |
| 54 | + run: rm .git/hooks/post-checkout |
| 55 | + |
| 56 | + - name: Install Crowdin CLI |
| 57 | + run: | |
| 58 | + wget https://artifacts.crowdin.com/repo/deb/crowdin3.deb -O /tmp/crowdin.deb |
| 59 | + sudo dpkg -i /tmp/crowdin.deb |
| 60 | +
|
| 61 | + - name: Upload files to crowdin |
| 62 | + run: crowdin upload sources --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml' |
| 63 | + env: |
| 64 | + # This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string |
| 65 | + # See "API v2" on https://crowdin.com/project/<your-project>/settings#api |
| 66 | + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} |
| 67 | + |
| 68 | + # A personal access token, not to be confused with Crowdin API v1 "API key" |
| 69 | + # See https://crowdin.com/settings#api-key to generate a token |
| 70 | + # This token was created by logging into Crowdin with the octoglot user |
| 71 | + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
| 72 | + |
| 73 | + - name: Remove all language translations |
| 74 | + run: | |
| 75 | + git rm -rf --quiet translations/${{ matrix.language }}/content |
| 76 | + git rm -rf --quiet translations/${{ matrix.language }}/data |
| 77 | +
|
| 78 | + - name: Download crowdin translations |
| 79 | + run: crowdin download --no-progress --no-colors --verbose --debug '--branch=main' '--config=crowdin.yml' --language=${{ matrix.language }} |
| 80 | + env: |
| 81 | + # This is a numeric id, not to be confused with Crowdin API v1 "project identifier" string |
| 82 | + # See "API v2" on https://crowdin.com/project/<your-project>/settings#api |
| 83 | + CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} |
| 84 | + |
| 85 | + # A personal access token, not to be confused with Crowdin API v1 "API key" |
| 86 | + # See https://crowdin.com/settings#api-key to generate a token |
| 87 | + # This token was created by logging into Crowdin with the octoglot user |
| 88 | + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
| 89 | + |
| 90 | + - name: Commit crowdin sync |
| 91 | + run: | |
| 92 | + git add . |
| 93 | + git commit -m "Add crowdin translations" || echo "Nothing to commit" |
| 94 | +
|
| 95 | + - name: 'Setup node' |
| 96 | + uses: actions/setup-node@270253e841af726300e85d718a5f606959b2903c |
| 97 | + with: |
| 98 | + node-version: '16' |
| 99 | + |
| 100 | + - run: npm ci |
| 101 | + |
| 102 | + - name: Reset files with broken liquid tags |
| 103 | + run: | |
| 104 | + node script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }} |
| 105 | + git add . && git commit -m "run script/i18n/reset-files-with-broken-liquid-tags.js --language=${{ matrix.language_code }}" || echo "Nothing to commit" |
| 106 | +
|
| 107 | + # step 5 in docs-engineering/crowdin.md using script from docs-internal#22709 |
| 108 | + - name: Reset known broken files |
| 109 | + run: | |
| 110 | + node script/i18n/reset-known-broken-translation-files.js |
| 111 | + git add . && git commit -m "run script/i18n/reset-known-broken-translation-files.js" || echo "Nothing to commit" |
| 112 | + env: |
| 113 | + GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }} |
| 114 | + |
| 115 | + # step 6 in docs-engineering/crowdin.md |
| 116 | + - name: Homogenize frontmatter |
| 117 | + run: | |
| 118 | + node script/i18n/homogenize-frontmatter.js |
| 119 | + git add . && git commit -m "Run script/i18n/homogenize-frontmatter.js" || echo "Nothing to commit" |
| 120 | +
|
| 121 | + # step 7 in docs-engineering/crowdin.md |
| 122 | + - name: Fix translation errors |
| 123 | + run: | |
| 124 | + node script/i18n/fix-translation-errors.js |
| 125 | + git add . && git commit -m "Run script/i18n/fix-translation-errors.js" || echo "Nothing to commit" |
| 126 | +
|
| 127 | + # step 8a in docs-engineering/crowdin.md |
| 128 | + - name: Check parsing |
| 129 | + run: | |
| 130 | + node script/i18n/lint-translation-files.js --check parsing |
| 131 | + git add . && git commit -m "Run script/i18n/lint-translation-files.js --check parsin" || echo "Nothing to commit" |
| 132 | +
|
| 133 | + # step 8b in docs-engineering/crowdin.md |
| 134 | + - name: Check rendering |
| 135 | + run: | |
| 136 | + node script/i18n/lint-translation-files.js --check rendering |
| 137 | + git add . && git commit -m "Run script/i18n/lint-translation-files.js --check rendering" || echo "Nothing to commit" |
| 138 | +
|
| 139 | + - name: Create Pull Request |
| 140 | + env: |
| 141 | + GITHUB_TOKEN: ${{ secrets.DOCUBOT_REPO_PAT }} |
| 142 | + # We'll try to create the pull request based on the changes we pushed up in the branch. |
| 143 | + # If there are actually no differences between the branch and `main`, we'll delete it. |
| 144 | + run: | |
| 145 | + git push origin ${{ steps.set-branch.outputs.BRANCH_NAME }} |
| 146 | + gh pr create -t "New translation batch for ${{ matrix.language }}" \ |
| 147 | + --base=main \ |
| 148 | + --head=${{ steps.set-branch.outputs.BRANCH_NAME }} \ |
| 149 | + -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 }} |
| 150 | +
|
| 151 | + # When the maximum execution time is reached for this job, Actions cancels the workflow run. |
| 152 | + # This emits a notification for the first responder to triage. |
| 153 | + - name: Send Slack notification if workflow is cancelled |
| 154 | + uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 |
| 155 | + if: cancelled() |
| 156 | + with: |
| 157 | + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} |
| 158 | + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} |
| 159 | + color: failure |
| 160 | + text: 'The new translation batch for ${{ matrix.language }} was cancelled.' |
| 161 | + |
| 162 | + # Emit a notification for the first responder to triage if the workflow failed. |
| 163 | + - name: Send Slack notification if workflow failed |
| 164 | + uses: someimportantcompany/github-actions-slack-message@f8d28715e7b8a4717047d23f48c39827cacad340 |
| 165 | + if: failure() |
| 166 | + with: |
| 167 | + channel: ${{ secrets.DOCS_ALERTS_SLACK_CHANNEL_ID }} |
| 168 | + bot-token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} |
| 169 | + color: failure |
| 170 | + text: 'The new translation batch for ${{ matrix.language }} failed.' |
0 commit comments