@argos-ci/core 6.2.3 → 6.4.0
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.mjs +208 -57
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -180,18 +180,32 @@ function listShas(path, maxCount) {
|
|
|
180
180
|
args.push(path);
|
|
181
181
|
return execFileSync("git", args).toString().trim().split("\n");
|
|
182
182
|
}
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
/**
|
|
184
|
+
* List the ancestor commits of a commit, ordered from the closest to the
|
|
185
|
+
* furthest ancestor, up to `limit` commits. The commit itself is excluded.
|
|
186
|
+
*
|
|
187
|
+
* The history is deepened with a shallow fetch so this works on the shallow
|
|
188
|
+
* clones typically used in CI. When the commit is not on the remote (e.g. not
|
|
189
|
+
* pushed yet) or the fetch fails, we fall back to whatever local history is
|
|
190
|
+
* available; when the commit is unknown locally too, we return an empty list.
|
|
191
|
+
*/
|
|
192
|
+
async function listAncestorCommits$1(input) {
|
|
193
|
+
const depth = input.limit + 1;
|
|
185
194
|
try {
|
|
186
195
|
await runGitFetch([
|
|
187
|
-
`--depth=${
|
|
196
|
+
`--depth=${depth}`,
|
|
188
197
|
"origin",
|
|
189
198
|
input.sha
|
|
190
199
|
]);
|
|
191
200
|
} catch (error) {
|
|
192
|
-
|
|
201
|
+
debug(`Failed to deepen history for ${input.sha}, using local history`, getGitErrorOutput(error));
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
return listShas(input.sha, depth).slice(1);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
debug(`Failed to list ancestors of ${input.sha}`, getGitErrorOutput(error));
|
|
207
|
+
return [];
|
|
193
208
|
}
|
|
194
|
-
return listShas(input.sha, limit);
|
|
195
209
|
}
|
|
196
210
|
//#endregion
|
|
197
211
|
//#region src/ci-environment/services/bitrise.ts
|
|
@@ -226,7 +240,7 @@ const service$7 = {
|
|
|
226
240
|
};
|
|
227
241
|
},
|
|
228
242
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
229
|
-
|
|
243
|
+
listAncestorCommits: listAncestorCommits$1
|
|
230
244
|
};
|
|
231
245
|
//#endregion
|
|
232
246
|
//#region src/util/url.ts
|
|
@@ -270,7 +284,7 @@ const service$6 = {
|
|
|
270
284
|
};
|
|
271
285
|
},
|
|
272
286
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
273
|
-
|
|
287
|
+
listAncestorCommits: listAncestorCommits$1
|
|
274
288
|
};
|
|
275
289
|
//#endregion
|
|
276
290
|
//#region src/ci-environment/services/heroku.ts
|
|
@@ -293,7 +307,7 @@ const service$5 = {
|
|
|
293
307
|
nonce: env.HEROKU_TEST_RUN_ID || null
|
|
294
308
|
}),
|
|
295
309
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
296
|
-
|
|
310
|
+
listAncestorCommits: listAncestorCommits$1
|
|
297
311
|
};
|
|
298
312
|
//#endregion
|
|
299
313
|
//#region src/ci-environment/github.ts
|
|
@@ -564,7 +578,7 @@ const service$4 = {
|
|
|
564
578
|
};
|
|
565
579
|
},
|
|
566
580
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
567
|
-
|
|
581
|
+
listAncestorCommits: listAncestorCommits$1
|
|
568
582
|
};
|
|
569
583
|
//#endregion
|
|
570
584
|
//#region src/ci-environment/services/circleci.ts
|
|
@@ -605,7 +619,7 @@ const service$3 = {
|
|
|
605
619
|
};
|
|
606
620
|
},
|
|
607
621
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
608
|
-
|
|
622
|
+
listAncestorCommits: listAncestorCommits$1
|
|
609
623
|
};
|
|
610
624
|
//#endregion
|
|
611
625
|
//#region src/ci-environment/services/travis.ts
|
|
@@ -644,7 +658,7 @@ const service$2 = {
|
|
|
644
658
|
};
|
|
645
659
|
},
|
|
646
660
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
647
|
-
|
|
661
|
+
listAncestorCommits: listAncestorCommits$1
|
|
648
662
|
};
|
|
649
663
|
//#endregion
|
|
650
664
|
//#region src/ci-environment/services/gitlab.ts
|
|
@@ -678,7 +692,7 @@ const service$1 = {
|
|
|
678
692
|
};
|
|
679
693
|
},
|
|
680
694
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
681
|
-
|
|
695
|
+
listAncestorCommits: listAncestorCommits$1
|
|
682
696
|
};
|
|
683
697
|
//#endregion
|
|
684
698
|
//#region src/ci-environment/services/git.ts
|
|
@@ -718,7 +732,7 @@ const services = [
|
|
|
718
732
|
};
|
|
719
733
|
},
|
|
720
734
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
721
|
-
|
|
735
|
+
listAncestorCommits: listAncestorCommits$1
|
|
722
736
|
}
|
|
723
737
|
];
|
|
724
738
|
/**
|
|
@@ -743,13 +757,13 @@ function getMergeBaseCommitSha(input) {
|
|
|
743
757
|
return service.getMergeBaseCommitSha(input, context);
|
|
744
758
|
}
|
|
745
759
|
/**
|
|
746
|
-
*
|
|
760
|
+
* List the ancestor commits of a commit, closest first, up to `limit` commits.
|
|
747
761
|
*/
|
|
748
|
-
function
|
|
762
|
+
function listAncestorCommits(input) {
|
|
749
763
|
const context = createContext();
|
|
750
764
|
const service = getCiService(context);
|
|
751
|
-
if (!service) return Promise.resolve(
|
|
752
|
-
return service.
|
|
765
|
+
if (!service) return Promise.resolve([]);
|
|
766
|
+
return service.listAncestorCommits(input, context);
|
|
753
767
|
}
|
|
754
768
|
/**
|
|
755
769
|
* Get the CI environment.
|
|
@@ -1133,6 +1147,27 @@ const chunk = (collection, size) => {
|
|
|
1133
1147
|
return result;
|
|
1134
1148
|
};
|
|
1135
1149
|
/**
|
|
1150
|
+
* Split items into chunks whose serialized JSON size stays under `maxBytes`.
|
|
1151
|
+
* An item larger than `maxBytes` on its own gets its own chunk.
|
|
1152
|
+
*/
|
|
1153
|
+
const chunkBySize = (items, maxBytes) => {
|
|
1154
|
+
const chunks = [];
|
|
1155
|
+
let current = [];
|
|
1156
|
+
let currentBytes = 0;
|
|
1157
|
+
for (const item of items) {
|
|
1158
|
+
const size = Buffer.byteLength(JSON.stringify(item));
|
|
1159
|
+
if (current.length > 0 && currentBytes + size > maxBytes) {
|
|
1160
|
+
chunks.push(current);
|
|
1161
|
+
current = [];
|
|
1162
|
+
currentBytes = 0;
|
|
1163
|
+
}
|
|
1164
|
+
current.push(item);
|
|
1165
|
+
currentBytes += size;
|
|
1166
|
+
}
|
|
1167
|
+
if (current.length > 0) chunks.push(current);
|
|
1168
|
+
return chunks;
|
|
1169
|
+
};
|
|
1170
|
+
/**
|
|
1136
1171
|
* Map over a collection asynchronously, processing at most `size` items
|
|
1137
1172
|
* concurrently to limit memory pressure.
|
|
1138
1173
|
*/
|
|
@@ -1439,6 +1474,93 @@ const require = createRequire(import.meta.url);
|
|
|
1439
1474
|
async function getArgosCoreSDKIdentifier() {
|
|
1440
1475
|
return `@argos-ci/core@${await readVersionFromPackage(require.resolve("@argos-ci/core/package.json"))}`;
|
|
1441
1476
|
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Maximum number of commits inspected before giving up.
|
|
1479
|
+
*/
|
|
1480
|
+
const MAX_COMMITS = 5e3;
|
|
1481
|
+
/**
|
|
1482
|
+
* Cumulative number of commits to inspect after each batch: 100, 600, 1100, …,
|
|
1483
|
+
* up to {@link MAX_COMMITS}.
|
|
1484
|
+
*/
|
|
1485
|
+
function getCumulativeBatchSizes() {
|
|
1486
|
+
const sizes = [];
|
|
1487
|
+
let total = Math.min(100, MAX_COMMITS);
|
|
1488
|
+
sizes.push(total);
|
|
1489
|
+
while (total < MAX_COMMITS) {
|
|
1490
|
+
total = Math.min(total + 500, MAX_COMMITS);
|
|
1491
|
+
sizes.push(total);
|
|
1492
|
+
}
|
|
1493
|
+
return sizes;
|
|
1494
|
+
}
|
|
1495
|
+
/**
|
|
1496
|
+
* Find the reference commit by asking the API to pick the closest commit that
|
|
1497
|
+
* has an eligible baseline build, among a list of candidate commits ordered from
|
|
1498
|
+
* the closest to the furthest ancestor. That build's commit becomes the
|
|
1499
|
+
* reference commit.
|
|
1500
|
+
*
|
|
1501
|
+
* Commits are inspected in growing batches ({@link FIRST_BATCH_SIZE}, then
|
|
1502
|
+
* {@link NEXT_BATCH_SIZE} per request, up to {@link MAX_COMMITS}) so the common
|
|
1503
|
+
* case resolves quickly without fetching and sending the whole history.
|
|
1504
|
+
*/
|
|
1505
|
+
async function findReferenceCommit(params) {
|
|
1506
|
+
let inspectedCount = 0;
|
|
1507
|
+
for (const limit of getCumulativeBatchSizes()) {
|
|
1508
|
+
const commits = await params.listCommits(limit);
|
|
1509
|
+
const batch = commits.slice(inspectedCount);
|
|
1510
|
+
if (batch.length === 0) break;
|
|
1511
|
+
debug(`Looking for a baseline among ${batch.length} commit(s)`);
|
|
1512
|
+
const baseline = await params.findBaseline(batch);
|
|
1513
|
+
if (baseline) {
|
|
1514
|
+
debug("Found baseline build for reference commit", baseline.head.sha);
|
|
1515
|
+
return baseline.head.sha;
|
|
1516
|
+
}
|
|
1517
|
+
inspectedCount = commits.length;
|
|
1518
|
+
if (commits.length < limit) break;
|
|
1519
|
+
}
|
|
1520
|
+
debug("No eligible baseline found among ancestor commits");
|
|
1521
|
+
return null;
|
|
1522
|
+
}
|
|
1523
|
+
/**
|
|
1524
|
+
* Resolve the baseline for a build that has no remote content access (no Git
|
|
1525
|
+
* provider connected).
|
|
1526
|
+
*
|
|
1527
|
+
* 1. Find the merge base — the closest common ancestor of the build branch and
|
|
1528
|
+
* its base branch. This is always the starting point.
|
|
1529
|
+
* 2. From the merge base, ask the API to pick the closest commit (the merge base
|
|
1530
|
+
* itself or one of its ancestors) that has an eligible baseline build, and use
|
|
1531
|
+
* it as the reference commit.
|
|
1532
|
+
* 3. If none is found, the baseline build may still be processing on the server.
|
|
1533
|
+
* Fall back to the merge base as the reference commit and send its parent
|
|
1534
|
+
* commits so the server can resolve the baseline once that build completes.
|
|
1535
|
+
*/
|
|
1536
|
+
async function resolveBaseline(params) {
|
|
1537
|
+
const mergeBase = await params.getMergeBase();
|
|
1538
|
+
if (!mergeBase) {
|
|
1539
|
+
debug("No merge base found");
|
|
1540
|
+
return {
|
|
1541
|
+
referenceCommit: null,
|
|
1542
|
+
parentCommits: null
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
debug("Found merge base", mergeBase);
|
|
1546
|
+
const referenceCommit = await findReferenceCommit({
|
|
1547
|
+
listCommits: (limit) => params.listCommits(mergeBase, limit),
|
|
1548
|
+
findBaseline: params.findBaseline
|
|
1549
|
+
});
|
|
1550
|
+
if (referenceCommit) {
|
|
1551
|
+
debug("Found reference commit from baseline", referenceCommit);
|
|
1552
|
+
return {
|
|
1553
|
+
referenceCommit,
|
|
1554
|
+
parentCommits: null
|
|
1555
|
+
};
|
|
1556
|
+
}
|
|
1557
|
+
const parentCommits = await params.listCommits(mergeBase, 300);
|
|
1558
|
+
debug("No baseline found, using merge base with parent commits", mergeBase);
|
|
1559
|
+
return {
|
|
1560
|
+
referenceCommit: mergeBase,
|
|
1561
|
+
parentCommits
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1442
1564
|
//#endregion
|
|
1443
1565
|
//#region src/mime-type.ts
|
|
1444
1566
|
/**
|
|
@@ -1488,6 +1610,12 @@ async function skip(params) {
|
|
|
1488
1610
|
* Limits concurrency to avoid memory pressure when handling many screenshots.
|
|
1489
1611
|
*/
|
|
1490
1612
|
const CHUNK_SIZE = 10;
|
|
1613
|
+
/**
|
|
1614
|
+
* Maximum serialized size (in bytes) of the screenshots sent in a single
|
|
1615
|
+
* `updateBuild` request. Kept below the API request body size limit (3MB) to
|
|
1616
|
+
* leave room for the rest of the body (build metadata, etc.).
|
|
1617
|
+
*/
|
|
1618
|
+
const MAX_UPDATE_BUILD_SCREENSHOTS_BYTES = 2 * 1024 * 1024;
|
|
1491
1619
|
const PLAYWRIGHT_TRACE_CONTENT_TYPE = "application/zip";
|
|
1492
1620
|
/**
|
|
1493
1621
|
* Upload screenshots to Argos.
|
|
@@ -1550,29 +1678,41 @@ async function upload(params) {
|
|
|
1550
1678
|
if (projectResponse.error) throwAPIError(projectResponse.error, projectResponse.response);
|
|
1551
1679
|
debug("Project fetched", projectResponse.data);
|
|
1552
1680
|
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
1553
|
-
const
|
|
1681
|
+
const listCommits = async (sha, limit) => {
|
|
1682
|
+
return [sha, ...await listAncestorCommits({
|
|
1683
|
+
sha,
|
|
1684
|
+
limit: limit - 1
|
|
1685
|
+
})];
|
|
1686
|
+
};
|
|
1687
|
+
const { referenceCommit, parentCommits } = await (async () => {
|
|
1554
1688
|
if (config.referenceCommit) {
|
|
1555
1689
|
debug("Found reference commit in config", config.referenceCommit);
|
|
1556
|
-
return
|
|
1690
|
+
return {
|
|
1691
|
+
referenceCommit: config.referenceCommit,
|
|
1692
|
+
parentCommits: await listCommits(config.referenceCommit, 300)
|
|
1693
|
+
};
|
|
1557
1694
|
}
|
|
1558
|
-
if (hasRemoteContentAccess) return
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1695
|
+
if (hasRemoteContentAccess) return {
|
|
1696
|
+
referenceCommit: null,
|
|
1697
|
+
parentCommits: null
|
|
1698
|
+
};
|
|
1699
|
+
const base = config.referenceBranch || config.prBaseBranch || defaultBaseBranch;
|
|
1700
|
+
return resolveBaseline({
|
|
1701
|
+
getMergeBase: () => getMergeBaseCommitSha({
|
|
1702
|
+
base,
|
|
1703
|
+
head: config.branch
|
|
1704
|
+
}),
|
|
1705
|
+
listCommits,
|
|
1706
|
+
findBaseline: async (commits) => {
|
|
1707
|
+
const response = await apiClient.POST("/baseline", { body: {
|
|
1708
|
+
commits,
|
|
1709
|
+
name: config.buildName ?? void 0,
|
|
1710
|
+
mode: config.mode ?? void 0
|
|
1711
|
+
} });
|
|
1712
|
+
if (response.error) throwAPIError(response.error, response.response);
|
|
1713
|
+
return response.data.baseline;
|
|
1714
|
+
}
|
|
1562
1715
|
});
|
|
1563
|
-
if (sha) debug("Found merge base", sha);
|
|
1564
|
-
else debug("No merge base found");
|
|
1565
|
-
return sha;
|
|
1566
|
-
})();
|
|
1567
|
-
const parentCommits = await (async () => {
|
|
1568
|
-
if (hasRemoteContentAccess) return null;
|
|
1569
|
-
if (referenceCommit) {
|
|
1570
|
-
const commits = await listParentCommits({ sha: referenceCommit });
|
|
1571
|
-
if (commits) debug("Found parent commits", commits);
|
|
1572
|
-
else debug("No parent commits found");
|
|
1573
|
-
return commits;
|
|
1574
|
-
}
|
|
1575
|
-
return null;
|
|
1576
1716
|
})();
|
|
1577
1717
|
debug("Creating build");
|
|
1578
1718
|
const pwTraceKeys = [];
|
|
@@ -1625,28 +1765,39 @@ async function upload(params) {
|
|
|
1625
1765
|
});
|
|
1626
1766
|
}) ?? []]);
|
|
1627
1767
|
debug("Updating build");
|
|
1628
|
-
const
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1768
|
+
const screenshotChunks = chunkBySize(snapshots.map((snapshot) => ({
|
|
1769
|
+
key: snapshot.hash,
|
|
1770
|
+
name: snapshot.name,
|
|
1771
|
+
metadata: snapshot.metadata,
|
|
1772
|
+
pwTraceKey: snapshot.pwTrace?.hash ?? null,
|
|
1773
|
+
threshold: snapshot.threshold ?? config?.threshold ?? null,
|
|
1774
|
+
baseName: snapshot.baseName,
|
|
1775
|
+
parentName: snapshot.parentName,
|
|
1776
|
+
contentType: snapshot.contentType
|
|
1777
|
+
})), MAX_UPDATE_BUILD_SCREENSHOTS_BYTES);
|
|
1778
|
+
if (screenshotChunks.length === 0) screenshotChunks.push([]);
|
|
1779
|
+
const groupsRequests = !config.parallel || config.parallelIndex != null;
|
|
1780
|
+
let build = null;
|
|
1781
|
+
for (let index = 0; index < screenshotChunks.length; index++) {
|
|
1782
|
+
const isLast = index === screenshotChunks.length - 1;
|
|
1783
|
+
debug(`Updating build (request ${index + 1}/${screenshotChunks.length})`);
|
|
1784
|
+
const uploadBuildResponse = await apiClient.PUT("/builds/{buildId}", {
|
|
1785
|
+
params: { path: { buildId: result.build.id } },
|
|
1786
|
+
body: {
|
|
1787
|
+
screenshots: screenshotChunks[index] ?? [],
|
|
1788
|
+
parallel: config.parallel,
|
|
1789
|
+
parallelTotal: config.parallelTotal,
|
|
1790
|
+
parallelIndex: config.parallelIndex,
|
|
1791
|
+
final: groupsRequests ? isLast : true,
|
|
1792
|
+
metadata: isLast ? params.metadata : void 0
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
if (uploadBuildResponse.error) throwAPIError(uploadBuildResponse.error, uploadBuildResponse.response);
|
|
1796
|
+
if (isLast) build = uploadBuildResponse.data.build;
|
|
1797
|
+
}
|
|
1798
|
+
if (!build) throw new Error("Invariant: the build was not updated");
|
|
1648
1799
|
return {
|
|
1649
|
-
build
|
|
1800
|
+
build,
|
|
1650
1801
|
screenshots: snapshots
|
|
1651
1802
|
};
|
|
1652
1803
|
}
|
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.4.0",
|
|
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.24.0",
|
|
43
43
|
"@argos-ci/util": "4.0.0",
|
|
44
44
|
"convict": "^6.2.5",
|
|
45
45
|
"debug": "^4.4.3",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"lint": "eslint .",
|
|
69
69
|
"test": "vitest"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "ee2e5d3c14c83e07dfffa14ddc9f34f934f8c368"
|
|
72
72
|
}
|