-
Notifications
You must be signed in to change notification settings - Fork 48
213 lines (176 loc) Β· 7.67 KB
/
i18n-check.yml
File metadata and controls
213 lines (176 loc) Β· 7.67 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: 'I18n Check - Find Unused Translation Keys'
on:
workflow_dispatch:
pull_request:
branches: [ main, dev ]
paths:
- 'src/**/*.vue'
- 'src/**/*.ts'
- 'src/**/*.js'
- 'src/i18n/**/*.json'
- 'scripts/find-unused-i18n.js'
- '.github/workflows/i18n-check.yml'
push:
branches: [ main, dev ]
paths:
- 'src/i18n/**/*.json'
env:
NODE_OPTIONS: '--max-old-space-size=4096'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
i18n-check:
name: Check for Unused I18n Keys
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run i18n unused keys check
id: i18n-check
run: |
echo "Running i18n unused keys analysis..."
# Run the script and capture output
OUTPUT=$(node scripts/find-unused-i18n.js 2>&1)
EXIT_CODE=$?
# Save the output to a file for the job summary
echo "$OUTPUT" > i18n-check-output.txt
# Also output to console
echo "$OUTPUT"
# Check if there are unused keys by looking for the specific pattern in output
if echo "$OUTPUT" | grep -q "ποΈ Unused I18n Keys:"; then
echo "unused_keys_found=true" >> $GITHUB_OUTPUT
echo "β Found unused i18n keys!"
exit 1
else
echo "unused_keys_found=false" >> $GITHUB_OUTPUT
echo "β
No unused i18n keys found!"
exit 0
fi
- name: Generate Job Summary
if: always()
run: |
echo "## π I18n Keys Analysis Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f i18n-check-output.txt ]; then
echo "### π Analysis Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat i18n-check-output.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ steps.i18n-check.outputs.unused_keys_found }}" = "true" ]; then
echo "### β Action Required" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Unused i18n keys were found. Consider:" >> $GITHUB_STEP_SUMMARY
echo "- Removing unused keys from locale files" >> $GITHUB_STEP_SUMMARY
echo "- Verifying that the keys are actually unused" >> $GITHUB_STEP_SUMMARY
echo "- Adding usage for keys that should be kept" >> $GITHUB_STEP_SUMMARY
else
echo "### β
All Clear" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "No unused i18n keys found. Great job maintaining clean translations! π" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### π‘ Tips" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- Run \`yarn i18n:check\` locally to check for unused keys" >> $GITHUB_STEP_SUMMARY
echo "- Run \`yarn i18n:check:verbose\` for detailed usage information" >> $GITHUB_STEP_SUMMARY
echo "- This check runs automatically on PRs that modify Vue, TS, JS, or i18n files" >> $GITHUB_STEP_SUMMARY
- name: Upload analysis results
if: always()
uses: actions/upload-artifact@v4
with:
name: i18n-analysis-results
path: i18n-check-output.txt
retention-days: 7
- name: Comment on PR (if unused keys found)
if: github.event_name == 'pull_request' && steps.i18n-check.outputs.unused_keys_found == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let output = '';
try {
output = fs.readFileSync('i18n-check-output.txt', 'utf8');
} catch (error) {
output = 'Unable to read analysis output';
}
const body = `## π I18n Analysis Report
β **Unused i18n keys were found in this PR**
<details>
<summary>π Click to view detailed analysis</summary>
\`\`\`
${output}
\`\`\`
</details>
### π§ Action Required
Please review the unused keys listed above and consider:
- **Removing** keys that are truly unused
- **Verifying** that the detection is correct (some dynamic key usage might not be detected)
- **Adding usage** for keys that should be kept
### π‘ Local Testing
You can run this analysis locally using:
\`\`\`bash
yarn i18n:check # Basic check
yarn i18n:check:verbose # Detailed output with usage examples
\`\`\`
---
*This comment was automatically generated by the I18n Check workflow.*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
locale-consistency-check:
name: Check Locale File Consistency
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Check locale files consistency
run: |
echo "Checking if all locale files have the same structure..."
# Run the i18n script in verbose mode to also check for inconsistencies
node scripts/find-unused-i18n.js --verbose > locale-check.txt 2>&1
# Check if there are inconsistencies reported
if grep -q "β οΈ Locale Inconsistencies:" locale-check.txt; then
echo "β Found locale inconsistencies!"
cat locale-check.txt
exit 1
else
echo "β
All locale files are consistent!"
fi
- name: Generate Consistency Report
if: always()
run: |
echo "## π Locale Consistency Check" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if grep -q "β οΈ Locale Inconsistencies:" locale-check.txt 2>/dev/null; then
echo "### β Inconsistencies Found" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Some keys exist in one locale but not others:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
cat locale-check.txt >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
else
echo "### β
All Locale Files Consistent" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "All locale files have matching key structures. Perfect! π" >> $GITHUB_STEP_SUMMARY
fi