Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 7 additions & 35 deletions .github/workflows/i18n_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ on:
branches: [main]
paths:
- "src/lang/en/**"
pull_request:
paths:
- ".github/workflows/i18n*.yml"
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
Expand Down Expand Up @@ -74,40 +74,13 @@ jobs:
git config --global user.name "${{ secrets.BOT_USERNAME }}"
git config --global user.email "${{ secrets.BOT_USEREMAIL }}"

- name: Commit changes
- name: Commit the 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.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_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"
# Skip pushing if triggered by a pull request
if [ "${{ github.event_name }}" != "pull_request" ]; then
git push
fi

- name: Sync to Crowdin
Expand All @@ -119,4 +92,3 @@ jobs:

permissions:
contents: write
pull-requests: write