-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crowdin CI v2 #12922
Crowdin CI v2 #12922
Changes from 11 commits
69d6a46
c3c591f
351a26d
e99cf23
4851902
c8235b9
3c2a5a3
6d618e4
546ce9b
12c7ae9
ea9c85d
fd1b979
58d5cbc
b7681d4
e3fd2cc
fc49c79
f01b0aa
6e9d020
bfb0755
0a50d17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
name: Import Crowdin translations | ||
name: Crowdin CI | ||
|
||
on: | ||
schedule: | ||
- cron: "20 16 1 * *" # Runs at 4:20 PM on the first day of every month | ||
workflow_dispatch: | ||
- cron: "20 4 1 * *" # Runs at 4:20 AM on the first day of every month | ||
workflow_dispatch: # Can be dispatched manually | ||
|
||
jobs: | ||
create_pr: | ||
create_approved_language_bucket_prs: | ||
runs-on: ubuntu-latest | ||
env: | ||
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }} | ||
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved these up to avoid repeating them during each needed step |
||
steps: | ||
# Set up environment | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
|
@@ -31,17 +37,42 @@ jobs: | |
- name: Fetch latest dev | ||
run: git fetch origin dev | ||
|
||
- name: Get translations | ||
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/getTranslations.ts | ||
env: | ||
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }} | ||
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }} | ||
|
||
- name: Authenticate GitHub CLI | ||
run: | | ||
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token | ||
|
||
# Build translations | ||
- name: Build Crowdin project | ||
id: build-crowdin | ||
run: | | ||
OUTPUT=$(npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/triggerBuild.ts) | ||
echo "$OUTPUT" | ||
shell: bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This syntax echo's the In |
||
|
||
- name: Await latest build to finish | ||
env: | ||
BUILD_ID: ${{ steps.build-crowdin.outputs.buildId}} | ||
run: | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assigns the |
||
OUTPUT=$(npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/awaitLatestBuild.ts) | ||
echo "$OUTPUT" | ||
shell: bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar syntax to above, but this time we're outputting |
||
|
||
- name: Check build success | ||
run: | | ||
if [ "${{ steps.build-crowdin.outputs.buildSuccess }}" = "false" ]; then | ||
echo "Build timed out, exiting" | ||
exit 1 | ||
fi | ||
shell: bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the |
||
|
||
# Prepare bucket ids | ||
- name: Get latest translation bucket directory ids | ||
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/getBucketDirectoryIds.ts | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Run the script to get the up-to-date bucket directory id's |
||
# Import approved translations | ||
- name: Get translations | ||
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/getTranslations.ts | ||
|
||
# Post updates as language-specific PRs | ||
- name: Process commits and post PRs by language | ||
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/translations/postLangPRs.ts | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import crowdin from "../api-client/crowdinClient" | ||
|
||
const FINISHED = "finished" | ||
const TIMEOUT = 2 * 60 * 60 * 1000 // Timeout after 2 hours | ||
const INTERVAL = 10 * 1000 // 10 seconds between checks | ||
|
||
async function awaitLatestBuild() { | ||
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359 | ||
|
||
// BUILD_ID is provided by the triggerBuild script run in the same workflow prior to this script | ||
const buildId = process.env.BUILD_ID | ||
|
||
console.log("Build ID provided:", buildId) | ||
const initialResponse = await crowdin.translationsApi.checkBuildStatus( | ||
projectId, | ||
Number(buildId) | ||
) | ||
let data = initialResponse.data | ||
|
||
let isFinished = data.status === FINISHED | ||
|
||
const timeoutTime = Date.now() + TIMEOUT | ||
let tryAgainTime = Date.now() - 1 | ||
while (!isFinished && Date.now() < timeoutTime) { | ||
if (Date.now() < tryAgainTime) continue | ||
tryAgainTime = Date.now() + INTERVAL | ||
|
||
const repeatCheck = await crowdin.translationsApi.checkBuildStatus( | ||
projectId, | ||
Number(buildId) | ||
) | ||
data = repeatCheck.data | ||
isFinished = data.status === FINISHED | ||
console.log( | ||
`id: ${buildId}, status: ${data.status}, progress ${data.progress}` | ||
) | ||
} | ||
|
||
if (data.status !== FINISHED) { | ||
console.error(`::set-output name=buildSuccess::false`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If fetch has timed out and still not finished, export |
||
throw new Error( | ||
`Timeout: Build did not finish in ${TIMEOUT / 1000 / 60} minutes` | ||
) | ||
} | ||
|
||
console.log("Latest build data:", data) | ||
console.error(`::set-output name=buildSuccess::true`) | ||
} | ||
|
||
awaitLatestBuild() | ||
|
||
export default awaitLatestBuild |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created this since |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import getAndSaveDirectories from "../source-files/fetchAndSaveDirectories" | ||
|
||
async function main() { | ||
await getAndSaveDirectories() | ||
} | ||
|
||
main() | ||
|
||
export default main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import crowdin from "../api-client/crowdinClient" | ||
|
||
import "dotenv/config" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out this isn't needed when running from an action |
||
async function triggerBuild() { | ||
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359 | ||
|
||
try { | ||
await crowdin.translationsApi.buildProject(projectId, { | ||
exportApprovedOnly: true, | ||
}) | ||
const response = await crowdin.translationsApi.buildProject(projectId) | ||
const { id, status } = response.data | ||
const isAlreadyFinished = status === "finished" | ||
console.log( | ||
`Build ${isAlreadyFinished ? "already finished" : "triggered"} id:`, | ||
id | ||
) | ||
console.log(`::set-output name=buildId::${id}`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output |
||
} catch (error: unknown) { | ||
console.error((error as Error).message) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ yarn markdown-checker | |
|
||
${qaResults} | ||
</details> | ||
|
||
@coderabbitai review | ||
` | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed as a dedicated workflow.