@argos-ci/core 2.2.0 → 2.3.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.d.ts CHANGED
@@ -25,6 +25,8 @@ interface UploadParameters {
25
25
  nonce: string;
26
26
  /** The number of parallel nodes being ran */
27
27
  total: number;
28
+ /** The index of the parallel node */
29
+ index?: number;
28
30
  } | false;
29
31
  /** Branch used as baseline for screenshot comparison */
30
32
  referenceBranch?: string;
@@ -59,6 +61,7 @@ interface Config {
59
61
  buildName: string | null;
60
62
  parallel: boolean;
61
63
  parallelNonce: string | null;
64
+ parallelIndex: number | null;
62
65
  parallelTotal: number | null;
63
66
  referenceBranch: string | null;
64
67
  referenceCommit: string | null;
@@ -66,9 +69,11 @@ interface Config {
66
69
  repository: string | null;
67
70
  jobId: string | null;
68
71
  runId: string | null;
72
+ runAttempt: number | null;
69
73
  prNumber: number | null;
70
74
  prHeadCommit: string | null;
71
75
  mode: "ci" | "monitoring" | null;
76
+ ciProvider: string | null;
72
77
  }
73
78
  declare function readConfig(options?: Partial<Config>): Promise<Config>;
74
79
  export { UploadParameters, upload, Config, readConfig };
package/dist/index.mjs CHANGED
@@ -10,13 +10,15 @@ import sharp from 'sharp';
10
10
  import tmp from 'tmp';
11
11
  import { createHash } from 'node:crypto';
12
12
  import { readFile } from 'node:fs/promises';
13
- import { readMetadata, getPlaywrightTracePath } from '@argos-ci/util';
13
+ import { readVersionFromPackage, readMetadata, getPlaywrightTracePath } from '@argos-ci/util';
14
+ import { createRequire } from 'node:module';
14
15
 
15
16
  const getPrNumber$2 = ({ env })=>{
16
17
  return env.BITRISE_PULL_REQUEST ? Number(env.BITRISE_PULL_REQUEST) : null;
17
18
  };
18
19
  const service$7 = {
19
20
  name: "Bitrise",
21
+ key: "bitrise",
20
22
  detect: ({ env })=>Boolean(env.BITRISE_IO),
21
23
  config: ({ env })=>{
22
24
  return {
@@ -26,6 +28,7 @@ const service$7 = {
26
28
  repository: env.BITRISEIO_GIT_REPOSITORY_SLUG || null,
27
29
  jobId: null,
28
30
  runId: null,
31
+ runAttempt: null,
29
32
  prNumber: getPrNumber$2({
30
33
  env
31
34
  }),
@@ -69,6 +72,7 @@ const service$7 = {
69
72
 
70
73
  const service$6 = {
71
74
  name: "Buildkite",
75
+ key: "buildkite",
72
76
  detect: ({ env })=>Boolean(env.BUILDKITE),
73
77
  config: ({ env })=>{
74
78
  return {
@@ -79,6 +83,7 @@ const service$6 = {
79
83
  repository: env.BUILDKITE_PROJECT_SLUG || null,
80
84
  jobId: null,
81
85
  runId: null,
86
+ runAttempt: null,
82
87
  prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null,
83
88
  prHeadCommit: null,
84
89
  nonce: env.BUILDKITE_BUILD_ID || null
@@ -88,6 +93,7 @@ const service$6 = {
88
93
 
89
94
  const service$5 = {
90
95
  name: "Heroku",
96
+ key: "heroku",
91
97
  detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
92
98
  config: ({ env })=>({
93
99
  commit: env.HEROKU_TEST_RUN_COMMIT_VERSION || null,
@@ -96,6 +102,7 @@ const service$5 = {
96
102
  repository: null,
97
103
  jobId: null,
98
104
  runId: null,
105
+ runAttempt: null,
99
106
  prNumber: null,
100
107
  prHeadCommit: null,
101
108
  nonce: env.HEROKU_TEST_RUN_ID || null
@@ -194,6 +201,7 @@ const readEventPayload = ({ env })=>{
194
201
  };
195
202
  const service$4 = {
196
203
  name: "GitHub Actions",
204
+ key: "github-actions",
197
205
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
198
206
  config: async ({ env })=>{
199
207
  const payload = readEventPayload({
@@ -211,6 +219,7 @@ const service$4 = {
211
219
  }),
212
220
  jobId: env.GITHUB_JOB || null,
213
221
  runId: env.GITHUB_RUN_ID || null,
222
+ runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null,
214
223
  nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null
215
224
  };
216
225
  // If the job is triggered by from a "deployment" or a "deployment_status"
@@ -250,6 +259,7 @@ const getPrNumber$1 = ({ env })=>{
250
259
  };
251
260
  const service$3 = {
252
261
  name: "CircleCI",
262
+ key: "circleci",
253
263
  detect: ({ env })=>Boolean(env.CIRCLECI),
254
264
  config: ({ env })=>{
255
265
  return {
@@ -259,6 +269,7 @@ const service$3 = {
259
269
  repository: env.CIRCLE_PROJECT_REPONAME || null,
260
270
  jobId: null,
261
271
  runId: null,
272
+ runAttempt: null,
262
273
  prNumber: getPrNumber$1({
263
274
  env
264
275
  }),
@@ -282,6 +293,7 @@ const getPrNumber = ({ env })=>{
282
293
  };
283
294
  const service$2 = {
284
295
  name: "Travis CI",
296
+ key: "travis",
285
297
  detect: ({ env })=>Boolean(env.TRAVIS),
286
298
  config: (ctx)=>{
287
299
  const { env } = ctx;
@@ -292,6 +304,7 @@ const service$2 = {
292
304
  repository: getRepository(ctx),
293
305
  jobId: null,
294
306
  runId: null,
307
+ runAttempt: null,
295
308
  prNumber: getPrNumber(ctx),
296
309
  prHeadCommit: null,
297
310
  nonce: env.TRAVIS_BUILD_ID || null
@@ -301,6 +314,7 @@ const service$2 = {
301
314
 
302
315
  const service$1 = {
303
316
  name: "GitLab",
317
+ key: "gitlab",
304
318
  detect: ({ env })=>env.GITLAB_CI === "true",
305
319
  config: ({ env })=>{
306
320
  return {
@@ -310,6 +324,7 @@ const service$1 = {
310
324
  repository: null,
311
325
  jobId: null,
312
326
  runId: null,
327
+ runAttempt: null,
313
328
  prNumber: null,
314
329
  prHeadCommit: null,
315
330
  nonce: env.CI_PIPELINE_ID || null
@@ -319,6 +334,7 @@ const service$1 = {
319
334
 
320
335
  const service = {
321
336
  name: "Git",
337
+ key: "git",
322
338
  detect: ()=>checkIsGitRepository(),
323
339
  config: ()=>{
324
340
  return {
@@ -328,6 +344,7 @@ const service = {
328
344
  repository: null,
329
345
  jobId: null,
330
346
  runId: null,
347
+ runAttempt: null,
331
348
  prNumber: null,
332
349
  prHeadCommit: null,
333
350
  nonce: null
@@ -361,6 +378,7 @@ async function getCiEnvironment({ env = process.env } = {}) {
361
378
  const variables = await service.config(ctx);
362
379
  const ciEnvironment = {
363
380
  name: service.name,
381
+ key: service.key,
364
382
  ...variables
365
383
  };
366
384
  debug("CI environment", ciEnvironment);
@@ -449,6 +467,12 @@ const schema = {
449
467
  default: null,
450
468
  nullable: true
451
469
  },
470
+ parallelIndex: {
471
+ env: "ARGOS_PARALLEL_INDEX",
472
+ format: "nat",
473
+ default: null,
474
+ nullable: true
475
+ },
452
476
  parallelTotal: {
453
477
  env: "ARGOS_PARALLEL_TOTAL",
454
478
  format: "nat",
@@ -467,18 +491,18 @@ const schema = {
467
491
  default: null,
468
492
  nullable: true
469
493
  },
470
- ciService: {
494
+ jobId: {
471
495
  format: String,
472
496
  default: null,
473
497
  nullable: true
474
498
  },
475
- jobId: {
499
+ runId: {
476
500
  format: String,
477
501
  default: null,
478
502
  nullable: true
479
503
  },
480
- runId: {
481
- format: String,
504
+ runAttempt: {
505
+ format: "nat",
482
506
  default: null,
483
507
  nullable: true
484
508
  },
@@ -491,6 +515,11 @@ const schema = {
491
515
  format: String,
492
516
  default: null,
493
517
  nullable: true
518
+ },
519
+ ciProvider: {
520
+ format: String,
521
+ default: null,
522
+ nullable: true
494
523
  }
495
524
  };
496
525
  const createConfig = ()=>{
@@ -511,15 +540,17 @@ async function readConfig(options = {}) {
511
540
  prHeadCommit: config.get("prHeadCommit") || ciEnv?.prHeadCommit || null,
512
541
  referenceBranch: options.referenceBranch || config.get("referenceBranch") || null,
513
542
  referenceCommit: options.referenceCommit || config.get("referenceCommit") || null,
514
- ciService: ciEnv?.name || null,
515
543
  owner: ciEnv?.owner || null,
516
544
  repository: ciEnv?.repository || null,
517
545
  jobId: ciEnv?.jobId || null,
518
546
  runId: ciEnv?.runId || null,
547
+ runAttempt: ciEnv?.runAttempt || null,
519
548
  parallel: options.parallel ?? config.get("parallel") ?? false,
520
549
  parallelNonce: options.parallelNonce || config.get("parallelNonce") || ciEnv?.nonce || null,
521
550
  parallelTotal: options.parallelTotal || config.get("parallelTotal") || null,
522
- mode: options.mode || config.get("mode") || null
551
+ parallelIndex: options.parallelIndex || config.get("parallelIndex") || null,
552
+ mode: options.mode || config.get("mode") || null,
553
+ ciProvider: ciEnv?.key || null
523
554
  });
524
555
  config.validate();
525
556
  return config.get();
@@ -574,13 +605,13 @@ const hashFile = async (filepath)=>{
574
605
  };
575
606
 
576
607
  const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
577
- const getBearerToken = ({ token, ciService, owner, repository, jobId, runId, prNumber })=>{
608
+ function getBearerToken({ token, ciProvider, owner, repository, jobId, runId, prNumber }) {
578
609
  if (token) return `Bearer ${token}`;
579
- switch(ciService){
580
- case "GitHub Actions":
610
+ switch(ciProvider){
611
+ case "github-actions":
581
612
  {
582
613
  if (!owner || !repository || !jobId || !runId) {
583
- throw new Error(`Automatic ${ciService} variables detection failed. Please add the 'ARGOS_TOKEN'`);
614
+ throw new Error(`Automatic GitHub Actions variables detection failed. Please add the 'ARGOS_TOKEN'`);
584
615
  }
585
616
  return `Bearer tokenless-github-${base64Encode({
586
617
  owner,
@@ -593,7 +624,7 @@ const getBearerToken = ({ token, ciService, owner, repository, jobId, runId, prN
593
624
  default:
594
625
  throw new Error("Missing Argos repository token 'ARGOS_TOKEN'");
595
626
  }
596
- };
627
+ }
597
628
  const createArgosApiClient = (options)=>{
598
629
  const axiosInstance = axios.create({
599
630
  baseURL: options.baseUrl,
@@ -666,6 +697,15 @@ const upload$1 = async (input)=>{
666
697
  return result;
667
698
  };
668
699
 
700
+ const require = createRequire(import.meta.url);
701
+ /**
702
+ * Get the version of the @argos-ci/core package.
703
+ */ async function getArgosCoreSDKIdentifier() {
704
+ const pkgPath = require.resolve("@argos-ci/core/package.json");
705
+ const version = await readVersionFromPackage(pkgPath);
706
+ return `@argos-ci/core@${version}`;
707
+ }
708
+
669
709
  /**
670
710
  * Size of the chunks used to upload screenshots to Argos.
671
711
  */ const CHUNK_SIZE = 10;
@@ -674,7 +714,8 @@ async function getConfigFromOptions({ parallel, ...options }) {
674
714
  ...options,
675
715
  parallel: Boolean(parallel),
676
716
  parallelNonce: parallel ? parallel.nonce : null,
677
- parallelTotal: parallel ? parallel.total : null
717
+ parallelTotal: parallel ? parallel.total : null,
718
+ parallelIndex: parallel ? parallel.index : null
678
719
  });
679
720
  }
680
721
  async function uploadFilesToS3(files) {
@@ -705,7 +746,10 @@ async function uploadFilesToS3(files) {
705
746
  */ async function upload(params) {
706
747
  debug("Starting upload with params", params);
707
748
  // Read config
708
- const config = await getConfigFromOptions(params);
749
+ const [config, argosSdk] = await Promise.all([
750
+ getConfigFromOptions(params),
751
+ getArgosCoreSDKIdentifier()
752
+ ]);
709
753
  const files = params.files ?? [
710
754
  "**/*.{png,jpg,jpeg}"
711
755
  ];
@@ -771,7 +815,11 @@ async function uploadFilesToS3(files) {
771
815
  prNumber: config.prNumber,
772
816
  prHeadCommit: config.prHeadCommit,
773
817
  referenceBranch: config.referenceBranch,
774
- referenceCommit: config.referenceCommit
818
+ referenceCommit: config.referenceCommit,
819
+ argosSdk,
820
+ ciProvider: config.ciProvider,
821
+ runId: config.runId,
822
+ runAttempt: config.runAttempt
775
823
  });
776
824
  debug("Got uploads url", result);
777
825
  const uploadFiles = [
@@ -810,7 +858,8 @@ async function uploadFilesToS3(files) {
810
858
  pwTraceKey: screenshot.pwTrace?.hash ?? null
811
859
  })),
812
860
  parallel: config.parallel,
813
- parallelTotal: config.parallelTotal
861
+ parallelTotal: config.parallelTotal,
862
+ parallelIndex: config.parallelIndex
814
863
  });
815
864
  return {
816
865
  build: result.build,
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.2.0",
4
+ "version": "2.3.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "types": "./dist/index.d.ts",
@@ -59,5 +59,5 @@
59
59
  "build": "rollup -c",
60
60
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
61
61
  },
62
- "gitHead": "5b18339a0b9e3a1e7529dfa999ed91227842c43c"
62
+ "gitHead": "0c328bfcd6475ad625c0335cab11e912e856173c"
63
63
  }