1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Tools: Trying to make encodeAssets script more robust on CI

This commit is contained in:
Laurent Cozic
2022-10-14 11:05:21 +01:00
parent 1fe6910089
commit bec97d6a42
2 changed files with 47 additions and 18 deletions

View File

@ -21,6 +21,8 @@ const walk = function(dir) {
}; };
async function encodeFile(sourcePath, destPath) { async function encodeFile(sourcePath, destPath) {
for (let i = 0; i < 3; i++) {
try {
const buffer = await fs.readFile(sourcePath); const buffer = await fs.readFile(sourcePath);
const hash = md5(buffer.toString('base64')); const hash = md5(buffer.toString('base64'));
const js = `module.exports = \`${buffer.toString('base64')}\`;`; const js = `module.exports = \`${buffer.toString('base64')}\`;`;
@ -41,6 +43,25 @@ async function encodeFile(sourcePath, destPath) {
mime: mime, mime: mime,
hash: hash, hash: hash,
}; };
} catch (error) {
// Although it makes no sense, the above function sometimes fails on CI
// with error "DEST does not exist", which of course it doesn't
// since we are trying to create it. So here we retry when it happens.
//
// Full error:
//
// Encoding "/home/runner/work/joplin/joplin/packages/app-mobile/tools/../../renderer/assets/katex/fonts/KaTeX_Math-BoldItalic.woff2" => "/home/runner/work/joplin/joplin/packages/app-mobile/tools/../pluginAssets/katex/fonts/KaTeX_Math-BoldItalic.woff2.base64.js"
// 'encodeAssets' errored after 115 ms
// Error: ENOENT: no such file or directory, open '/home/runner/work/joplin/joplin/packages/app-mobile/tools/../pluginAssets/katex/fonts/KaTeX_Math-BoldItalic.woff2.base64.js'
console.warn(`Could not encode file (${i}). Will try again...`);
console.warn('Error was:', error);
await utils.msleep(1000 + 1000 * i);
continue;
}
}
throw new Error('Could not encode file after multiple attempts. See above for errors.');
} }
async function main() { async function main() {

View File

@ -211,4 +211,12 @@ utils.getFilename = (path) => {
return splitted.join('.'); return splitted.join('.');
}; };
utils.msleep = (ms) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, ms);
});
};
module.exports = utils; module.exports = utils;