Skip to content

Commit 1565781

Browse files
committed
refactor: pass env vars, rm unused steps
1 parent 936954e commit 1565781

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

.github/workflows/crowdin-ai-import.yml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ on:
44
workflow_dispatch:
55
inputs:
66
file_limit:
7-
description: 'Number of files to process (default: 100, use 1-10 for testing)'
7+
description: "Number of files to process (default: 100, use 1-10 for testing)"
88
required: false
9-
default: '100'
9+
default: "100"
10+
type: string
11+
target_languages:
12+
description: "Comma-separated Crowdin language codes (default: es-EM)"
13+
required: false
14+
default: "es-EM"
15+
type: string
16+
base_branch:
17+
description: "Base branch to create PR against (default: dev)"
18+
required: false
19+
default: "dev"
1020
type: string
1121

1222
jobs:
@@ -23,35 +33,17 @@ jobs:
2333
uses: actions/setup-node@v6
2434
with:
2535
node-version: 20
26-
cache: 'pnpm'
36+
cache: "pnpm"
2737

2838
- name: Install dependencies
2939
run: pnpm install
3040

31-
- name: Set up git
32-
run: |
33-
git config --global user.email "actions@github.com"
34-
git config --global user.name "GitHub Action"
35-
36-
- name: Generate timestamp and readable date
37-
id: date
38-
run: |
39-
echo "TIMESTAMP=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
40-
echo "READABLE_DATE=$(date +'%B %-d, %Y at %H:%M UTC')" >> $GITHUB_ENV
41-
4241
- name: Run Crowdin AI translation import
4342
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/i18n/main.ts
4443
env:
4544
I18N_CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
4645
I18N_GITHUB_API_KEY: ${{ secrets.I18N_GITHUB_TOKEN }}
47-
48-
- name: Summary
49-
run: |
50-
echo "## 🎉 Translation Import Complete!" >> $GITHUB_STEP_SUMMARY
51-
echo "" >> $GITHUB_STEP_SUMMARY
52-
echo "The script has completed successfully and created a pull request with the translations." >> $GITHUB_STEP_SUMMARY
53-
echo "" >> $GITHUB_STEP_SUMMARY
54-
echo "**Details:**" >> $GITHUB_STEP_SUMMARY
55-
echo "- Triggered: ${{ env.READABLE_DATE }}" >> $GITHUB_STEP_SUMMARY
56-
echo "- File limit: ${{ github.event.inputs.file_limit }} files" >> $GITHUB_STEP_SUMMARY
57-
echo "- Check the script output above for PR link and translation details" >> $GITHUB_STEP_SUMMARY
46+
FILE_LIMIT: ${{ github.event.inputs.file_limit }}
47+
TARGET_LANGUAGES: ${{ github.event.inputs.target_languages }}
48+
BASE_BRANCH: ${{ github.event.inputs.base_branch }}
49+
GITHUB_REPOSITORY: ${{ github.repository }}

src/scripts/i18n/main.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,37 @@ if (!crowdinApiKey) {
4949
console.log("[DEBUG] Crowdin API key found ✓")
5050
const crowdinBearerHeaders = { Authorization: `Bearer ${crowdinApiKey}` }
5151

52+
// Parse environment variables with defaults
53+
const targetLanguages = process.env.TARGET_LANGUAGES
54+
? process.env.TARGET_LANGUAGES.split(",").map((lang) => lang.trim())
55+
: ["es-EM"]
56+
57+
const baseBranch = process.env.BASE_BRANCH || "dev"
58+
59+
const fileLimit = process.env.FILE_LIMIT
60+
? parseInt(process.env.FILE_LIMIT, 10)
61+
: 100
62+
63+
// Parse GitHub repository from env (format: "owner/repo")
64+
const githubRepo =
65+
process.env.GITHUB_REPOSITORY || "ethereum/ethereum-org-website"
66+
const [ghOrganization, ghRepo] = githubRepo.split("/")
67+
68+
console.log("[DEBUG] Configuration:")
69+
console.log(`[DEBUG] - Target languages: ${targetLanguages.join(", ")}`)
70+
console.log(`[DEBUG] - Base branch: ${baseBranch}`)
71+
console.log(`[DEBUG] - File limit: ${fileLimit}`)
72+
console.log(`[DEBUG] - GitHub repo: ${ghOrganization}/${ghRepo}`)
73+
5274
const env = {
5375
projectId: 834930,
54-
ghOrganization: "ethereum",
55-
ghRepo: "ethereum-org-website",
76+
ghOrganization,
77+
ghRepo,
5678
jsonRoot: "src/intl/en",
5779
mdRoot: "public/content",
5880
preTranslatePromptId: 168584,
59-
allCrowdinCodes: ["es-EM"], // i18nConfig.map((item) => item.crowdinCode),
60-
baseBranch: "i18n-flow-1", // "dev",
81+
allCrowdinCodes: targetLanguages,
82+
baseBranch,
6183
}
6284

6385
// --- Utilities: resilient fetch for GitHub calls ---
@@ -1067,8 +1089,8 @@ async function main(options?: { allLangs: boolean }) {
10671089
allCrowdinCodes: env.allCrowdinCodes,
10681090
})
10691091

1070-
// Increase scope of English files fetched (remove overly restrictive perPage=4)
1071-
const allEnglishFiles = await getAllEnglishFiles()
1092+
// Fetch English files with the configured file limit
1093+
const allEnglishFiles = await getAllEnglishFiles(fileLimit)
10721094
console.log(
10731095
`[DEBUG] Found ${allEnglishFiles.length} English files from GitHub`
10741096
)

0 commit comments

Comments
 (0)