1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-01 21:24:45 +02:00

Tools: Apply "withRetry" technique to copyPluginAssets too to try to fix CI

This commit is contained in:
Laurent Cozic 2022-01-02 18:36:58 +01:00
parent 7cba4be498
commit c74e51a58e

@ -1,5 +1,29 @@
const { copy, mkdirp, remove } = require('fs-extra');
const msleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
};
// Same as copyApplicationAssets - probably both scripts should be merged in
// one.
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 rootDir = `${__dirname}/..`;
@ -12,11 +36,11 @@ async function main() {
for (const action of ['delete', 'copy']) {
for (const destDir of destDirs) {
if (action === 'delete') {
await remove(destDir);
await withRetry(() => remove(destDir));
} else {
console.info(`Copying to ${destDir}`);
await mkdirp(destDir);
await copy(sourceDir, destDir, { overwrite: true });
await withRetry(() => mkdirp(destDir));
await withRetry(() => copy(sourceDir, destDir, { overwrite: true }));
}
}
}