Tools: Trying to fix CI

pull/5928/head
Laurent Cozic 2021-12-28 14:52:39 +01:00
parent c7d0d659a0
commit aaf5d74b94
1 changed files with 28 additions and 6 deletions

View File

@ -1,4 +1,4 @@
const { writeFile, copySync, mkdirpSync, removeSync } = require('fs-extra');
const { writeFile, copy, mkdirp, remove } = require('fs-extra');
const glob = require('glob');
const { resolve } = require('path');
const { dirname } = require('@joplin/tools/gulp/utils');
@ -11,6 +11,28 @@ function stripOffRootDir(path) {
return path;
}
const msleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
};
const withRetry = async (fn) => {
for (let i = 0; i < 5; i++) {
try {
await fn();
return;
} catch (error) {
console.warn(`withRetry: Failed calling function - will retry (${i})`, error);
await msleep(1000 + i * 1000);
}
}
throw new Error('withRetry: Could not run function after multiple attempts');
};
async function main() {
const langSourceDir = resolve(__dirname, '../../../Assets/TinyMCE/langs');
const buildLibDir = resolve(__dirname, '../vendor/lib');
@ -56,11 +78,11 @@ async function main() {
}
if (action === 'delete') {
removeSync(destDir);
await withRetry(() => remove(destDir));
} else {
console.info(`Copying ${stripOffRootDir(sourceDir)} => ${stripOffRootDir(destDir)}`);
mkdirpSync(destDir);
copySync(sourceDir, destDir, { overwrite: true });
await withRetry(() => mkdirp(destDir));
await withRetry(() => copy(sourceDir, destDir, { overwrite: true }));
}
}
}
@ -76,10 +98,10 @@ async function main() {
destFile = `${buildLibDir}/${file}`;
}
mkdirpSync(dirname(destFile));
await withRetry(() => mkdirp(dirname(destFile)));
console.info(`Copying ${stripOffRootDir(sourceFile)} => ${stripOffRootDir(destFile)}`);
copySync(sourceFile, destFile, { overwrite: true });
await withRetry(() => copy(sourceFile, destFile, { overwrite: true }));
}
const supportedLocales = glob.sync(`${langSourceDir}/*.js`).map(s => {