Skip to content

Commit 28f03fa

Browse files
authored
[code-infra] Make Argos upload script reusable (#45883)
1 parent 228df9c commit 28f03fa

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

apps/pigment-css-vite-app/src/pages/fixtures/index.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as playwright from 'playwright';
44

55
async function main() {
66
const baseUrl = 'http://localhost:5001/fixtures';
7-
const screenshotDir = path.resolve('screenshots/chrome');
7+
const screenshotDir = path.resolve('test/regressions/screenshots/chrome');
88
const browser = await playwright.chromium.launch({
99
args: ['--font-render-hinting=none'],
1010
// otherwise the loaded google Roboto font isn't applied
@@ -86,9 +86,6 @@ async function main() {
8686
});
8787
}
8888

89-
// prepare screenshots
90-
await fse.emptyDir(screenshotDir);
91-
9289
describe('visual regressions', () => {
9390
beforeEach(async () => {
9491
await page.evaluate(() => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"test:regressions-pigment-css:run": "nx run nx_test_regressions_pigment_css_run",
8080
"test:regressions-pigment-css:server": "pnpm --filter @app/pigment-css-vite-app run preview --port 5001",
8181
"test:unit": "nx run nx_test_unit",
82-
"test:argos": "node ./scripts/pushArgos.mjs",
82+
"test:argos": "node ./scripts/pushArgos.mjs test/regressions/screenshots/chrome",
8383
"typescript": "lerna run --no-bail typescript",
8484
"typescript:ci": "lerna run --concurrency 3 --no-bail typescript",
8585
"use-react-version": "node ./scripts/useReactVersion.mjs",

scripts/pushArgos.mjs

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,65 @@ import fse from 'fs-extra';
44
import lodashChunk from 'lodash/chunk.js';
55
import { upload } from '@argos-ci/core';
66
import yargs from 'yargs';
7+
import path from 'path';
78

8-
const screenshotsBase = 'test/regressions/screenshots/chrome';
9-
const screenshotsPigmentCSSBase = 'screenshots/chrome';
10-
const screenshotsTmp = 'test/regressions/screenshots/argos';
119
const BATCH_SIZE = 200;
1210

13-
const argv = yargs(process.argv.slice(2)).option('verbose', {
14-
alias: 'v',
15-
type: 'boolean',
16-
description: 'Run with verbose logging',
17-
}).argv;
11+
const argv = yargs(process.argv.slice(2))
12+
.option('verbose', {
13+
alias: 'v',
14+
type: 'boolean',
15+
description: 'Run with verbose logging',
16+
})
17+
.demandCommand(1, 'You need to specify the screenshots folder as a positional argument').argv;
1818

1919
async function run() {
20-
const emotionScreenshots = await glob(`${screenshotsBase}/**/*`);
21-
const pigmentCSSScnreeshots = await glob(`${screenshotsPigmentCSSBase}/**/*`);
22-
const screenshots = [...emotionScreenshots, ...pigmentCSSScnreeshots];
20+
const tempDir = await fse.mkdtemp(path.resolve('argos-screenshots-'));
2321

24-
console.log(`Found ${screenshots.length} screenshots.`);
25-
if (argv.verbose) {
26-
console.log('Screenshots found:');
27-
screenshots.forEach((screenshot) => {
28-
console.log(` - ${screenshot}`);
29-
});
30-
}
22+
try {
23+
const screenshotsFolder = argv._[0];
24+
const screenshots = await glob(`${screenshotsFolder}/**/*`);
25+
26+
console.log(`Found ${screenshots.length} screenshots.`);
27+
if (argv.verbose) {
28+
console.log('Screenshots found:');
29+
screenshots.forEach((screenshot) => {
30+
console.log(` - ${screenshot}`);
31+
});
32+
}
3133

32-
const chunks = lodashChunk(screenshots, BATCH_SIZE);
34+
const chunks = lodashChunk(screenshots, BATCH_SIZE);
3335

34-
await Promise.all(
35-
chunks.map((chunk, chunkIndex) =>
36-
Promise.all(
37-
chunk.map((screenshot) => {
38-
return fse.move(
39-
screenshot,
40-
`${screenshotsTmp}/${chunkIndex}/${screenshot.replace(screenshotsBase, '').replace(screenshotsPigmentCSSBase, '')}`,
41-
);
42-
}),
36+
await Promise.all(
37+
chunks.map((chunk, chunkIndex) =>
38+
Promise.all(
39+
chunk.map((screenshot) => {
40+
const relativePath = path.relative(screenshotsFolder, screenshot);
41+
return fse.move(screenshot, path.join(tempDir, `${chunkIndex}`, relativePath));
42+
}),
43+
),
4344
),
44-
),
45-
);
45+
);
4646

47-
for (let i = 0; i < chunks.length; i += 1) {
48-
// eslint-disable-next-line no-await-in-loop
49-
const result = await upload({
50-
root: `${screenshotsTmp}/${i}`,
51-
commit: process.env.CIRCLE_SHA1,
52-
branch: process.env.CIRCLE_BRANCH,
53-
token: process.env.ARGOS_TOKEN,
54-
parallel: {
55-
total: chunks.length,
56-
nonce: process.env.CIRCLE_BUILD_NUM,
57-
},
58-
});
47+
for (let i = 0; i < chunks.length; i += 1) {
48+
// eslint-disable-next-line no-await-in-loop
49+
const result = await upload({
50+
root: `${tempDir}/${i}`,
51+
commit: process.env.CIRCLE_SHA1,
52+
branch: process.env.CIRCLE_BRANCH,
53+
token: process.env.ARGOS_TOKEN,
54+
parallel: {
55+
total: chunks.length,
56+
nonce: process.env.CIRCLE_BUILD_NUM,
57+
},
58+
});
5959

60-
console.log(
61-
`Batch of ${chunks[i].length} screenshots uploaded. Build URL: ${result.build.url}`,
62-
);
60+
console.log(
61+
`Batch of ${chunks[i].length} screenshots uploaded. Build URL: ${result.build.url}`,
62+
);
63+
}
64+
} finally {
65+
await fse.remove(tempDir);
6366
}
6467
}
6568

0 commit comments

Comments
 (0)