@argos-ci/core 6.5.0 → 6.6.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.mts CHANGED
@@ -193,60 +193,46 @@ declare function deploy(params: DeployParameters): Promise<{
193
193
  //#endregion
194
194
  //#region src/finalize.d.ts
195
195
  type FinalizeParameters = {
196
+ /**
197
+ * Base URL of the Argos API.
198
+ */
199
+ apiBaseUrl?: string;
200
+ /**
201
+ * Argos token.
202
+ */
203
+ token?: string;
196
204
  parallel?: {
197
205
  nonce: string;
198
206
  };
207
+ /**
208
+ * Create a skipped build when no parallel build matches the nonce.
209
+ * Useful when uploads are conditional (e.g. skipped by a CI cache such as
210
+ * Turborepo or Nx) and Argos is a required status check: the skipped build
211
+ * reports a success status even though nothing was uploaded.
212
+ */
213
+ skipIfEmpty?: boolean;
214
+ /**
215
+ * Name of the build, used by the skipped build created when `skipIfEmpty`
216
+ * is enabled and no build matches the nonce.
217
+ */
218
+ buildName?: string;
219
+ };
220
+ type Build = ArgosAPISchema.components["schemas"]["Build"];
221
+ type FinalizeResult = {
222
+ /**
223
+ * Parallel builds finalized by this call.
224
+ */
225
+ builds: Build[];
226
+ /**
227
+ * Skipped build created when `skipIfEmpty` is enabled and no parallel
228
+ * build matched the nonce, `null` otherwise.
229
+ */
230
+ skippedBuild: Build | null;
199
231
  };
200
232
  /**
201
233
  * Finalize pending builds.
202
234
  */
203
- declare function finalize(params: FinalizeParameters): Promise<{
204
- builds: {
205
- id: string;
206
- number: unknown;
207
- head: {
208
- sha: string;
209
- branch: string;
210
- };
211
- base: {
212
- sha: string;
213
- branch: string;
214
- } | null;
215
- status: ("accepted" | "rejected") | ("no-changes" | "changes-detected") | ("expired" | "pending" | "progress" | "error" | "aborted");
216
- conclusion: ("no-changes" | "changes-detected") | null;
217
- stats: {
218
- added: number;
219
- removed: number;
220
- unchanged: number;
221
- changed: number;
222
- ignored: number;
223
- failure: number;
224
- retryFailure: number;
225
- total: number;
226
- } | null;
227
- metadata: {
228
- testReport?: {
229
- status: "passed" | "failed" | "timedout" | "interrupted";
230
- stats?: {
231
- startTime?: string | undefined;
232
- duration?: number | undefined;
233
- } | undefined;
234
- } | undefined;
235
- } | null;
236
- url: string;
237
- notification: {
238
- description: string;
239
- context: string;
240
- github: {
241
- state: "pending" | "success" | "error" | "failure";
242
- };
243
- gitlab: {
244
- state: "pending" | "running" | "success" | "failed" | "canceled";
245
- };
246
- url: string;
247
- } | null;
248
- }[];
249
- }>;
235
+ declare function finalize(params: FinalizeParameters): Promise<FinalizeResult>;
250
236
  //#endregion
251
237
  //#region src/mime-type.d.ts
252
238
  /**
@@ -387,4 +373,4 @@ declare function skip(params: SkipParameters): Promise<{
387
373
  build: ArgosAPISchema.components["schemas"]["Build"];
388
374
  }>;
389
375
  //#endregion
390
- export { Config, DeployParameters, FinalizeParameters, UploadParameters, deploy, finalize, getConfigFromOptions, getSnapshotMimeType, readConfig, skip, upload };
376
+ export { Config, DeployParameters, FinalizeParameters, FinalizeResult, UploadParameters, deploy, finalize, getConfigFromOptions, getSnapshotMimeType, readConfig, skip, upload };
package/dist/index.mjs CHANGED
@@ -11,9 +11,9 @@ import glob from "fast-glob";
11
11
  import mime from "mime-types";
12
12
  import { createClient, throwAPIError } from "@argos-ci/api-client";
13
13
  import { createHash } from "node:crypto";
14
+ import { getPlaywrightTracePath, readMetadata, readVersionFromPackage } from "@argos-ci/util";
14
15
  import sharp from "sharp";
15
16
  import tmp from "tmp";
16
- import { getPlaywrightTracePath, readMetadata, readVersionFromPackage } from "@argos-ci/util";
17
17
  //#region src/debug.ts
18
18
  const KEY = "@argos-ci/core";
19
19
  const debug = createDebug(KEY);
@@ -1024,6 +1024,7 @@ async function readConfig(options = {}) {
1024
1024
  prBaseBranch: defaultConfig.prBaseBranch || ciEnv?.prBaseBranch || null,
1025
1025
  referenceBranch: options.referenceBranch || defaultConfig.referenceBranch || null,
1026
1026
  referenceCommit: options.referenceCommit || defaultConfig.referenceCommit || null,
1027
+ threshold: options.threshold ?? defaultConfig.threshold ?? null,
1027
1028
  repository: ciEnv?.repository || null,
1028
1029
  originalRepository: ciEnv?.originalRepository || null,
1029
1030
  jobId: ciEnv?.jobId || null,
@@ -1368,12 +1369,57 @@ async function deploy(params) {
1368
1369
  return finalizeResponse.data;
1369
1370
  }
1370
1371
  //#endregion
1372
+ //#region src/version.ts
1373
+ const require = createRequire(import.meta.url);
1374
+ /**
1375
+ * Get the version of the @argos-ci/core package.
1376
+ */
1377
+ async function getArgosCoreSDKIdentifier() {
1378
+ return `@argos-ci/core@${await readVersionFromPackage(require.resolve("@argos-ci/core/package.json"))}`;
1379
+ }
1380
+ //#endregion
1381
+ //#region src/skip.ts
1382
+ /**
1383
+ * Mark a build as skipped.
1384
+ */
1385
+ async function skip(params) {
1386
+ const [config, argosSdk] = await Promise.all([getConfigFromOptions(params), getArgosCoreSDKIdentifier()]);
1387
+ const authToken = await resolveArgosToken(config);
1388
+ const createBuildResponse = await createClient({
1389
+ baseUrl: config.apiBaseUrl,
1390
+ authToken
1391
+ }).POST("/builds", { body: {
1392
+ commit: config.commit,
1393
+ branch: config.branch,
1394
+ name: config.buildName,
1395
+ mode: config.mode,
1396
+ prNumber: config.prNumber,
1397
+ prHeadCommit: config.prHeadCommit,
1398
+ referenceBranch: config.referenceBranch,
1399
+ referenceCommit: config.referenceCommit,
1400
+ argosSdk,
1401
+ ciProvider: config.ciProvider,
1402
+ runId: config.runId,
1403
+ runAttempt: config.runAttempt,
1404
+ skipped: true,
1405
+ screenshots: [],
1406
+ pwTraceKeys: [],
1407
+ parentCommits: []
1408
+ } });
1409
+ if (createBuildResponse.error) throwAPIError(createBuildResponse.error, createBuildResponse.response);
1410
+ return { build: createBuildResponse.data.build };
1411
+ }
1412
+ //#endregion
1371
1413
  //#region src/finalize.ts
1372
1414
  /**
1373
1415
  * Finalize pending builds.
1374
1416
  */
1375
1417
  async function finalize(params) {
1376
- const config = await readConfig({ parallelNonce: params.parallel?.nonce });
1418
+ const config = await readConfig({
1419
+ apiBaseUrl: params.apiBaseUrl,
1420
+ token: params.token,
1421
+ parallelNonce: params.parallel?.nonce
1422
+ });
1377
1423
  const authToken = await resolveArgosToken(config);
1378
1424
  const apiClient = createClient({
1379
1425
  baseUrl: config.apiBaseUrl,
@@ -1382,7 +1428,22 @@ async function finalize(params) {
1382
1428
  if (!config.parallelNonce) throw new Error("parallel.nonce is required to finalize the build");
1383
1429
  const finalizeBuildsResult = await apiClient.POST("/builds/finalize", { body: { parallelNonce: config.parallelNonce } });
1384
1430
  if (finalizeBuildsResult.error) throwAPIError(finalizeBuildsResult.error, finalizeBuildsResult.response);
1385
- return finalizeBuildsResult.data;
1431
+ const { builds } = finalizeBuildsResult.data;
1432
+ if (builds.length === 0 && params.skipIfEmpty) {
1433
+ const { build } = await skip({
1434
+ apiBaseUrl: params.apiBaseUrl,
1435
+ token: params.token,
1436
+ buildName: params.buildName
1437
+ });
1438
+ return {
1439
+ builds,
1440
+ skippedBuild: build
1441
+ };
1442
+ }
1443
+ return {
1444
+ builds,
1445
+ skippedBuild: null
1446
+ };
1386
1447
  }
1387
1448
  //#endregion
1388
1449
  //#region src/mime-type.ts
@@ -1475,15 +1536,6 @@ async function optimizeScreenshot(filepath) {
1475
1536
  throw new Error(`Error while processing image (${filepath}): ${message}`, { cause: error });
1476
1537
  }
1477
1538
  }
1478
- //#endregion
1479
- //#region src/version.ts
1480
- const require = createRequire(import.meta.url);
1481
- /**
1482
- * Get the version of the @argos-ci/core package.
1483
- */
1484
- async function getArgosCoreSDKIdentifier() {
1485
- return `@argos-ci/core@${await readVersionFromPackage(require.resolve("@argos-ci/core/package.json"))}`;
1486
- }
1487
1539
  /**
1488
1540
  * Maximum number of commits inspected before giving up.
1489
1541
  */
@@ -1572,38 +1624,6 @@ async function resolveBaseline(params) {
1572
1624
  };
1573
1625
  }
1574
1626
  //#endregion
1575
- //#region src/skip.ts
1576
- /**
1577
- * Mark a build as skipped.
1578
- */
1579
- async function skip(params) {
1580
- const [config, argosSdk] = await Promise.all([getConfigFromOptions(params), getArgosCoreSDKIdentifier()]);
1581
- const authToken = await resolveArgosToken(config);
1582
- const createBuildResponse = await createClient({
1583
- baseUrl: config.apiBaseUrl,
1584
- authToken
1585
- }).POST("/builds", { body: {
1586
- commit: config.commit,
1587
- branch: config.branch,
1588
- name: config.buildName,
1589
- mode: config.mode,
1590
- prNumber: config.prNumber,
1591
- prHeadCommit: config.prHeadCommit,
1592
- referenceBranch: config.referenceBranch,
1593
- referenceCommit: config.referenceCommit,
1594
- argosSdk,
1595
- ciProvider: config.ciProvider,
1596
- runId: config.runId,
1597
- runAttempt: config.runAttempt,
1598
- skipped: true,
1599
- screenshots: [],
1600
- pwTraceKeys: [],
1601
- parentCommits: []
1602
- } });
1603
- if (createBuildResponse.error) throwAPIError(createBuildResponse.error, createBuildResponse.response);
1604
- return { build: createBuildResponse.data.build };
1605
- }
1606
- //#endregion
1607
1627
  //#region src/upload.ts
1608
1628
  /**
1609
1629
  * Size of the chunks used to process and upload screenshots.
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.5.0",
4
+ "version": "6.6.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -39,8 +39,8 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@argos-ci/api-client": "0.24.1",
43
- "@argos-ci/util": "4.0.1",
42
+ "@argos-ci/api-client": "0.25.0",
43
+ "@argos-ci/util": "4.0.4",
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": "7fddaad1a6bb251a1f2eecbf8f4ecfa3e84e9b97"
71
+ "gitHead": "686b6fa8385ed77598ec86f66b073e9897cef176"
72
72
  }