@argos-ci/core 0.12.0 → 0.12.1-alpha.7

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
@@ -38,11 +38,11 @@ declare const upload: (params: UploadParameters) => Promise<{
38
38
  url: string;
39
39
  };
40
40
  screenshots: {
41
+ metadata: import("@argos-ci/util").ScreenshotMetadata | null;
41
42
  optimizedPath: string;
42
43
  hash: string;
43
44
  name: string;
44
45
  path: string;
45
46
  }[];
46
47
  }>;
47
-
48
- export { type UploadParameters, upload };
48
+ export { UploadParameters, upload };
package/dist/index.mjs CHANGED
@@ -2,7 +2,6 @@ import convict from 'convict';
2
2
  import { execSync } from 'node:child_process';
3
3
  import { existsSync, readFileSync, createReadStream } from 'node:fs';
4
4
  import createDebug from 'debug';
5
- import envCi from 'env-ci';
6
5
  import { resolve } from 'node:path';
7
6
  import glob from 'fast-glob';
8
7
  import { promisify } from 'node:util';
@@ -11,6 +10,7 @@ import tmp from 'tmp';
11
10
  import { createHash } from 'node:crypto';
12
11
  import axios from 'axios';
13
12
  import { readFile } from 'node:fs/promises';
13
+ import { readMetadata } from '@argos-ci/util';
14
14
 
15
15
  const mustBeApiBaseUrl = (value)=>{
16
16
  const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
@@ -133,6 +133,15 @@ const createConfig = ()=>{
133
133
  });
134
134
  };
135
135
 
136
+ /**
137
+ * Check if the current directory is a git repository.
138
+ */ const checkIsGitRepository = ()=>{
139
+ try {
140
+ return execSync("git rev-parse --is-inside-work-tree").toString().trim() === "true";
141
+ } catch {
142
+ return false;
143
+ }
144
+ };
136
145
  /**
137
146
  * Returns the head commit.
138
147
  */ const head = ()=>{
@@ -156,7 +165,7 @@ const createConfig = ()=>{
156
165
  }
157
166
  };
158
167
 
159
- const service$5 = {
168
+ const service$6 = {
160
169
  name: "Buildkite",
161
170
  detect: ({ env })=>Boolean(env.BUILDKITE),
162
171
  config: ({ env })=>{
@@ -174,7 +183,7 @@ const service$5 = {
174
183
  }
175
184
  };
176
185
 
177
- const service$4 = {
186
+ const service$5 = {
178
187
  name: "Heroku",
179
188
  detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
180
189
  config: ({ env })=>({
@@ -209,16 +218,17 @@ const readEventPayload = ({ env })=>{
209
218
  if (!existsSync(env.GITHUB_EVENT_PATH)) return null;
210
219
  return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf-8"));
211
220
  };
212
- const service$3 = {
221
+ const service$4 = {
213
222
  name: "GitHub Actions",
214
223
  detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
215
224
  config: ({ env })=>{
225
+ var _payload_pull_request, _payload_pull_request1, _payload_pull_request2;
216
226
  const payload = readEventPayload({
217
227
  env
218
228
  });
219
229
  return {
220
230
  commit: process.env.GITHUB_SHA || null,
221
- branch: payload?.pull_request?.head.ref || getBranch({
231
+ 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({
222
232
  env
223
233
  }) || null,
224
234
  owner: env.GITHUB_REPOSITORY_OWNER || null,
@@ -227,8 +237,8 @@ const service$3 = {
227
237
  }),
228
238
  jobId: env.GITHUB_JOB || null,
229
239
  runId: env.GITHUB_RUN_ID || null,
230
- prNumber: payload?.pull_request?.number || null,
231
- prHeadCommit: payload?.pull_request?.head.sha ?? null
240
+ 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,
241
+ 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
232
242
  };
233
243
  }
234
244
  };
@@ -241,7 +251,7 @@ const getPrNumber$1 = ({ env })=>{
241
251
  }
242
252
  return null;
243
253
  };
244
- const service$2 = {
254
+ const service$3 = {
245
255
  name: "CircleCI",
246
256
  detect: ({ env })=>Boolean(env.CIRCLECI),
247
257
  config: ({ env })=>{
@@ -272,7 +282,7 @@ const getPrNumber = ({ env })=>{
272
282
  if (env.TRAVIS_PULL_REQUEST) return Number(env.TRAVIS_PULL_REQUEST);
273
283
  return null;
274
284
  };
275
- const service$1 = {
285
+ const service$2 = {
276
286
  name: "Travis CI",
277
287
  detect: ({ env })=>Boolean(env.TRAVIS),
278
288
  config: (ctx)=>{
@@ -290,7 +300,7 @@ const service$1 = {
290
300
  }
291
301
  };
292
302
 
293
- const service = {
303
+ const service$1 = {
294
304
  name: "GitLab",
295
305
  detect: ({ env })=>env.GITLAB_CI === "true",
296
306
  config: ({ env })=>{
@@ -307,6 +317,24 @@ const service = {
307
317
  }
308
318
  };
309
319
 
320
+ const service = {
321
+ name: "Git",
322
+ detect: ()=>checkIsGitRepository(),
323
+ config: ()=>{
324
+ return {
325
+ // Buildkite doesn't work well so we fallback to git to ensure we have commit and branch
326
+ commit: head() || null,
327
+ branch: branch() || null,
328
+ owner: null,
329
+ repository: null,
330
+ jobId: null,
331
+ runId: null,
332
+ prNumber: null,
333
+ prHeadCommit: null
334
+ };
335
+ }
336
+ };
337
+
310
338
  const KEY = "@argos-ci/core";
311
339
  const debug = createDebug(KEY);
312
340
  const debugTime = (arg)=>{
@@ -322,37 +350,13 @@ const debugTimeEnd = (arg)=>{
322
350
  }
323
351
  };
324
352
 
325
- const getCiEnvironmentFromEnvCi = (ctx)=>{
326
- const ciContext = envCi(ctx);
327
- const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
328
- const commit = ciContext.commit ?? null;
329
- const branch = (ciContext.branch || ciContext.prBranch) ?? null;
330
- const slug = ciContext.slug ? ciContext.slug.split("/") : null;
331
- const owner = slug ? slug[0] : null;
332
- const repository = slug ? slug[1] : null;
333
- const jobId = ciContext.job ?? null;
334
- const runId = null;
335
- const prNumber = null;
336
- const prHeadCommit = null;
337
- return commit ? {
338
- name,
339
- commit,
340
- branch,
341
- owner,
342
- repository,
343
- jobId,
344
- runId,
345
- prNumber,
346
- prHeadCommit
347
- } : null;
348
- };
349
-
350
353
  const services = [
354
+ service$5,
351
355
  service$4,
352
356
  service$3,
353
357
  service$2,
358
+ service$6,
354
359
  service$1,
355
- service$5,
356
360
  service
357
361
  ];
358
362
  const getCiEnvironment = ({ env = process.env } = {})=>{
@@ -374,11 +378,7 @@ const getCiEnvironment = ({ env = process.env } = {})=>{
374
378
  debug("CI environment", ciEnvironment);
375
379
  return ciEnvironment;
376
380
  }
377
- // We fallback on "env-ci" library, not very good but it's better than nothing
378
- debug("Falling back on env-ci");
379
- const ciEnvironment = getCiEnvironmentFromEnvCi(ctx);
380
- debug("CI environment", ciEnvironment);
381
- return ciEnvironment;
381
+ return null;
382
382
  };
383
383
 
384
384
  const discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {})=>{
@@ -387,10 +387,13 @@ const discoverScreenshots = async (patterns, { root = process.cwd(), ignore } =
387
387
  ignore,
388
388
  cwd: root
389
389
  });
390
- return matches.map((match)=>({
390
+ return matches.map((match)=>{
391
+ const path = resolve(root, match);
392
+ return {
391
393
  name: match,
392
- path: resolve(root, match)
393
- }));
394
+ path
395
+ };
396
+ });
394
397
  };
395
398
 
396
399
  const tmpFile = promisify(tmp.file);
@@ -465,7 +468,8 @@ const createArgosApiClient = (options)=>{
465
468
  });
466
469
  return response.data;
467
470
  } catch (error) {
468
- if (error?.response?.data?.error?.message) {
471
+ var _error_response_data_error, _error_response_data, _error_response;
472
+ 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) {
469
473
  // @ts-ignore
470
474
  throw new Error(error.response.data.error.message, {
471
475
  cause: error
@@ -518,19 +522,19 @@ const getConfigFromOptions = (options)=>{
518
522
  const ciEnv = getCiEnvironment();
519
523
  config.load({
520
524
  apiBaseUrl: options.apiBaseUrl ?? config.get("apiBaseUrl"),
521
- commit: options.commit ?? config.get("commit") ?? ciEnv?.commit ?? null,
522
- branch: options.branch ?? config.get("branch") ?? ciEnv?.branch ?? null,
525
+ commit: options.commit ?? config.get("commit") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.commit) ?? null,
526
+ branch: options.branch ?? config.get("branch") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.branch) ?? null,
523
527
  token: options.token ?? config.get("token") ?? null,
524
528
  buildName: options.buildName ?? config.get("buildName") ?? null,
525
- prNumber: options.prNumber ?? config.get("prNumber") ?? ciEnv?.prNumber ?? null,
526
- prHeadCommit: config.get("prHeadCommit") ?? ciEnv?.prHeadCommit ?? null,
529
+ prNumber: options.prNumber ?? config.get("prNumber") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prNumber) ?? null,
530
+ prHeadCommit: config.get("prHeadCommit") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.prHeadCommit) ?? null,
527
531
  referenceBranch: options.referenceBranch ?? config.get("referenceBranch") ?? null,
528
532
  referenceCommit: options.referenceCommit ?? config.get("referenceCommit") ?? null,
529
- ciService: ciEnv?.name ?? null,
530
- owner: ciEnv?.owner ?? null,
531
- repository: ciEnv?.repository ?? null,
532
- jobId: ciEnv?.jobId ?? null,
533
- runId: ciEnv?.runId ?? null
533
+ ciService: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.name) ?? null,
534
+ owner: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.owner) ?? null,
535
+ repository: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.repository) ?? null,
536
+ jobId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.jobId) ?? null,
537
+ runId: (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.runId) ?? null
534
538
  });
535
539
  if (options.parallel) {
536
540
  config.load({
@@ -564,10 +568,14 @@ const getConfigFromOptions = (options)=>{
564
568
  debug("Found screenshots", foundScreenshots);
565
569
  // Optimize & compute hashes
566
570
  const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
567
- const optimizedPath = await optimizeScreenshot(screenshot.path);
571
+ const [metadata, optimizedPath] = await Promise.all([
572
+ readMetadata(screenshot.path),
573
+ optimizeScreenshot(screenshot.path)
574
+ ]);
568
575
  const hash = await hashFile(optimizedPath);
569
576
  return {
570
577
  ...screenshot,
578
+ metadata,
571
579
  optimizedPath,
572
580
  hash
573
581
  };
@@ -612,7 +620,8 @@ const getConfigFromOptions = (options)=>{
612
620
  buildId: result.build.id,
613
621
  screenshots: screenshots.map((screenshot)=>({
614
622
  key: screenshot.hash,
615
- name: screenshot.name
623
+ name: screenshot.name,
624
+ metadata: screenshot.metadata
616
625
  })),
617
626
  parallel: config.parallel,
618
627
  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.12.0",
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.7+b2cbada",
10
5
  "type": "module",
11
6
  "main": "./dist/index.cjs",
12
7
  "types": "./dist/index.d.ts",
@@ -45,21 +40,24 @@
45
40
  "access": "public"
46
41
  },
47
42
  "dependencies": {
43
+ "@argos-ci/util": "0.0.1-alpha.187+b2cbada",
48
44
  "axios": "^1.5.0",
49
45
  "convict": "^6.2.4",
50
46
  "debug": "^4.3.4",
51
- "env-ci": "^9.1.1",
52
47
  "fast-glob": "^3.3.1",
53
48
  "sharp": "^0.32.5",
54
49
  "tmp": "^0.2.1"
55
50
  },
56
51
  "devDependencies": {
57
52
  "@types/convict": "^6.1.4",
53
+ "@types/debug": "^4.1.9",
58
54
  "@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"
55
+ "msw": "^1.3.0"
56
+ },
57
+ "scripts": {
58
+ "prebuild": "rm -rf dist",
59
+ "build": "rollup -c",
60
+ "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
63
61
  },
64
- "gitHead": "e58b26f5c3a9998d89353c4435aa742b5ae3d244"
62
+ "gitHead": "b2cbadab77b42d32946e7ed315290e9b9bd7d245"
65
63
  }