@argos-ci/core 0.11.1 → 0.12.1-alpha.4

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
@@ -24,6 +24,10 @@ interface UploadParameters {
24
24
  /** The number of parallel nodes being ran */
25
25
  total: number;
26
26
  } | false;
27
+ /** Branch used as baseline for screenshot comparison */
28
+ referenceBranch?: string;
29
+ /** Commit used as baseline for screenshot comparison */
30
+ referenceCommit?: string;
27
31
  }
28
32
  /**
29
33
  * Upload screenshots to argos-ci.com.
@@ -34,11 +38,11 @@ declare const upload: (params: UploadParameters) => Promise<{
34
38
  url: string;
35
39
  };
36
40
  screenshots: {
41
+ metadata: import("@argos-ci/util").ScreenshotMetadata | null;
37
42
  optimizedPath: string;
38
43
  hash: string;
39
44
  name: string;
40
45
  path: string;
41
46
  }[];
42
47
  }>;
43
-
44
- export { type UploadParameters, upload };
48
+ export { UploadParameters, upload };
package/dist/index.mjs CHANGED
@@ -11,6 +11,7 @@ import tmp from 'tmp';
11
11
  import { createHash } from 'node:crypto';
12
12
  import axios from 'axios';
13
13
  import { readFile } from 'node:fs/promises';
14
+ import { readMetadata } from '@argos-ci/util';
14
15
 
15
16
  const mustBeApiBaseUrl = (value)=>{
16
17
  const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
@@ -89,6 +90,18 @@ const schema = {
89
90
  default: null,
90
91
  nullable: true
91
92
  },
93
+ referenceBranch: {
94
+ env: "ARGOS_REFERENCE_BRANCH",
95
+ format: String,
96
+ default: null,
97
+ nullable: true
98
+ },
99
+ referenceCommit: {
100
+ env: "ARGOS_REFERENCE_COMMIT",
101
+ format: String,
102
+ default: null,
103
+ nullable: true
104
+ },
92
105
  ciService: {
93
106
  format: String,
94
107
  default: null,
@@ -201,12 +214,13 @@ const service$3 = {
201
214
  name: "GitHub Actions",
202
215
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
203
216
  config: ({ env })=>{
217
+ var _payload_pull_request, _payload_pull_request1, _payload_pull_request2;
204
218
  const payload = readEventPayload({
205
219
  env
206
220
  });
207
221
  return {
208
222
  commit: process.env.GITHUB_SHA || null,
209
- branch: payload?.pull_request?.head.ref || getBranch({
223
+ branch: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request = payload.pull_request) === null || _payload_pull_request === void 0 ? void 0 : _payload_pull_request.head.ref) || getBranch({
210
224
  env
211
225
  }) || null,
212
226
  owner: env.GITHUB_REPOSITORY_OWNER || null,
@@ -215,8 +229,8 @@ const service$3 = {
215
229
  }),
216
230
  jobId: env.GITHUB_JOB || null,
217
231
  runId: env.GITHUB_RUN_ID || null,
218
- prNumber: payload?.pull_request?.number || null,
219
- prHeadCommit: payload?.pull_request?.head.sha ?? null
232
+ prNumber: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request1 = payload.pull_request) === null || _payload_pull_request1 === void 0 ? void 0 : _payload_pull_request1.number) || null,
233
+ prHeadCommit: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request2 = payload.pull_request) === null || _payload_pull_request2 === void 0 ? void 0 : _payload_pull_request2.head.sha) ?? null
220
234
  };
221
235
  }
222
236
  };
@@ -375,10 +389,13 @@ const discoverScreenshots = async (patterns, { root = process.cwd(), ignore } =
375
389
  ignore,
376
390
  cwd: root
377
391
  });
378
- return matches.map((match)=>({
392
+ return matches.map((match)=>{
393
+ const path = resolve(root, match);
394
+ return {
379
395
  name: match,
380
- path: resolve(root, match)
381
- }));
396
+ path
397
+ };
398
+ });
382
399
  };
383
400
 
384
401
  const tmpFile = promisify(tmp.file);
@@ -453,7 +470,8 @@ const createArgosApiClient = (options)=>{
453
470
  });
454
471
  return response.data;
455
472
  } catch (error) {
456
- if (error?.response?.data?.error?.message) {
473
+ var _error_response_data_error, _error_response_data, _error_response;
474
+ if (error === null || error === void 0 ? void 0 : (_error_response = error.response) === null || _error_response === void 0 ? void 0 : (_error_response_data = _error_response.data) === null || _error_response_data === void 0 ? void 0 : (_error_response_data_error = _error_response_data.error) === null || _error_response_data_error === void 0 ? void 0 : _error_response_data_error.message) {
457
475
  // @ts-ignore
458
476
  throw new Error(error.response.data.error.message, {
459
477
  cause: error
@@ -506,17 +524,19 @@ const getConfigFromOptions = (options)=>{
506
524
  const ciEnv = getCiEnvironment();
507
525
  config.load({
508
526
  apiBaseUrl: options.apiBaseUrl ?? config.get("apiBaseUrl"),
509
- commit: options.commit ?? config.get("commit") ?? ciEnv?.commit ?? null,
510
- branch: options.branch ?? config.get("branch") ?? ciEnv?.branch ?? null,
527
+ commit: options.commit ?? config.get("commit") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.commit) ?? null,
528
+ branch: options.branch ?? config.get("branch") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.branch) ?? null,
511
529
  token: options.token ?? config.get("token") ?? null,
512
530
  buildName: options.buildName ?? config.get("buildName") ?? null,
513
- prNumber: options.prNumber ?? config.get("prNumber") ?? ciEnv?.prNumber ?? null,
514
- prHeadCommit: config.get("prHeadCommit") ?? ciEnv?.prHeadCommit ?? null,
515
- ciService: ciEnv?.name ?? null,
516
- owner: ciEnv?.owner ?? null,
517
- repository: ciEnv?.repository ?? null,
518
- jobId: ciEnv?.jobId ?? null,
519
- runId: ciEnv?.runId ?? null
531
+ prNumber: options.prNumber ?? config.get("prNumber") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prNumber) ?? null,
532
+ prHeadCommit: config.get("prHeadCommit") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prHeadCommit) ?? null,
533
+ referenceBranch: options.referenceBranch ?? config.get("referenceBranch") ?? null,
534
+ referenceCommit: options.referenceCommit ?? config.get("referenceCommit") ?? null,
535
+ ciService: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.name) ?? null,
536
+ owner: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.owner) ?? null,
537
+ repository: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.repository) ?? null,
538
+ jobId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.jobId) ?? null,
539
+ runId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.runId) ?? null
520
540
  });
521
541
  if (options.parallel) {
522
542
  config.load({
@@ -550,10 +570,14 @@ const getConfigFromOptions = (options)=>{
550
570
  debug("Found screenshots", foundScreenshots);
551
571
  // Optimize & compute hashes
552
572
  const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
553
- const optimizedPath = await optimizeScreenshot(screenshot.path);
573
+ const [metadata, optimizedPath] = await Promise.all([
574
+ readMetadata(screenshot.path),
575
+ optimizeScreenshot(screenshot.path)
576
+ ]);
554
577
  const hash = await hashFile(optimizedPath);
555
578
  return {
556
579
  ...screenshot,
580
+ metadata,
557
581
  optimizedPath,
558
582
  hash
559
583
  };
@@ -568,7 +592,9 @@ const getConfigFromOptions = (options)=>{
568
592
  parallelNonce: config.parallelNonce,
569
593
  screenshotKeys: Array.from(new Set(screenshots.map((screenshot)=>screenshot.hash))),
570
594
  prNumber: config.prNumber,
571
- prHeadCommit: config.prHeadCommit
595
+ prHeadCommit: config.prHeadCommit,
596
+ referenceBranch: config.referenceBranch,
597
+ referenceCommit: config.referenceCommit
572
598
  });
573
599
  debug("Got screenshots", result);
574
600
  debug(`Split screenshots in chunks of ${CHUNK_SIZE}`);
@@ -596,7 +622,8 @@ const getConfigFromOptions = (options)=>{
596
622
  buildId: result.build.id,
597
623
  screenshots: screenshots.map((screenshot)=>({
598
624
  key: screenshot.hash,
599
- name: screenshot.name
625
+ name: screenshot.name,
626
+ metadata: screenshot.metadata
600
627
  })),
601
628
  parallel: config.parallel,
602
629
  parallelTotal: config.parallelTotal
package/package.json CHANGED
@@ -1,12 +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": "0.11.1",
5
- "scripts": {
6
- "prebuild": "rm -rf dist",
7
- "build": "rollup -c",
8
- "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
9
- },
4
+ "version": "0.12.1-alpha.4+8a2e9db",
10
5
  "type": "module",
11
6
  "main": "./dist/index.cjs",
12
7
  "types": "./dist/index.d.ts",
@@ -45,6 +40,7 @@
45
40
  "access": "public"
46
41
  },
47
42
  "dependencies": {
43
+ "@argos-ci/util": "0.0.1-alpha.182+8a2e9db",
48
44
  "axios": "^1.5.0",
49
45
  "convict": "^6.2.4",
50
46
  "debug": "^4.3.4",
@@ -55,11 +51,14 @@
55
51
  },
56
52
  "devDependencies": {
57
53
  "@types/convict": "^6.1.4",
54
+ "@types/debug": "^4.1.9",
58
55
  "@types/tmp": "^0.2.3",
59
- "msw": "^1.3.0",
60
- "rollup": "^3.29.0",
61
- "rollup-plugin-dts": "^6.0.1",
62
- "rollup-plugin-swc3": "^0.10.1"
56
+ "msw": "^1.3.0"
57
+ },
58
+ "scripts": {
59
+ "prebuild": "rm -rf dist",
60
+ "build": "rollup -c",
61
+ "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
63
62
  },
64
- "gitHead": "8e3c44d658f3abd5ce3ac1bc829e2754974a2125"
63
+ "gitHead": "8a2e9db6427071708c3d701a3230f228b1216893"
65
64
  }