@argos-ci/core 6.3.0 → 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 +149 -36
- 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.
|
|
@@ -1460,6 +1474,93 @@ const require = createRequire(import.meta.url);
|
|
|
1460
1474
|
async function getArgosCoreSDKIdentifier() {
|
|
1461
1475
|
return `@argos-ci/core@${await readVersionFromPackage(require.resolve("@argos-ci/core/package.json"))}`;
|
|
1462
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
|
+
}
|
|
1463
1564
|
//#endregion
|
|
1464
1565
|
//#region src/mime-type.ts
|
|
1465
1566
|
/**
|
|
@@ -1577,29 +1678,41 @@ async function upload(params) {
|
|
|
1577
1678
|
if (projectResponse.error) throwAPIError(projectResponse.error, projectResponse.response);
|
|
1578
1679
|
debug("Project fetched", projectResponse.data);
|
|
1579
1680
|
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
1580
|
-
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 () => {
|
|
1581
1688
|
if (config.referenceCommit) {
|
|
1582
1689
|
debug("Found reference commit in config", config.referenceCommit);
|
|
1583
|
-
return
|
|
1690
|
+
return {
|
|
1691
|
+
referenceCommit: config.referenceCommit,
|
|
1692
|
+
parentCommits: await listCommits(config.referenceCommit, 300)
|
|
1693
|
+
};
|
|
1584
1694
|
}
|
|
1585
|
-
if (hasRemoteContentAccess) return
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
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
|
+
}
|
|
1589
1715
|
});
|
|
1590
|
-
if (sha) debug("Found merge base", sha);
|
|
1591
|
-
else debug("No merge base found");
|
|
1592
|
-
return sha;
|
|
1593
|
-
})();
|
|
1594
|
-
const parentCommits = await (async () => {
|
|
1595
|
-
if (hasRemoteContentAccess) return null;
|
|
1596
|
-
if (referenceCommit) {
|
|
1597
|
-
const commits = await listParentCommits({ sha: referenceCommit });
|
|
1598
|
-
if (commits) debug("Found parent commits", commits);
|
|
1599
|
-
else debug("No parent commits found");
|
|
1600
|
-
return commits;
|
|
1601
|
-
}
|
|
1602
|
-
return null;
|
|
1603
1716
|
})();
|
|
1604
1717
|
debug("Creating build");
|
|
1605
1718
|
const pwTraceKeys = [];
|
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
|
}
|