@argos-ci/core 2.8.2 → 2.9.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.ts CHANGED
@@ -154,6 +154,7 @@ interface Config {
154
154
  runAttempt: number | null;
155
155
  prNumber: number | null;
156
156
  prHeadCommit: string | null;
157
+ prBaseBranch: string | null;
157
158
  mode: "ci" | "monitoring" | null;
158
159
  ciProvider: string | null;
159
160
  threshold: number | null;
package/dist/index.mjs CHANGED
@@ -56,7 +56,7 @@ function getMergeBaseCommitShaWithDepth(input) {
56
56
  }
57
57
  }
58
58
  function getMergeBaseCommitSha$1(input) {
59
- let depth = 50;
59
+ let depth = 200;
60
60
  while(depth < 1000){
61
61
  const mergeBase = getMergeBaseCommitShaWithDepth({
62
62
  depth,
@@ -65,10 +65,20 @@ function getMergeBaseCommitSha$1(input) {
65
65
  if (mergeBase) {
66
66
  return mergeBase;
67
67
  }
68
- depth += 50;
68
+ depth += 200;
69
69
  }
70
70
  return null;
71
71
  }
72
+ function listParentCommits$1(input) {
73
+ try {
74
+ execSync(`git fetch --depth=200 origin ${input.sha}`);
75
+ const raw = execSync(`git log --format="%H" --max-count=200 ${input.sha}`);
76
+ const shas = raw.toString().trim().split("\n");
77
+ return shas;
78
+ } catch {
79
+ return null;
80
+ }
81
+ }
72
82
 
73
83
  const getPrNumber$2 = ({ env })=>{
74
84
  return env.BITRISE_PULL_REQUEST ? Number(env.BITRISE_PULL_REQUEST) : null;
@@ -90,10 +100,12 @@ const service$7 = {
90
100
  env
91
101
  }),
92
102
  prHeadCommit: null,
103
+ prBaseBranch: null,
93
104
  nonce: env.BITRISEIO_PIPELINE_ID || null
94
105
  };
95
106
  },
96
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
107
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
108
+ listParentCommits: listParentCommits$1
97
109
  };
98
110
 
99
111
  const service$6 = {
@@ -112,10 +124,12 @@ const service$6 = {
112
124
  runAttempt: null,
113
125
  prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null,
114
126
  prHeadCommit: null,
127
+ prBaseBranch: null,
115
128
  nonce: env.BUILDKITE_BUILD_ID || null
116
129
  };
117
130
  },
118
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
131
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
132
+ listParentCommits: listParentCommits$1
119
133
  };
120
134
 
121
135
  const service$5 = {
@@ -132,9 +146,11 @@ const service$5 = {
132
146
  runAttempt: null,
133
147
  prNumber: null,
134
148
  prHeadCommit: null,
149
+ prBaseBranch: null,
135
150
  nonce: env.HEROKU_TEST_RUN_ID || null
136
151
  }),
137
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
152
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
153
+ listParentCommits: listParentCommits$1
138
154
  };
139
155
 
140
156
  const KEY = "@argos-ci/core";
@@ -262,17 +278,20 @@ const service$4 = {
262
278
  // Branch name is required to create a build but has no real impact on the build.
263
279
  branch: pullRequest?.head.ref || payload.deployment.environment || null,
264
280
  prNumber: pullRequest?.number || null,
265
- prHeadCommit: pullRequest?.head.sha || null
281
+ prHeadCommit: pullRequest?.head.sha || null,
282
+ prBaseBranch: null
266
283
  };
267
284
  }
268
285
  return {
269
286
  ...commonConfig,
270
287
  branch: payload?.pull_request?.head.ref || getBranch(context, payload) || null,
271
288
  prNumber: payload?.pull_request?.number || null,
272
- prHeadCommit: payload?.pull_request?.head.sha ?? null
289
+ prHeadCommit: payload?.pull_request?.head.sha ?? null,
290
+ prBaseBranch: payload?.pull_request?.base.ref ?? null
273
291
  };
274
292
  },
275
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
293
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
294
+ listParentCommits: listParentCommits$1
276
295
  };
277
296
 
278
297
  const getPrNumber$1 = ({ env })=>{
@@ -300,10 +319,12 @@ const service$3 = {
300
319
  env
301
320
  }),
302
321
  prHeadCommit: null,
322
+ prBaseBranch: null,
303
323
  nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null
304
324
  };
305
325
  },
306
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
326
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
327
+ listParentCommits: listParentCommits$1
307
328
  };
308
329
 
309
330
  const getOwner = ({ env })=>{
@@ -334,10 +355,12 @@ const service$2 = {
334
355
  runAttempt: null,
335
356
  prNumber: getPrNumber(ctx),
336
357
  prHeadCommit: null,
358
+ prBaseBranch: null,
337
359
  nonce: env.TRAVIS_BUILD_ID || null
338
360
  };
339
361
  },
340
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
362
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
363
+ listParentCommits: listParentCommits$1
341
364
  };
342
365
 
343
366
  const service$1 = {
@@ -355,10 +378,12 @@ const service$1 = {
355
378
  runAttempt: null,
356
379
  prNumber: null,
357
380
  prHeadCommit: null,
381
+ prBaseBranch: null,
358
382
  nonce: env.CI_PIPELINE_ID || null
359
383
  };
360
384
  },
361
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
385
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
386
+ listParentCommits: listParentCommits$1
362
387
  };
363
388
 
364
389
  const service = {
@@ -376,10 +401,12 @@ const service = {
376
401
  runAttempt: null,
377
402
  prNumber: null,
378
403
  prHeadCommit: null,
404
+ prBaseBranch: null,
379
405
  nonce: null
380
406
  };
381
407
  },
382
- getMergeBaseCommitSha: getMergeBaseCommitSha$1
408
+ getMergeBaseCommitSha: getMergeBaseCommitSha$1,
409
+ listParentCommits: listParentCommits$1
383
410
  };
384
411
 
385
412
  // List of services ordered by usage
@@ -416,6 +443,16 @@ const services = [
416
443
  }
417
444
  return service.getMergeBaseCommitSha(input, context);
418
445
  }
446
+ /**
447
+ * Get the merge base commit.
448
+ */ function listParentCommits(input) {
449
+ const context = createContext();
450
+ const service = getCiService(context);
451
+ if (!service) {
452
+ return null;
453
+ }
454
+ return service.listParentCommits(input, context);
455
+ }
419
456
  /**
420
457
  * Get the CI environment.
421
458
  */ async function getCiEnvironment() {
@@ -517,6 +554,12 @@ const schema = {
517
554
  default: null,
518
555
  nullable: true
519
556
  },
557
+ prBaseBranch: {
558
+ env: "ARGOS_PR_BASE_BRANCH",
559
+ format: String,
560
+ default: null,
561
+ nullable: true
562
+ },
520
563
  parallel: {
521
564
  env: "ARGOS_PARALLEL",
522
565
  default: false,
@@ -605,6 +648,7 @@ async function readConfig(options = {}) {
605
648
  buildName: options.buildName || config.get("buildName") || null,
606
649
  prNumber: options.prNumber || config.get("prNumber") || ciEnv?.prNumber || null,
607
650
  prHeadCommit: config.get("prHeadCommit") || ciEnv?.prHeadCommit || null,
651
+ prBaseBranch: config.get("prBaseBranch") || ciEnv?.prBaseBranch || null,
608
652
  referenceBranch: options.referenceBranch || config.get("referenceBranch") || null,
609
653
  referenceCommit: options.referenceCommit || config.get("referenceCommit") || null,
610
654
  owner: ciEnv?.owner || null,
@@ -824,27 +868,49 @@ async function uploadFilesToS3(files) {
824
868
  if (projectResponse.error) {
825
869
  throwAPIError(projectResponse.error);
826
870
  }
871
+ debug("Project fetched", projectResponse.data);
827
872
  const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
828
- const referenceBranch = config.referenceBranch || defaultBaseBranch;
829
873
  const referenceCommit = (()=>{
830
874
  if (config.referenceCommit) {
831
875
  debug("Found reference commit in config", config.referenceCommit);
832
876
  return config.referenceCommit;
833
877
  }
878
+ // If we have remote access, we will fetch it from the Git Provider.
834
879
  if (hasRemoteContentAccess) {
835
880
  return null;
836
881
  }
882
+ // We use the pull request as base branch if possible
883
+ // else branch specified by the user or the default branch.
884
+ const base = config.referenceBranch || config.prBaseBranch || defaultBaseBranch;
837
885
  const sha = getMergeBaseCommitSha({
838
- base: referenceBranch,
886
+ base,
839
887
  head: config.branch
840
888
  });
841
889
  if (sha) {
842
- debug("Found reference commit from git", sha);
890
+ debug("Found merge base", sha);
843
891
  } else {
844
- debug("No reference commit found in git");
892
+ debug("No merge base found");
845
893
  }
846
894
  return sha;
847
895
  })();
896
+ const parentCommits = (()=>{
897
+ // If we have remote access, we will fetch them from the Git Provider.
898
+ if (hasRemoteContentAccess) {
899
+ return null;
900
+ }
901
+ if (referenceCommit) {
902
+ const commits = listParentCommits({
903
+ sha: referenceCommit
904
+ });
905
+ if (commits) {
906
+ debug("Found parent commits", commits);
907
+ } else {
908
+ debug("No parent commits found");
909
+ }
910
+ return commits;
911
+ }
912
+ return null;
913
+ })();
848
914
  // Create build
849
915
  debug("Creating build");
850
916
  const [pwTraceKeys, screenshotKeys] = screenshots.reduce(([pwTraceKeys, screenshotKeys], screenshot)=>{
@@ -874,8 +940,9 @@ async function uploadFilesToS3(files) {
874
940
  pwTraceKeys,
875
941
  prNumber: config.prNumber,
876
942
  prHeadCommit: config.prHeadCommit,
877
- referenceBranch,
943
+ referenceBranch: config.referenceBranch,
878
944
  referenceCommit,
945
+ parentCommits,
879
946
  argosSdk,
880
947
  ciProvider: config.ciProvider,
881
948
  runId: config.runId,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@argos-ci/core",
3
3
  "description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
4
- "version": "2.8.2",
4
+ "version": "2.9.1",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "types": "./dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/api-client": "0.5.1",
43
+ "@argos-ci/api-client": "0.6.1",
44
44
  "@argos-ci/util": "2.1.1",
45
45
  "axios": "^1.7.4",
46
46
  "convict": "^6.2.4",
@@ -60,5 +60,5 @@
60
60
  "build": "rollup -c",
61
61
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
62
62
  },
63
- "gitHead": "0e6df5391e875daba1da61fac33ca1c215db4bc2"
63
+ "gitHead": "db599c8bc3021cb18315f4e39717f9c2990e7847"
64
64
  }