|
7 | 7 | branches: [main] |
8 | 8 | paths: |
9 | 9 | - "src/lang/en/**" |
10 | | - pull_request: |
11 | | - paths: |
12 | | - - ".github/workflows/i18n*.yml" |
13 | 10 | workflow_dispatch: |
14 | 11 |
|
15 | 12 | jobs: |
16 | 13 | sync_i18n: |
17 | 14 | name: Generate and i18n files |
18 | 15 | 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 }} |
19 | 19 | steps: |
20 | 20 | - name: Checkout frontend codes |
21 | 21 | uses: actions/checkout@v6 |
@@ -74,13 +74,40 @@ jobs: |
74 | 74 | git config --global user.name "${{ secrets.BOT_USERNAME }}" |
75 | 75 | git config --global user.email "${{ secrets.BOT_USEREMAIL }}" |
76 | 76 |
|
77 | | - - name: Commit the changes |
| 77 | + - name: Commit changes |
78 | 78 | if: steps.verify-changed-files.outputs.changed == 'true' |
79 | 79 | 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 |
80 | 85 | 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" |
84 | 111 | fi |
85 | 112 |
|
86 | 113 | - name: Sync to Crowdin |
|
92 | 119 |
|
93 | 120 | permissions: |
94 | 121 | contents: write |
| 122 | + pull-requests: write |
0 commit comments