@argos-ci/core 6.8.0 → 6.8.2
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 +5 -1
- package/dist/index.mjs +126 -14
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -299,7 +299,11 @@ interface UploadMediaParameters {
|
|
|
299
299
|
description?: string;
|
|
300
300
|
/**
|
|
301
301
|
* Who can open the share page. `team` requires an Argos session; `public` only
|
|
302
|
-
* requires the URL.
|
|
302
|
+
* requires the URL.
|
|
303
|
+
*
|
|
304
|
+
* Leave it out — the usual case — and the media takes the visibility of its
|
|
305
|
+
* project in Argos: `public` for a public project, `team` for a private one.
|
|
306
|
+
* `team` requires a paid plan.
|
|
303
307
|
*/
|
|
304
308
|
visibility?: MediaVisibility;
|
|
305
309
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -202,7 +202,7 @@ async function fetchMergeBaseRef(input) {
|
|
|
202
202
|
* history and returns `null` when no merge base can be found, which resolves
|
|
203
203
|
* to a build without baseline (see `resolveBaseline`).
|
|
204
204
|
*/
|
|
205
|
-
async function getMergeBaseCommitSha$
|
|
205
|
+
async function getMergeBaseCommitSha$2(input) {
|
|
206
206
|
const argosBaseRef = `argos/${input.base}`;
|
|
207
207
|
const argosHeadRef = `argos/${input.head}`;
|
|
208
208
|
let head = null;
|
|
@@ -271,6 +271,56 @@ async function listAncestorCommits$1(input) {
|
|
|
271
271
|
return [];
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* Read the parent commits of a commit, ordered as recorded in the commit — the
|
|
276
|
+
* first parent first. Returns `null` when the commit is unknown, and an empty
|
|
277
|
+
* array when it has no parent.
|
|
278
|
+
*
|
|
279
|
+
* The history is deepened with a shallow fetch when the parents are not
|
|
280
|
+
* available locally: in the shallow clones typically used in CI, git hides the
|
|
281
|
+
* parents of the commits at the boundary of the history.
|
|
282
|
+
*/
|
|
283
|
+
async function getCommitParents(sha) {
|
|
284
|
+
const localParents = readCommitParents(sha);
|
|
285
|
+
if (localParents?.length) return localParents;
|
|
286
|
+
try {
|
|
287
|
+
await runGitFetch([
|
|
288
|
+
"--depth=2",
|
|
289
|
+
"origin",
|
|
290
|
+
sha
|
|
291
|
+
]);
|
|
292
|
+
} catch (error) {
|
|
293
|
+
debug(`Failed to deepen history for ${sha}, using local history`, getGitErrorOutput(error));
|
|
294
|
+
return localParents;
|
|
295
|
+
}
|
|
296
|
+
return readCommitParents(sha);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Read the parent commits of a commit from the local history. Returns `null`
|
|
300
|
+
* when the commit is unknown, and an empty array when it has no parent — a root
|
|
301
|
+
* commit, or a commit at the boundary of a shallow history, where git hides the
|
|
302
|
+
* parents.
|
|
303
|
+
*/
|
|
304
|
+
function readCommitParents(sha) {
|
|
305
|
+
try {
|
|
306
|
+
const [, ...parents] = execFileSync("git", [
|
|
307
|
+
"rev-list",
|
|
308
|
+
"--parents",
|
|
309
|
+
"-n",
|
|
310
|
+
"1",
|
|
311
|
+
sha,
|
|
312
|
+
"--"
|
|
313
|
+
], { stdio: [
|
|
314
|
+
"ignore",
|
|
315
|
+
"pipe",
|
|
316
|
+
"pipe"
|
|
317
|
+
] }).toString().trim().split(" ");
|
|
318
|
+
return parents;
|
|
319
|
+
} catch (error) {
|
|
320
|
+
debug(`Failed to read the parents of ${sha}`, getGitErrorOutput(error));
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
274
324
|
//#endregion
|
|
275
325
|
//#region src/ci-environment/services/bitrise.ts
|
|
276
326
|
function getPrNumber$2(context) {
|
|
@@ -303,7 +353,7 @@ const service$7 = {
|
|
|
303
353
|
nonce: env.BITRISEIO_PIPELINE_ID || null
|
|
304
354
|
};
|
|
305
355
|
},
|
|
306
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
356
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
307
357
|
listAncestorCommits: listAncestorCommits$1
|
|
308
358
|
};
|
|
309
359
|
//#endregion
|
|
@@ -315,7 +365,7 @@ const service$7 = {
|
|
|
315
365
|
function getRepositoryNameFromURL(url) {
|
|
316
366
|
const sshMatch = url.match(/^git@[^:]+:([^/]+)\/(.+?)(?:\.git)?$/);
|
|
317
367
|
if (sshMatch && sshMatch[1] && sshMatch[2]) return `${sshMatch[1]}/${sshMatch[2]}`;
|
|
318
|
-
const httpsMatch = url.match(/^(?:https?|git):\/\/[^/]+\/([^/]+)\/(.+?)(?:\.git)?$/);
|
|
368
|
+
const httpsMatch = url.replace(/^(https?:\/\/origin\.cursor\.com)\/git\//, "$1/").match(/^(?:https?|git):\/\/[^/]+\/([^/]+)\/(.+?)(?:\.git)?$/);
|
|
319
369
|
if (httpsMatch && httpsMatch[1] && httpsMatch[2]) return `${httpsMatch[1]}/${httpsMatch[2]}`;
|
|
320
370
|
return null;
|
|
321
371
|
}
|
|
@@ -326,6 +376,16 @@ function getRepository$5(context) {
|
|
|
326
376
|
if (env.BUILDKITE_REPO) return getRepositoryNameFromURL(env.BUILDKITE_REPO);
|
|
327
377
|
return null;
|
|
328
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* `BUILDKITE_COMMIT` is what the build was created with, not necessarily a
|
|
381
|
+
* SHA: a build started from the UI without a commit carries the literal
|
|
382
|
+
* `HEAD`. Only a full SHA is worth trusting over the checkout.
|
|
383
|
+
*/
|
|
384
|
+
function getCommit(env) {
|
|
385
|
+
const commit = env.BUILDKITE_COMMIT;
|
|
386
|
+
if (commit && /^[0-9a-f]{40}$/.test(commit)) return commit;
|
|
387
|
+
return head() || null;
|
|
388
|
+
}
|
|
329
389
|
const service$6 = {
|
|
330
390
|
name: "Buildkite",
|
|
331
391
|
key: "buildkite",
|
|
@@ -334,20 +394,20 @@ const service$6 = {
|
|
|
334
394
|
const { env } = context;
|
|
335
395
|
const repository = getRepository$5(context);
|
|
336
396
|
return {
|
|
337
|
-
commit: env
|
|
397
|
+
commit: getCommit(env),
|
|
338
398
|
branch: env.BUILDKITE_BRANCH || branch() || null,
|
|
339
399
|
repository,
|
|
340
400
|
originalRepository: repository,
|
|
341
401
|
jobId: null,
|
|
342
402
|
runId: null,
|
|
343
403
|
runAttempt: null,
|
|
344
|
-
prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null,
|
|
404
|
+
prNumber: /^\d+$/.test(env.BUILDKITE_PULL_REQUEST ?? "") ? Number(env.BUILDKITE_PULL_REQUEST) : null,
|
|
345
405
|
prHeadCommit: null,
|
|
346
|
-
prBaseBranch: null,
|
|
406
|
+
prBaseBranch: env.BUILDKITE_PULL_REQUEST_BASE_BRANCH || null,
|
|
347
407
|
nonce: env.BUILDKITE_BUILD_ID || null
|
|
348
408
|
};
|
|
349
409
|
},
|
|
350
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
410
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
351
411
|
listAncestorCommits: listAncestorCommits$1
|
|
352
412
|
};
|
|
353
413
|
//#endregion
|
|
@@ -370,7 +430,7 @@ const service$5 = {
|
|
|
370
430
|
prBaseBranch: null,
|
|
371
431
|
nonce: env.HEROKU_TEST_RUN_ID || null
|
|
372
432
|
}),
|
|
373
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
433
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
374
434
|
listAncestorCommits: listAncestorCommits$1
|
|
375
435
|
};
|
|
376
436
|
//#endregion
|
|
@@ -599,6 +659,57 @@ async function getPullRequest(args) {
|
|
|
599
659
|
}
|
|
600
660
|
return getPullRequestFromPayload(payload);
|
|
601
661
|
}
|
|
662
|
+
/**
|
|
663
|
+
* Get the commit of the base branch that GitHub merged into the pull request to
|
|
664
|
+
* run its checks.
|
|
665
|
+
*
|
|
666
|
+
* On a `pull_request` event, GitHub checks out a "test-merge" commit
|
|
667
|
+
* (`refs/pull/<n>/merge`): the pull request head merged into the tip of the base
|
|
668
|
+
* branch. The screenshots of such a build then contain the base branch changes
|
|
669
|
+
* up to that tip, so that tip — the first parent of the test-merge commit — is
|
|
670
|
+
* the commit to compare the build against. Comparing against the merge base
|
|
671
|
+
* instead reports every visual change merged into the base branch since the pull
|
|
672
|
+
* request branch was created as a change of the pull request.
|
|
673
|
+
*
|
|
674
|
+
* Returns `null` when the build does not run on a test-merge commit, in which
|
|
675
|
+
* case the merge base is used: another event, a workflow that checked out
|
|
676
|
+
* something else (e.g. the pull request head itself), a base branch overridden
|
|
677
|
+
* to another branch, or a commit whose parents can't be read.
|
|
678
|
+
*/
|
|
679
|
+
async function getTestMergeBaseCommitSha(input, ctx) {
|
|
680
|
+
if (ctx.env.GITHUB_EVENT_NAME !== "pull_request") return null;
|
|
681
|
+
const payload = readEventPayload(ctx);
|
|
682
|
+
const pullRequest = payload ? getPullRequestFromPayload(payload) : null;
|
|
683
|
+
if (!pullRequest) return null;
|
|
684
|
+
if (input.base !== pullRequest.base.ref) {
|
|
685
|
+
debug(`Base "${input.base}" is not the pull request base branch "${pullRequest.base.ref}", ignoring the test-merge commit`);
|
|
686
|
+
return null;
|
|
687
|
+
}
|
|
688
|
+
const sha = ctx.env.GITHUB_SHA;
|
|
689
|
+
if (!sha || head() !== sha) {
|
|
690
|
+
debug("Not running on the checked out commit, ignoring the test-merge commit");
|
|
691
|
+
return null;
|
|
692
|
+
}
|
|
693
|
+
const parents = await getCommitParents(sha);
|
|
694
|
+
if (parents?.length !== 2 || parents[1] !== pullRequest.head.sha) {
|
|
695
|
+
debug(`${sha} is not a test-merge commit of #${pullRequest.number}`);
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
return parents[0] ?? null;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Get the commit to compare the build against: the base commit merged into the
|
|
702
|
+
* test-merge commit when the build runs on one, else the merge base of the
|
|
703
|
+
* branch and its base branch.
|
|
704
|
+
*/
|
|
705
|
+
async function getMergeBaseCommitSha$1(input, ctx) {
|
|
706
|
+
const testMergeBase = await getTestMergeBaseCommitSha(input, ctx);
|
|
707
|
+
if (testMergeBase) {
|
|
708
|
+
debug("Found base commit from the test-merge commit", testMergeBase);
|
|
709
|
+
return testMergeBase;
|
|
710
|
+
}
|
|
711
|
+
return getMergeBaseCommitSha$2(input);
|
|
712
|
+
}
|
|
602
713
|
const service$4 = {
|
|
603
714
|
name: "GitHub Actions",
|
|
604
715
|
key: "github-actions",
|
|
@@ -682,7 +793,7 @@ const service$3 = {
|
|
|
682
793
|
nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null
|
|
683
794
|
};
|
|
684
795
|
},
|
|
685
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
796
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
686
797
|
listAncestorCommits: listAncestorCommits$1
|
|
687
798
|
};
|
|
688
799
|
//#endregion
|
|
@@ -721,7 +832,7 @@ const service$2 = {
|
|
|
721
832
|
nonce: env.TRAVIS_BUILD_ID || null
|
|
722
833
|
};
|
|
723
834
|
},
|
|
724
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
835
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
725
836
|
listAncestorCommits: listAncestorCommits$1
|
|
726
837
|
};
|
|
727
838
|
//#endregion
|
|
@@ -755,7 +866,7 @@ const service$1 = {
|
|
|
755
866
|
nonce: env.CI_PIPELINE_ID || null
|
|
756
867
|
};
|
|
757
868
|
},
|
|
758
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
869
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
759
870
|
listAncestorCommits: listAncestorCommits$1
|
|
760
871
|
};
|
|
761
872
|
//#endregion
|
|
@@ -795,7 +906,7 @@ const services = [
|
|
|
795
906
|
nonce: null
|
|
796
907
|
};
|
|
797
908
|
},
|
|
798
|
-
getMergeBaseCommitSha: getMergeBaseCommitSha$
|
|
909
|
+
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
799
910
|
listAncestorCommits: listAncestorCommits$1
|
|
800
911
|
}
|
|
801
912
|
];
|
|
@@ -2031,8 +2142,9 @@ async function findReferenceCommit(params) {
|
|
|
2031
2142
|
* Resolve the baseline for a build that has no remote content access (no Git
|
|
2032
2143
|
* provider connected).
|
|
2033
2144
|
*
|
|
2034
|
-
* 1. Find the
|
|
2035
|
-
*
|
|
2145
|
+
* 1. Find the base commit the build content is derived from — usually the merge
|
|
2146
|
+
* base, the closest common ancestor of the build branch and its base branch.
|
|
2147
|
+
* This is always the starting point.
|
|
2036
2148
|
* 2. From the merge base, ask the API to pick the closest commit (the merge base
|
|
2037
2149
|
* itself or one of its ancestors) that has an eligible baseline build, and use
|
|
2038
2150
|
* it as the reference commit.
|
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.8.
|
|
4
|
+
"version": "6.8.2",
|
|
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.31.0",
|
|
43
43
|
"@argos-ci/util": "4.1.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": "30a374b2c0f2b67b7a90fd4d22e395b70c191e0c"
|
|
72
72
|
}
|