Skip to content

Commit aa22464

Browse files
authored
fix(i18n): create pr for i18n_sync (#537)
Signed-off-by: MadDogOwner <xiaoran@xrgzs.top>
1 parent 21893bd commit aa22464

1 file changed

Lines changed: 35 additions & 7 deletions

File tree

.github/workflows/i18n_sync.yml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ on:
77
branches: [main]
88
paths:
99
- "src/lang/en/**"
10-
pull_request:
11-
paths:
12-
- ".github/workflows/i18n*.yml"
1310
workflow_dispatch:
1411

1512
jobs:
1613
sync_i18n:
1714
name: Generate and i18n files
1815
runs-on: ubuntu-latest
16+
env:
17+
SYNC_PR_BRANCH: ${{ vars.SYNC_LANG_PR_BRANCH || 'chore/auto-update-i18n' }}
18+
SYNC_TARGET_BRANCH: ${{ github.event.repository.default_branch }}
1919
steps:
2020
- name: Checkout frontend codes
2121
uses: actions/checkout@v6
@@ -74,13 +74,40 @@ jobs:
7474
git config --global user.name "${{ secrets.BOT_USERNAME }}"
7575
git config --global user.email "${{ secrets.BOT_USEREMAIL }}"
7676
77-
- name: Commit the changes
77+
- name: Commit changes
7878
if: steps.verify-changed-files.outputs.changed == 'true'
7979
run: |
80+
git checkout -b "$SYNC_PR_BRANCH" || git checkout "$SYNC_PR_BRANCH"
81+
if git diff --cached --quiet; then
82+
echo "No staged changes to commit. Skipping commit."
83+
exit 0
84+
fi
8085
git commit -S -m "chore: auto update i18n file"
81-
# Skip pushing if triggered by a pull request
82-
if [ "${{ github.event_name }}" != "pull_request" ]; then
83-
git push
86+
87+
- name: Push branch
88+
if: steps.verify-changed-files.outputs.changed == 'true'
89+
run: |
90+
git push --force-with-lease origin "$SYNC_PR_BRANCH"
91+
92+
- name: Create Pull Request
93+
if: steps.verify-changed-files.outputs.changed == 'true'
94+
shell: bash
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+
run: |
99+
PR_TITLE="chore: auto update i18n file"
100+
PR_BODY="This PR was automatically generated by a workflow to update i18n files."
101+
PR_BRANCH="$SYNC_PR_BRANCH"
102+
TARGET_BRANCH="$SYNC_TARGET_BRANCH"
103+
# Check if a PR already exists
104+
EXISTING_PR=$(gh pr list --head "$PR_BRANCH" --base "$TARGET_BRANCH" --state open --json number --jq '.[0].number // empty')
105+
if [ -n "$EXISTING_PR" ]; then
106+
echo "PR #$EXISTING_PR already exists. Updating it."
107+
gh pr edit "$EXISTING_PR" --title "$PR_TITLE" --body "$PR_BODY"
108+
else
109+
echo "Creating a new PR."
110+
gh pr create --head "$PR_BRANCH" --base "$TARGET_BRANCH" --title "$PR_TITLE" --body "$PR_BODY"
84111
fi
85112
86113
- name: Sync to Crowdin
@@ -92,3 +119,4 @@ jobs:
92119

93120
permissions:
94121
contents: write
122+
pull-requests: write

0 commit comments

Comments
 (0)