-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(v2): Fix Crowdin 409 issues in CI (#4739)
- Loading branch information
Showing
3 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const {Translations} = require('@crowdin/crowdin-api-client'); | ||
|
||
/* | ||
Crowdin does not support concurrent "project builds" (downloads of translations). | ||
The Crowdin CLI fails with error 409, and it leads to failures on Netlify. | ||
On Docusaurus, when we commit on master, we have 2 Netlify deployments triggered: | ||
- prod | ||
- i18n-staging (work-in-progress locales) | ||
This script helps the 2 deployments to not download translations concurrently from Crowdin. | ||
*/ | ||
|
||
const pollInterval = 5000; | ||
const timeout = 5 * 60 * 1000; | ||
|
||
const projectId = 428890; | ||
const token = process.env.CROWDIN_PERSONAL_TOKEN; // set on Netlify | ||
|
||
const translations = new Translations({ | ||
token, | ||
}); | ||
|
||
async function delay(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function hasBuildInProgress() { | ||
const projectBuilds = await translations.listProjectBuilds(projectId); | ||
return projectBuilds.data.some( | ||
(build) => build.data.status === 'in-progress', | ||
); | ||
} | ||
|
||
async function run() { | ||
const timeBefore = Date.now(); | ||
while (true) { | ||
if (Date.now() - timeBefore > timeout) { | ||
console.warn( | ||
'[Crowdin] Timeout of wait script reached => will try to proceed but download translations is likely to fail...', | ||
); | ||
break; | ||
} | ||
|
||
const inProgress = await hasBuildInProgress(); | ||
if (inProgress) { | ||
console.log('[Crowdin] A build is still in progress => waiting...'); | ||
await delay(pollInterval); | ||
} else { | ||
console.warn('[Crowdin] No build in progress => lets continue'); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
run().then( | ||
() => { | ||
process.exit(0); | ||
}, | ||
(e) => { | ||
console.error(e.message); | ||
console.error(e.stack); | ||
process.exit(1); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters