@argos-ci/core 6.8.1 → 6.8.3

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 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. Defaults to the most private option the plan allows.
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$1(input) {
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$1,
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.BUILDKITE_COMMIT || head() || null,
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$1,
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$1,
433
+ getMergeBaseCommitSha: getMergeBaseCommitSha$2,
374
434
  listAncestorCommits: listAncestorCommits$1
375
435
  };
376
436
  //#endregion
@@ -599,6 +659,62 @@ 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) {
695
+ debug(`${sha} is not a merge commit, ignoring the test-merge commit`);
696
+ return null;
697
+ }
698
+ if (ctx.env.GITHUB_REF === `refs/pull/${pullRequest.number}/merge`) return parents[0] ?? null;
699
+ if (parents[1] !== pullRequest.head.sha) {
700
+ debug(`${sha} is not a test-merge commit of #${pullRequest.number}`);
701
+ return null;
702
+ }
703
+ return parents[0] ?? null;
704
+ }
705
+ /**
706
+ * Get the commit to compare the build against: the base commit merged into the
707
+ * test-merge commit when the build runs on one, else the merge base of the
708
+ * branch and its base branch.
709
+ */
710
+ async function getMergeBaseCommitSha$1(input, ctx) {
711
+ const testMergeBase = await getTestMergeBaseCommitSha(input, ctx);
712
+ if (testMergeBase) {
713
+ debug("Found base commit from the test-merge commit", testMergeBase);
714
+ return testMergeBase;
715
+ }
716
+ return getMergeBaseCommitSha$2(input);
717
+ }
602
718
  const service$4 = {
603
719
  name: "GitHub Actions",
604
720
  key: "github-actions",
@@ -682,7 +798,7 @@ const service$3 = {
682
798
  nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null
683
799
  };
684
800
  },
685
- getMergeBaseCommitSha: getMergeBaseCommitSha$1,
801
+ getMergeBaseCommitSha: getMergeBaseCommitSha$2,
686
802
  listAncestorCommits: listAncestorCommits$1
687
803
  };
688
804
  //#endregion
@@ -721,7 +837,7 @@ const service$2 = {
721
837
  nonce: env.TRAVIS_BUILD_ID || null
722
838
  };
723
839
  },
724
- getMergeBaseCommitSha: getMergeBaseCommitSha$1,
840
+ getMergeBaseCommitSha: getMergeBaseCommitSha$2,
725
841
  listAncestorCommits: listAncestorCommits$1
726
842
  };
727
843
  //#endregion
@@ -755,7 +871,7 @@ const service$1 = {
755
871
  nonce: env.CI_PIPELINE_ID || null
756
872
  };
757
873
  },
758
- getMergeBaseCommitSha: getMergeBaseCommitSha$1,
874
+ getMergeBaseCommitSha: getMergeBaseCommitSha$2,
759
875
  listAncestorCommits: listAncestorCommits$1
760
876
  };
761
877
  //#endregion
@@ -795,7 +911,7 @@ const services = [
795
911
  nonce: null
796
912
  };
797
913
  },
798
- getMergeBaseCommitSha: getMergeBaseCommitSha$1,
914
+ getMergeBaseCommitSha: getMergeBaseCommitSha$2,
799
915
  listAncestorCommits: listAncestorCommits$1
800
916
  }
801
917
  ];
@@ -2031,8 +2147,9 @@ async function findReferenceCommit(params) {
2031
2147
  * Resolve the baseline for a build that has no remote content access (no Git
2032
2148
  * provider connected).
2033
2149
  *
2034
- * 1. Find the merge base — the closest common ancestor of the build branch and
2035
- * its base branch. This is always the starting point.
2150
+ * 1. Find the base commit the build content is derived from — usually the merge
2151
+ * base, the closest common ancestor of the build branch and its base branch.
2152
+ * This is always the starting point.
2036
2153
  * 2. From the merge base, ask the API to pick the closest commit (the merge base
2037
2154
  * itself or one of its ancestors) that has an eligible baseline build, and use
2038
2155
  * 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.1",
4
+ "version": "6.8.3",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@argos-ci/api-client": "0.31.0",
43
- "@argos-ci/util": "4.1.0",
43
+ "@argos-ci/util": "4.2.0",
44
44
  "convict": "^6.2.5",
45
45
  "debug": "^4.4.3",
46
46
  "fast-glob": "^3.3.3",
@@ -68,5 +68,5 @@
68
68
  "lint": "eslint .",
69
69
  "test": "vitest"
70
70
  },
71
- "gitHead": "180580eb5a263a65ed15cbd18cdd98d39f3a5325"
71
+ "gitHead": "b2a9a9d84dc14e148a68295f56cfdfec03f887f1"
72
72
  }