-
Notifications
You must be signed in to change notification settings - Fork 186
99 lines (87 loc) · 3.43 KB
/
Copy pathi18n-sync-check.yml
File metadata and controls
99 lines (87 loc) · 3.43 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
name: i18n Translation Sync Check
on:
pull_request:
branches:
- main
paths:
- '**/*.mdx'
- 'docs.json'
jobs:
check-i18n-translations:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run i18n sync check
id: check
continue-on-error: true
env:
CHECK_I18N_OUTPUT: /tmp/i18n-check.json
run: node .github/scripts/i18n/check-i18n-sync.mjs \
"${{ github.event.pull_request.base.sha }}" \
"${{ github.event.pull_request.head.sha }}"
- name: Notify translator on PR
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHECK_I18N_OUTPUT: /tmp/i18n-check.json
run: |
if [ ! -f "$CHECK_I18N_OUTPUT" ]; then
echo "No check output; skipping comment."
exit 0
fi
MISSING=$(node -e "
const data = require('$CHECK_I18N_OUTPUT');
if (data.skipped) process.exit(2);
const n = Object.values(data.missingByLang || {}).reduce((s, v) => s + v.files.length, 0);
if (n === 0) process.exit(2);
process.stdout.write(String(n));
" 2>/dev/null) || true
if [ -z "$MISSING" ]; then
echo "No missing translations; skipping PR comment."
exit 0
fi
BODY_FILE=/tmp/i18n-comment.md
BODY_FILE="$BODY_FILE" node -e "
const data = require(process.env.CHECK_I18N_OUTPUT);
const lines = [
'## 🌐 i18n translation sync reminder',
'',
'@comfyui-wiki English documentation was updated in this PR. Please complete or schedule translation updates for the following files:',
'',
];
for (const [code, { name, files }] of Object.entries(data.missingByLang)) {
lines.push('### ' + name + ' (\`' + code + '\`)');
for (const f of files) lines.push('- \`' + f + '\`');
lines.push('');
}
lines.push('---');
lines.push('');
lines.push('**Local sync:** \`npm run translate\` (see [README — Automated translation](https://github.com/${{ github.repository }}/blob/main/README.md#automated-translation))');
lines.push('');
lines.push('<!-- i18n-sync-check -->');
require('fs').writeFileSync(process.env.BODY_FILE, lines.join('\n'));
"
PR_NUMBER="${{ github.event.pull_request.number }}"
REPO="${{ github.repository }}"
MARKER="<!-- i18n-sync-check -->"
EXISTING_ID=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
--jq '.[] | select(.body | contains("'"$MARKER"'")) | .id' | head -1)
if [ -n "$EXISTING_ID" ]; then
gh api -X PATCH "repos/${REPO}/issues/comments/${EXISTING_ID}" \
-f body="$(cat "$BODY_FILE")"
echo "Updated existing i18n reminder comment."
else
gh pr comment "$PR_NUMBER" --body-file "$BODY_FILE"
echo "Posted new i18n reminder comment."
fi
- name: Fail on redirect errors
if: steps.check.outcome == 'failure'
run: |
echo "i18n sync check failed — missing docs.json redirects for moved files."
exit 1