Sync i18n files #561
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: Sync i18n files | |
| on: | |
| schedule: | |
| - cron: "0 12 * * *" | |
| push: | |
| branches: [main] | |
| paths: | |
| - "src/lang/en/**" | |
| workflow_dispatch: | |
| jobs: | |
| sync_i18n: | |
| name: Generate and i18n files | |
| runs-on: ubuntu-latest | |
| env: | |
| SYNC_PR_BRANCH: ${{ vars.SYNC_LANG_PR_BRANCH || 'chore/auto-update-i18n' }} | |
| SYNC_TARGET_BRANCH: ${{ github.event.repository.default_branch }} | |
| steps: | |
| - name: Checkout frontend codes | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Checkout backend codes | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: ${{ vars.SYNC_LANG_ENV_BACKEND_REPOSITORY || 'OpenListTeam/OpenList' }} | |
| ref: main | |
| path: backend | |
| fetch-depth: 0 | |
| submodules: recursive | |
| - name: Setup go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: "1.26.4" | |
| cache-dependency-path: backend/go.sum | |
| - name: Generate and update lang files | |
| run: | | |
| cd backend | |
| go run ./main.go lang --frontend-path ../ | |
| cd .. | |
| - name: Check for changes and stage | |
| id: verify-changed-files | |
| run: | | |
| cp -f ./backend/lang/*.json ./src/lang/en/ 2>/dev/null || : | |
| if git diff --quiet HEAD -- src/lang/en/; then | |
| echo "No changes detected in src/lang/en/" | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Changes detected in src/lang/en/" | |
| git add src/lang/en/ | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Import GPG key | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| uses: crazy-max/ghaction-import-gpg@v7 | |
| with: | |
| gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} | |
| passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} | |
| git_config_global: true | |
| git_user_signingkey: true | |
| git_commit_gpgsign: true | |
| git_tag_gpgsign: true | |
| - name: Setup CI Bot | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| run: | | |
| git config --global user.name "${{ secrets.BOT_USERNAME }}" | |
| git config --global user.email "${{ secrets.BOT_USEREMAIL }}" | |
| - name: Commit changes | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| run: | | |
| git checkout -b "$SYNC_PR_BRANCH" || git checkout "$SYNC_PR_BRANCH" | |
| if git diff --cached --quiet; then | |
| echo "No staged changes to commit. Skipping commit." | |
| exit 0 | |
| fi | |
| git commit -S -m "chore: auto update i18n file" | |
| - name: Push branch | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| run: | | |
| git push --force-with-lease origin "$SYNC_PR_BRANCH" | |
| - name: Create Pull Request | |
| if: steps.verify-changed-files.outputs.changed == 'true' | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }} | |
| run: | | |
| PR_TITLE="chore: auto update i18n file" | |
| PR_BODY="This PR was automatically generated by a workflow to update i18n files." | |
| PR_BRANCH="$SYNC_PR_BRANCH" | |
| TARGET_BRANCH="$SYNC_TARGET_BRANCH" | |
| # Check if a PR already exists | |
| EXISTING_PR=$(gh pr list --head "$PR_BRANCH" --base "$TARGET_BRANCH" --state open --json number --jq '.[0].number // empty') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR #$EXISTING_PR already exists. Updating it." | |
| gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY" | |
| else | |
| echo "Creating a new PR." | |
| gh pr create --head "$PR_BRANCH" --base "$TARGET_BRANCH" --title "$PR_TITLE" --body "$PR_BODY" | |
| fi | |
| - name: Sync to Crowdin | |
| if: ${{ steps.verify-changed-files.outputs.changed == 'true' || github.event_name == 'push' }} | |
| uses: ./.github/actions/sync_to_crowdin | |
| with: | |
| crowdin_project_id: ${{ secrets.CROWDIN_PROJECT_ID }} | |
| crowdin_personal_token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }} | |
| permissions: | |
| contents: write | |
| pull-requests: write |