|
| 1 | +name: Crowdin (pull) |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: '0 7 * * MON' # every monday at 7 am |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: i18n-management |
| 10 | + |
| 11 | +jobs: |
| 12 | + pull_translations: |
| 13 | + name: 'Pull translations from Crowdin' |
| 14 | + runs-on: ubuntu-22.04 |
| 15 | + if: github.ref == 'refs/heads/main' |
| 16 | + concurrency: |
| 17 | + group: i18n-pull:${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + steps: |
| 20 | + - name: Preflight check |
| 21 | + run: | |
| 22 | + PREFLIGHT_CHECK_RESULT=true |
| 23 | +
|
| 24 | + function flight_failure () { |
| 25 | + if [ "$PREFLIGHT_CHECK_RESULT" = true ]; then |
| 26 | + echo "One or more pre-flight checks failed!" |
| 27 | + echo "" |
| 28 | + PREFLIGHT_CHECK_RESULT=false |
| 29 | + fi |
| 30 | + echo "- $1" |
| 31 | + } |
| 32 | +
|
| 33 | + if [ "$CROWDIN_PROJECT_ID_DEFINED" != true ]; then |
| 34 | + flight_failure "CROWDIN_PROJECT_ID variable is not defined (required to push)" |
| 35 | + fi |
| 36 | +
|
| 37 | + if [ "$CROWDIN_PERSONAL_TOKEN_DEFINED" != true ]; then |
| 38 | + flight_failure "CROWDIN_PERSONAL_TOKEN secret is not defined (required to push)" |
| 39 | + fi |
| 40 | +
|
| 41 | + if [ "$CROWDIN_GH_TOKEN_DEFINED" != true ]; then |
| 42 | + flight_failure "CROWDIN_GH_TOKEN secret is not defined (required to make pull requests)" |
| 43 | + fi |
| 44 | +
|
| 45 | + if [ "$PREFLIGHT_CHECK_RESULT" = false ]; then |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | + env: |
| 49 | + CROWDIN_PROJECT_ID_DEFINED: ${{ vars.CROWDIN_PROJECT_ID != '' }} |
| 50 | + CROWDIN_PERSONAL_TOKEN_DEFINED: ${{ secrets.CROWDIN_PERSONAL_TOKEN != '' }} |
| 51 | + CROWDIN_GH_TOKEN_DEFINED: ${{ secrets.CROWDIN_GH_TOKEN != '' }} |
| 52 | + |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + ref: ${{ github.ref }} |
| 57 | + token: ${{ secrets.CROWDIN_GH_TOKEN }} |
| 58 | + |
| 59 | + - name: Configure Git author |
| 60 | + id: git-author |
| 61 | + uses: MarcoIeni/git-config@v0.1 |
| 62 | + env: |
| 63 | + GITHUB_TOKEN: ${{ secrets.CROWDIN_GH_TOKEN }} |
| 64 | + |
| 65 | + # # Because --all flag of Crowdin CLI is currently broken we need to create a fake source file |
| 66 | + # # so that the CLI won't omit translations for it. See https://github.com/crowdin/crowdin-cli/issues/724 |
| 67 | + # - name: Write fake sources |
| 68 | + # shell: bash |
| 69 | + # run: echo "{}" > locales/en-US/index.json |
| 70 | + |
| 71 | + - name: Query branch name |
| 72 | + id: branch-name |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 76 | + SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | sed -e "s/[\\\\/\\:*?\"<>|]/_/g") |
| 77 | + echo "Branch name is $BRANCH_NAME (escaped as $SAFE_BRANCH_NAME)" |
| 78 | + echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 79 | + echo "safe_branch_name=$SAFE_BRANCH_NAME" >> "$GITHUB_OUTPUT" |
| 80 | +
|
| 81 | + - name: Download translations from Crowdin |
| 82 | + uses: crowdin/github-action@v2 |
| 83 | + with: |
| 84 | + upload_sources: false |
| 85 | + upload_translations: false |
| 86 | + download_translations: true |
| 87 | + push_translations: false |
| 88 | + create_pull_request: false |
| 89 | + crowdin_branch_name: '[${{ github.repository_owner }}.${{ github.event.repository.name }}] ${{ steps.branch-name.outputs.safe_branch_name }}' |
| 90 | + env: |
| 91 | + CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID }} |
| 92 | + CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} |
| 93 | + |
| 94 | + - name: Fix broken permissions |
| 95 | + shell: bash |
| 96 | + run: sudo chown -R $USER:$USER . |
| 97 | + |
| 98 | + - name: Create Pull Request |
| 99 | + uses: peter-evans/create-pull-request@v7 |
| 100 | + with: |
| 101 | + title: 'New translations from Crowdin (${{ steps.branch-name.outputs.branch_name }})' |
| 102 | + body-path: .github/templates/crowdin-pr.md |
| 103 | + commit-message: 'New translations from Crowdin (${{ steps.branch-name.outputs.branch_name }})' |
| 104 | + branch: crowdin-pull/${{ steps.branch-name.outputs.branch_name }} |
| 105 | + author: '${{ steps.git-author.outputs.name }} <${{ steps.git-author.outputs.email }}>' |
| 106 | + committer: '${{ steps.git-author.outputs.name }} <${{ steps.git-author.outputs.email }}>' |
| 107 | + labels: sync |
| 108 | + token: ${{ secrets.CROWDIN_GH_TOKEN }} |
0 commit comments