-
Notifications
You must be signed in to change notification settings - Fork 153
119 lines (105 loc) · 3.74 KB
/
i18n-sync.yml
File metadata and controls
119 lines (105 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: i18n-sync
on:
workflow_dispatch:
inputs:
reviewer:
description: "自动请求评审的 GitHub 用户名(可留空)"
required: false
schedule:
# 每天 UTC 03:00 自动运行(可按需调整) 测试
- cron: "0 3 * * *"
permissions:
contents: write
pull-requests: write
env:
I18N_SYNC_BRANCH: "chore/i18n-auto-sync"
PR_TITLE: "chore: auto sync OCR i18n expected"
DEFAULT_PR_REVIEWER: "EeeMaoY"
jobs:
sync-ocr-expected:
if: github.event_name == 'workflow_dispatch' || github.repository == '1bananachicken/MaaNTE'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.MAANTE_BOT_TOKEN }}
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Prepare fixed sync branch
env:
BASE_BRANCH: ${{ github.event.repository.default_branch }}
run: |
git checkout -B "$I18N_SYNC_BRANCH" "origin/$BASE_BRANCH"
- name: Clone translation repository
run: |
git clone --depth 1 https://github.com/Abino01/ExtractForNTE.git "$RUNNER_TEMP/ExtractForNTE"
- name: Show translation repository commit
run: |
git -C "$RUNNER_TEMP/ExtractForNTE" rev-parse HEAD
- name: Run OCR expected sync (write mode)
run: |
python tools/i18n/sync_ocr_expected.py --write --i18n-dir "$RUNNER_TEMP/ExtractForNTE"
- name: Check changes
id: changes
run: |
if git diff --quiet; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Commit and push changes
if: steps.changes.outputs.has_changes == 'true'
uses: actions-js/push@master
with:
force: true
branch: ${{ env.I18N_SYNC_BRANCH }}
message: "chore: auto sync OCR i18n expected [skip changelog]"
github_token: ${{ secrets.MAANTE_BOT_TOKEN }}
- name: Create PR when missing
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.MAANTE_BOT_TOKEN }}
BASE_BRANCH: ${{ github.event.repository.default_branch }}
PR_REVIEWER: ${{ github.event.inputs.reviewer || env.DEFAULT_PR_REVIEWER }}
run: |
pr_number="$(gh pr list --base "$BASE_BRANCH" --head "$I18N_SYNC_BRANCH" --state open --json number --jq '.[0].number')"
if [ -n "$pr_number" ]; then
echo "PR already exists: #$pr_number"
if [ -n "$PR_REVIEWER" ]; then
if ! output="$(gh pr edit "$pr_number" --add-reviewer "$PR_REVIEWER" 2>&1)"; then
if echo "$output" | grep -qi "already requested"; then
echo "Skip add reviewer (already requested)"
else
echo "$output" >&2
exit 1
fi
fi
fi
exit 0
fi
pr_body="$(cat <<'EOF'
## Summary
- Auto run i18n OCR expected sync.
- Update expected values based on latest ExtractForNTE translation repository.
## Trigger
- workflow_dispatch
- schedule (daily UTC)
EOF
)"
reviewer_args=()
if [ -n "$PR_REVIEWER" ]; then
reviewer_args=(--reviewer "$PR_REVIEWER")
fi
gh pr create \
--base "$BASE_BRANCH" \
--head "$I18N_SYNC_BRANCH" \
--title "$PR_TITLE" \
--body "$pr_body" \
"${reviewer_args[@]}"
- name: Show changed files
run: |
git status --short