2022-04-22 22:31:39 +08:00
|
|
|
// Thanks to material-ui ❤️
|
|
|
|
// Create chunks for Argos: https://github.com/mui/material-ui/pull/23518
|
|
|
|
// https://github.com/mui/material-ui/blob/af81aae3b292ed180e7652a665fad1be2b38a7b3/scripts/pushArgos.js
|
2023-04-28 21:01:45 +08:00
|
|
|
import argos from '@argos-ci/core';
|
|
|
|
import childProcess from 'child_process';
|
|
|
|
import glob from 'fast-glob';
|
|
|
|
import lodashChunk from 'lodash/chunk';
|
|
|
|
import util from 'util';
|
2022-09-09 18:21:50 +08:00
|
|
|
|
2022-04-22 22:31:39 +08:00
|
|
|
const execFileNode = util.promisify(childProcess.execFile);
|
|
|
|
|
2023-04-28 21:01:45 +08:00
|
|
|
function execFile(command: string, args: string[]) {
|
2022-04-22 22:31:39 +08:00
|
|
|
return execFileNode(command, args, {
|
|
|
|
cwd: process.cwd(),
|
|
|
|
env: process.env,
|
|
|
|
encoding: 'utf-8',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const screenshotsBase = 'imageSnapshots';
|
2022-09-09 18:21:50 +08:00
|
|
|
const screenshotsChunks = `imageSnapshots-chunks`;
|
2023-07-21 14:53:35 +08:00
|
|
|
const BATCH_SIZE = 128;
|
2022-04-22 22:31:39 +08:00
|
|
|
|
2023-04-28 21:01:45 +08:00
|
|
|
async function cpToTemp(screenshot: string, target: string) {
|
2022-04-22 22:31:39 +08:00
|
|
|
await execFile('mkdir', ['-p', target]);
|
2022-09-09 18:21:50 +08:00
|
|
|
await execFile('cp', [screenshot, target]);
|
2022-04-22 22:31:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function run() {
|
|
|
|
const screenshots = await glob(`${screenshotsBase}/**/*`);
|
2023-04-28 21:01:45 +08:00
|
|
|
const chunks = lodashChunk<string>(screenshots, BATCH_SIZE);
|
2022-04-22 22:31:39 +08:00
|
|
|
|
|
|
|
await Promise.all(
|
|
|
|
chunks.map((chunk, chunkIndex) =>
|
|
|
|
Promise.all(
|
2023-04-28 21:01:45 +08:00
|
|
|
chunk.map<Promise<void>>((screenshot) =>
|
|
|
|
cpToTemp(screenshot, `${screenshotsChunks}/${chunkIndex}`),
|
|
|
|
),
|
2022-04-22 22:31:39 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-07-21 14:53:35 +08:00
|
|
|
// eslint-disable-next-line no-console -- pipe stdout
|
|
|
|
console.log('Chunk Size:', chunks.length, '/', 'Total Snapshots:', screenshots.length);
|
|
|
|
|
2022-04-22 22:31:39 +08:00
|
|
|
for (let i = 0; i < chunks.length; i += 1) {
|
|
|
|
// eslint-disable-next-line no-await-in-loop
|
2022-09-09 18:21:50 +08:00
|
|
|
const result = await argos.upload({
|
|
|
|
root: `${screenshotsChunks}/${i}`,
|
|
|
|
token: process.env.ARGOS_TOKEN,
|
|
|
|
parallel: {
|
|
|
|
total: chunks.length,
|
2023-04-28 21:01:45 +08:00
|
|
|
nonce: process.env.ARGOS_PARALLEL_NONCE || process.env.CIRCLE_BUILD_NUM || '',
|
2022-09-09 18:21:50 +08:00
|
|
|
},
|
|
|
|
});
|
2022-04-22 22:31:39 +08:00
|
|
|
// eslint-disable-next-line no-console -- pipe stdout
|
2023-07-21 14:53:35 +08:00
|
|
|
console.log(i, '>', result);
|
2022-04-22 22:31:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
run().catch((error) => {
|
2022-04-22 22:31:39 +08:00
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(error);
|
|
|
|
process.exit(1);
|
|
|
|
});
|