pocketmine_mp_crowdin_download #35
This file contains hidden or 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: PocketMine-MP Crowdin download | |
| on: | |
| workflow_dispatch: | |
| repository_dispatch: | |
| types: pocketmine_mp_crowdin_download | |
| jobs: | |
| download: | |
| name: Download translations | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| branch: | |
| - stable | |
| - minor-next | |
| - major-next | |
| fail-fast: false | |
| steps: | |
| - name: Generate access token | |
| id: token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ vars.RESTRICTED_ACTIONS_APP_ID }} | |
| private-key: ${{ secrets.RESTRICTED_ACTIONS_APP_KEY }} | |
| owner: ${{ github.repository_owner }} | |
| repositories: PocketMine-MP | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.repository_owner }}/PocketMine-MP # to allow testing on forks without editing the workflow | |
| fetch-depth: 0 | |
| token: ${{ steps.token.outputs.token }} | |
| ref: ${{ matrix.branch }} | |
| - name: Download translations | |
| uses: crowdin/github-action@v2 | |
| with: | |
| upload_sources: false | |
| upload_translations: false | |
| download_translations: true | |
| create_pull_request: false | |
| push_translations: false | |
| export_only_approved: true #irrespective of project config, only accept approved translations here | |
| crowdin_branch_name: ${{ matrix.branch }} | |
| env: | |
| CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | |
| CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} | |
| - name: Post-process placeholders back into PocketMine format | |
| working-directory: resources/translations | |
| run: | | |
| sed -i -r 's/\{([A-Za-z0-9]+)\}/\{%\1\}/g' *.ini | |
| git diff | |
| git status | |
| - name: Delete translation files with no useful translations | |
| working-directory: resources/translations | |
| run: | | |
| for file in *.ini; do | |
| if grep -q -P '^(?!language\.name[ ]*=)[A-Za-z0-9_\-\.]+[ ]*=' $file; then | |
| echo "Not empty: $file" | |
| else | |
| echo "Deleting empty file: $file" | |
| rm "$file" | |
| fi | |
| done | |
| - name: Get GitHub App User ID | |
| id: get-user-id | |
| run: echo "user-id=$(gh api "/users/${{ steps.token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ steps.token.outputs.token }} | |
| - name: Create Pull Request | |
| uses: peter-evans/create-pull-request@v7 | |
| with: | |
| add-paths: 'resources/translations/*.ini' | |
| commit-message: 'New translations from Crowdin (${{ matrix.branch }})' | |
| branch: crowdin-auto-fetch/${{ matrix.branch }} | |
| title: 'New translations from Crowdin (${{ matrix.branch }})' | |
| body: 'Pull request created by: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
| base: ${{ matrix.branch }} | |
| token: ${{ steps.token.outputs.token }} | |
| author: '${{ steps.token.outputs.app-slug }}[bot] <${{ steps.get-user-id.outputs.user-id }}+${{ steps.token.outputs.app-slug }}[bot]@users.noreply.github.com>' |