@argos-ci/core 6.0.3 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +56 -29
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1002,6 +1002,18 @@ async function uploadFile(input) {
|
|
|
1002
1002
|
});
|
|
1003
1003
|
if (!response.ok) throw new Error(`Failed to upload file to ${input.url}: ${response.status} ${response.statusText}`);
|
|
1004
1004
|
}
|
|
1005
|
+
async function uploadFileWithPresignedPost(input) {
|
|
1006
|
+
const file = await readFile(input.path);
|
|
1007
|
+
const formData = new FormData();
|
|
1008
|
+
for (const [key, value] of Object.entries(input.fields)) formData.append(key, value);
|
|
1009
|
+
formData.append("file", new Blob([new Uint8Array(file)], { type: input.contentType }), basename(input.path));
|
|
1010
|
+
const response = await fetch(input.url, {
|
|
1011
|
+
method: "POST",
|
|
1012
|
+
signal: AbortSignal.timeout(3e4),
|
|
1013
|
+
body: formData
|
|
1014
|
+
});
|
|
1015
|
+
if (!response.ok) throw new Error(`Failed to upload file to ${input.url}: ${response.status} ${response.statusText}`);
|
|
1016
|
+
}
|
|
1005
1017
|
//#endregion
|
|
1006
1018
|
//#region src/util/chunk.ts
|
|
1007
1019
|
/**
|
|
@@ -1016,6 +1028,15 @@ const chunk = (collection, size) => {
|
|
|
1016
1028
|
}
|
|
1017
1029
|
return result;
|
|
1018
1030
|
};
|
|
1031
|
+
/**
|
|
1032
|
+
* Map over a collection asynchronously, processing at most `size` items
|
|
1033
|
+
* concurrently to limit memory pressure.
|
|
1034
|
+
*/
|
|
1035
|
+
async function mapInChunks(collection, size, mapper) {
|
|
1036
|
+
const results = [];
|
|
1037
|
+
for (const items of chunk(collection, size)) results.push(...await Promise.all(items.map(mapper)));
|
|
1038
|
+
return results;
|
|
1039
|
+
}
|
|
1019
1040
|
//#endregion
|
|
1020
1041
|
//#region src/github-actions-oidc.ts
|
|
1021
1042
|
/**
|
|
@@ -1348,7 +1369,7 @@ async function skip(params) {
|
|
|
1348
1369
|
runId: config.runId,
|
|
1349
1370
|
runAttempt: config.runAttempt,
|
|
1350
1371
|
skipped: true,
|
|
1351
|
-
|
|
1372
|
+
screenshots: [],
|
|
1352
1373
|
pwTraceKeys: [],
|
|
1353
1374
|
parentCommits: []
|
|
1354
1375
|
} });
|
|
@@ -1358,9 +1379,11 @@ async function skip(params) {
|
|
|
1358
1379
|
//#endregion
|
|
1359
1380
|
//#region src/upload.ts
|
|
1360
1381
|
/**
|
|
1361
|
-
* Size of the chunks used to upload screenshots
|
|
1382
|
+
* Size of the chunks used to process and upload screenshots.
|
|
1383
|
+
* Limits concurrency to avoid memory pressure when handling many screenshots.
|
|
1362
1384
|
*/
|
|
1363
1385
|
const CHUNK_SIZE = 10;
|
|
1386
|
+
const PLAYWRIGHT_TRACE_CONTENT_TYPE = "application/zip";
|
|
1364
1387
|
/**
|
|
1365
1388
|
* Upload screenshots to Argos.
|
|
1366
1389
|
*/
|
|
@@ -1387,7 +1410,7 @@ async function upload(params) {
|
|
|
1387
1410
|
ignore: params.ignore
|
|
1388
1411
|
});
|
|
1389
1412
|
debug("Found snapshots", files);
|
|
1390
|
-
const snapshots = await
|
|
1413
|
+
const snapshots = await mapInChunks(files, CHUNK_SIZE, async (snapshot) => {
|
|
1391
1414
|
const contentType = getSnapshotMimeType(snapshot.path);
|
|
1392
1415
|
const [metadata, pwTracePath, optimizedPath] = await Promise.all([
|
|
1393
1416
|
readMetadata(snapshot.path),
|
|
@@ -1416,7 +1439,7 @@ async function upload(params) {
|
|
|
1416
1439
|
} : null,
|
|
1417
1440
|
contentType
|
|
1418
1441
|
};
|
|
1419
|
-
})
|
|
1442
|
+
});
|
|
1420
1443
|
debug("Fetch project");
|
|
1421
1444
|
const projectResponse = await apiClient.GET("/project");
|
|
1422
1445
|
if (projectResponse.error) throwAPIError(projectResponse.error);
|
|
@@ -1447,11 +1470,15 @@ async function upload(params) {
|
|
|
1447
1470
|
return null;
|
|
1448
1471
|
})();
|
|
1449
1472
|
debug("Creating build");
|
|
1450
|
-
const
|
|
1473
|
+
const pwTraceKeys = [];
|
|
1474
|
+
const screenshots = [];
|
|
1475
|
+
for (const snapshot of snapshots) {
|
|
1451
1476
|
if (snapshot.pwTrace && !pwTraceKeys.includes(snapshot.pwTrace.hash)) pwTraceKeys.push(snapshot.pwTrace.hash);
|
|
1452
|
-
if (!
|
|
1453
|
-
|
|
1454
|
-
|
|
1477
|
+
if (!screenshots.some((item) => item.key === snapshot.hash)) screenshots.push({
|
|
1478
|
+
key: snapshot.hash,
|
|
1479
|
+
contentType: snapshot.contentType
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1455
1482
|
const createBuildResponse = await apiClient.POST("/builds", { body: {
|
|
1456
1483
|
commit: config.commit,
|
|
1457
1484
|
branch: config.branch,
|
|
@@ -1459,7 +1486,7 @@ async function upload(params) {
|
|
|
1459
1486
|
mode: config.mode,
|
|
1460
1487
|
parallel: config.parallel,
|
|
1461
1488
|
parallelNonce: config.parallelNonce,
|
|
1462
|
-
|
|
1489
|
+
screenshots,
|
|
1463
1490
|
pwTraceKeys,
|
|
1464
1491
|
prNumber: config.prNumber,
|
|
1465
1492
|
prHeadCommit: config.prHeadCommit,
|
|
@@ -1477,22 +1504,20 @@ async function upload(params) {
|
|
|
1477
1504
|
if (createBuildResponse.error) throwAPIError(createBuildResponse.error);
|
|
1478
1505
|
const result = createBuildResponse.data;
|
|
1479
1506
|
debug("Got uploads url", result);
|
|
1480
|
-
await uploadFilesToS3([...result.screenshots.map((
|
|
1481
|
-
const snapshot = snapshots.find((s) => s.hash === key);
|
|
1482
|
-
if (!snapshot) throw new Error(`Invariant: snapshot with hash ${key} not found`);
|
|
1483
|
-
return {
|
|
1484
|
-
url: putUrl,
|
|
1507
|
+
await uploadFilesToS3([...result.screenshots.map((upload) => {
|
|
1508
|
+
const snapshot = snapshots.find((s) => s.hash === upload.key);
|
|
1509
|
+
if (!snapshot) throw new Error(`Invariant: snapshot with hash ${upload.key} not found`);
|
|
1510
|
+
return createSecureUploadFileInput(upload, {
|
|
1485
1511
|
path: snapshot.optimizedPath,
|
|
1486
1512
|
contentType: snapshot.contentType
|
|
1487
|
-
};
|
|
1488
|
-
}), ...result.pwTraces?.map((
|
|
1489
|
-
const snapshot = snapshots.find((s) => s.pwTrace && s.pwTrace.hash === key);
|
|
1490
|
-
if (!snapshot || !snapshot.pwTrace) throw new Error(`Invariant: trace with ${key} not found`);
|
|
1491
|
-
return {
|
|
1492
|
-
url: putUrl,
|
|
1513
|
+
});
|
|
1514
|
+
}), ...result.pwTraces?.map((upload) => {
|
|
1515
|
+
const snapshot = snapshots.find((s) => s.pwTrace && s.pwTrace.hash === upload.key);
|
|
1516
|
+
if (!snapshot || !snapshot.pwTrace) throw new Error(`Invariant: trace with ${upload.key} not found`);
|
|
1517
|
+
return createSecureUploadFileInput(upload, {
|
|
1493
1518
|
path: snapshot.pwTrace.path,
|
|
1494
|
-
contentType:
|
|
1495
|
-
};
|
|
1519
|
+
contentType: PLAYWRIGHT_TRACE_CONTENT_TYPE
|
|
1520
|
+
});
|
|
1496
1521
|
}) ?? []]);
|
|
1497
1522
|
debug("Updating build");
|
|
1498
1523
|
const uploadBuildResponse = await apiClient.PUT("/builds/{buildId}", {
|
|
@@ -1530,16 +1555,18 @@ async function uploadFilesToS3(files) {
|
|
|
1530
1555
|
debugTime(timeLabel);
|
|
1531
1556
|
const chunk = chunks[i];
|
|
1532
1557
|
if (!chunk) throw new Error(`Invariant: chunk ${i} is empty`);
|
|
1533
|
-
await Promise.all(chunk.map(
|
|
1534
|
-
await uploadFile({
|
|
1535
|
-
url,
|
|
1536
|
-
path,
|
|
1537
|
-
contentType
|
|
1538
|
-
});
|
|
1539
|
-
}));
|
|
1558
|
+
await Promise.all(chunk.map((file) => uploadFileWithPresignedPost(file)));
|
|
1540
1559
|
debugTimeEnd(timeLabel);
|
|
1541
1560
|
}
|
|
1542
1561
|
}
|
|
1562
|
+
function createSecureUploadFileInput(upload, file) {
|
|
1563
|
+
if (!("postUrl" in upload)) throw new Error(`Invariant: expected secure upload for ${upload.key}`);
|
|
1564
|
+
return {
|
|
1565
|
+
url: upload.postUrl,
|
|
1566
|
+
fields: upload.fields,
|
|
1567
|
+
...file
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1543
1570
|
/**
|
|
1544
1571
|
* Format the preview URL.
|
|
1545
1572
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Node.js SDK for visual testing with Argos.",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.1.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@argos-ci/api-client": "0.
|
|
42
|
+
"@argos-ci/api-client": "0.22.0",
|
|
43
43
|
"@argos-ci/util": "4.0.0",
|
|
44
44
|
"convict": "^6.2.5",
|
|
45
45
|
"debug": "^4.4.3",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"lint": "eslint .",
|
|
68
68
|
"test": "vitest"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "ee8cfb3ab17cb541f8c3456a271d32c3411077c6"
|
|
71
71
|
}
|