You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.8 KiB
63 lines
1.8 KiB
3 years ago
|
// 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
|
||
2 years ago
|
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';
|
||
2 years ago
|
|
||
3 years ago
|
const execFileNode = util.promisify(childProcess.execFile);
|
||
|
|
||
2 years ago
|
function execFile(command: string, args: string[]) {
|
||
3 years ago
|
return execFileNode(command, args, {
|
||
|
cwd: process.cwd(),
|
||
|
env: process.env,
|
||
|
encoding: 'utf-8',
|
||
|
});
|
||
|
}
|
||
|
|
||
|
const screenshotsBase = 'imageSnapshots';
|
||
2 years ago
|
const screenshotsChunks = `imageSnapshots-chunks`;
|
||
3 years ago
|
const BATCH_SIZE = 200;
|
||
|
|
||
2 years ago
|
async function cpToTemp(screenshot: string, target: string) {
|
||
3 years ago
|
await execFile('mkdir', ['-p', target]);
|
||
2 years ago
|
await execFile('cp', [screenshot, target]);
|
||
3 years ago
|
}
|
||
|
|
||
|
async function run() {
|
||
|
const screenshots = await glob(`${screenshotsBase}/**/*`);
|
||
2 years ago
|
const chunks = lodashChunk<string>(screenshots, BATCH_SIZE);
|
||
3 years ago
|
|
||
|
await Promise.all(
|
||
|
chunks.map((chunk, chunkIndex) =>
|
||
|
Promise.all(
|
||
2 years ago
|
chunk.map<Promise<void>>((screenshot) =>
|
||
|
cpToTemp(screenshot, `${screenshotsChunks}/${chunkIndex}`),
|
||
|
),
|
||
3 years ago
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
for (let i = 0; i < chunks.length; i += 1) {
|
||
|
// eslint-disable-next-line no-await-in-loop
|
||
2 years ago
|
const result = await argos.upload({
|
||
|
root: `${screenshotsChunks}/${i}`,
|
||
|
token: process.env.ARGOS_TOKEN,
|
||
|
parallel: {
|
||
|
total: chunks.length,
|
||
2 years ago
|
nonce: process.env.ARGOS_PARALLEL_NONCE || process.env.CIRCLE_BUILD_NUM || '',
|
||
2 years ago
|
},
|
||
|
});
|
||
3 years ago
|
// eslint-disable-next-line no-console -- pipe stdout
|
||
2 years ago
|
console.log(result);
|
||
3 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
run().catch((error) => {
|
||
3 years ago
|
// eslint-disable-next-line no-console
|
||
|
console.error(error);
|
||
|
process.exit(1);
|
||
|
});
|