@argos-ci/core 6.8.7 → 6.9.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 +25 -22
- package/dist/index.mjs +82 -77
- package/package.json +11 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ArgosAPISchema } from "@argos-ci/api-client";
|
|
2
2
|
import { ScreenshotMetadata } from "@argos-ci/util";
|
|
3
|
-
//#region src/config.d.ts
|
|
4
3
|
/** Argos API used unless one is named explicitly or by `ARGOS_API_BASE_URL`. */
|
|
5
4
|
export declare const DEFAULT_API_BASE_URL = "https://api.argos-ci.com/v2/";
|
|
6
5
|
export interface Config {
|
|
@@ -24,9 +23,10 @@ export interface Config {
|
|
|
24
23
|
*/
|
|
25
24
|
token: string | null;
|
|
26
25
|
/**
|
|
27
|
-
* Argos project slug
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* Argos project slug (`owner/project`) the build, deployment or media
|
|
27
|
+
* belongs to. Required with a project token linked to several projects;
|
|
28
|
+
* also disambiguates tokenless authentication when multiple Argos projects
|
|
29
|
+
* are linked to the same repository.
|
|
30
30
|
* @example "my-org/my-project"
|
|
31
31
|
*/
|
|
32
32
|
project: string | null;
|
|
@@ -161,8 +161,6 @@ export declare function getConfigFromOptions({ parallel, ...options }: Omit<Part
|
|
|
161
161
|
index?: number;
|
|
162
162
|
} | false | undefined;
|
|
163
163
|
}, readOptions?: ReadConfigOptions): Promise<Config>;
|
|
164
|
-
//#endregion
|
|
165
|
-
//#region src/deploy.d.ts
|
|
166
164
|
export interface DeployParameters {
|
|
167
165
|
/**
|
|
168
166
|
* Directory containing the static files to deploy.
|
|
@@ -172,6 +170,12 @@ export interface DeployParameters {
|
|
|
172
170
|
* Argos repository access token.
|
|
173
171
|
*/
|
|
174
172
|
token?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Argos project slug (`account/project`).
|
|
175
|
+
* Required when the token is linked to several projects.
|
|
176
|
+
* @default process.env.ARGOS_PROJECT
|
|
177
|
+
*/
|
|
178
|
+
project?: string;
|
|
175
179
|
/**
|
|
176
180
|
* Base URL of the Argos API.
|
|
177
181
|
* @default "https://api.argos-ci.com/v2/"
|
|
@@ -206,8 +210,6 @@ export declare function deploy(params: DeployParameters): Promise<{
|
|
|
206
210
|
url: string;
|
|
207
211
|
createdAt: string;
|
|
208
212
|
}>;
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region src/finalize.d.ts
|
|
211
213
|
export type FinalizeParameters = {
|
|
212
214
|
/**
|
|
213
215
|
* Base URL of the Argos API.
|
|
@@ -217,6 +219,12 @@ export type FinalizeParameters = {
|
|
|
217
219
|
* Argos token.
|
|
218
220
|
*/
|
|
219
221
|
token?: string;
|
|
222
|
+
/**
|
|
223
|
+
* Argos project slug (`account/project`).
|
|
224
|
+
* Required when the token is linked to several projects.
|
|
225
|
+
* @default process.env.ARGOS_PROJECT
|
|
226
|
+
*/
|
|
227
|
+
project?: string;
|
|
220
228
|
parallel?: {
|
|
221
229
|
nonce: string;
|
|
222
230
|
};
|
|
@@ -249,8 +257,6 @@ export type FinalizeResult = {
|
|
|
249
257
|
* Finalize pending builds.
|
|
250
258
|
*/
|
|
251
259
|
export declare function finalize(params: FinalizeParameters): Promise<FinalizeResult>;
|
|
252
|
-
//#endregion
|
|
253
|
-
//#region src/media.d.ts
|
|
254
260
|
export type Media = ArgosAPISchema.components["schemas"]["Media"];
|
|
255
261
|
/** Which half of a before/after pair a media is. */
|
|
256
262
|
export type MediaState = NonNullable<Media["state"]>;
|
|
@@ -273,8 +279,9 @@ export interface UploadMediaParameters {
|
|
|
273
279
|
apiBaseUrl?: string;
|
|
274
280
|
/**
|
|
275
281
|
* Project to upload to, as `owner/project`. Required when authenticating with
|
|
276
|
-
* a personal access token
|
|
277
|
-
*
|
|
282
|
+
* a personal access token or a project token linked to several projects;
|
|
283
|
+
* ignored with a project token linked to a single one, which already
|
|
284
|
+
* identifies it.
|
|
278
285
|
*/
|
|
279
286
|
project?: string;
|
|
280
287
|
/**
|
|
@@ -324,14 +331,10 @@ export interface UploadMediaParameters {
|
|
|
324
331
|
* is ready the moment the upload finishes — there is no processing to wait on.
|
|
325
332
|
*/
|
|
326
333
|
export declare function uploadMedia(params: UploadMediaParameters): Promise<Media[]>;
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/mime-type.d.ts
|
|
329
334
|
/**
|
|
330
335
|
* Get the mime type of a snapshot file based on its extension.
|
|
331
336
|
*/
|
|
332
337
|
export declare function getSnapshotMimeType(filepath: string): string;
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/upload.d.ts
|
|
335
338
|
type BuildMetadata = ArgosAPISchema.components["schemas"]["BuildMetadata"];
|
|
336
339
|
export interface UploadParameters {
|
|
337
340
|
/**
|
|
@@ -367,8 +370,10 @@ export interface UploadParameters {
|
|
|
367
370
|
token?: string;
|
|
368
371
|
/**
|
|
369
372
|
* Argos project slug (`account/project`).
|
|
370
|
-
*
|
|
371
|
-
*
|
|
373
|
+
* Required when the token is linked to several projects. Also used to
|
|
374
|
+
* disambiguate tokenless authentication when multiple Argos projects are
|
|
375
|
+
* linked to the same repository.
|
|
376
|
+
* @default process.env.ARGOS_PROJECT
|
|
372
377
|
*/
|
|
373
378
|
project?: string;
|
|
374
379
|
/**
|
|
@@ -457,13 +462,11 @@ export declare function upload(params: UploadParameters): Promise<{
|
|
|
457
462
|
build: ArgosAPISchema.components["schemas"]["Build"];
|
|
458
463
|
screenshots: Screenshot[];
|
|
459
464
|
}>;
|
|
460
|
-
|
|
461
|
-
//#region src/skip.d.ts
|
|
462
|
-
type SkipParameters = Pick<UploadParameters, "apiBaseUrl" | "commit" | "branch" | "token" | "prNumber" | "buildName" | "metadata">;
|
|
465
|
+
type SkipParameters = Pick<UploadParameters, "apiBaseUrl" | "commit" | "branch" | "token" | "project" | "prNumber" | "buildName" | "metadata">;
|
|
463
466
|
/**
|
|
464
467
|
* Mark a build as skipped.
|
|
465
468
|
*/
|
|
466
469
|
export declare function skip(params: SkipParameters): Promise<{
|
|
467
470
|
build: ArgosAPISchema.components["schemas"]["Build"];
|
|
468
471
|
}>;
|
|
469
|
-
|
|
472
|
+
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import convict from "convict";
|
|
3
3
|
import { execFile, execFileSync, execSync } from "node:child_process";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
-
import pRetry from "p-retry";
|
|
5
|
+
import pRetry, { AbortError } from "p-retry";
|
|
6
6
|
import createDebug from "debug";
|
|
7
7
|
import { createReadStream, existsSync, readFileSync } from "node:fs";
|
|
8
8
|
import { open, readFile, stat } from "node:fs/promises";
|
|
@@ -14,7 +14,7 @@ import { createHash } from "node:crypto";
|
|
|
14
14
|
import { getPlaywrightTracePath, readMetadata, readVersionFromPackage } from "@argos-ci/util";
|
|
15
15
|
import sharp from "sharp";
|
|
16
16
|
import tmp from "tmp";
|
|
17
|
-
|
|
17
|
+
// src/debug.ts
|
|
18
18
|
const KEY = "@argos-ci/core";
|
|
19
19
|
const debug = createDebug(KEY);
|
|
20
20
|
/**
|
|
@@ -42,8 +42,7 @@ const debugTime = (arg) => {
|
|
|
42
42
|
const debugTimeEnd = (arg) => {
|
|
43
43
|
if (isDebugEnabled) console.timeEnd(arg);
|
|
44
44
|
};
|
|
45
|
-
|
|
46
|
-
//#region src/ci-environment/git.ts
|
|
45
|
+
// src/ci-environment/git.ts
|
|
47
46
|
const execFileAsync = promisify(execFile);
|
|
48
47
|
/**
|
|
49
48
|
* Check if the current directory is a git repository.
|
|
@@ -347,8 +346,7 @@ function readCommitParents(sha) {
|
|
|
347
346
|
return null;
|
|
348
347
|
}
|
|
349
348
|
}
|
|
350
|
-
|
|
351
|
-
//#region src/ci-environment/services/bitrise.ts
|
|
349
|
+
// src/ci-environment/services/bitrise.ts
|
|
352
350
|
function getPrNumber$2(context) {
|
|
353
351
|
const { env } = context;
|
|
354
352
|
return env.BITRISE_PULL_REQUEST ? Number(env.BITRISE_PULL_REQUEST) : null;
|
|
@@ -382,8 +380,7 @@ const service$7 = {
|
|
|
382
380
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
383
381
|
listAncestorCommits: listAncestorCommits$1
|
|
384
382
|
};
|
|
385
|
-
|
|
386
|
-
//#region src/util/url.ts
|
|
383
|
+
// src/util/url.ts
|
|
387
384
|
/**
|
|
388
385
|
* Utility functions for parsing Git remote URLs.
|
|
389
386
|
* Supports SSH, HTTPS, and git protocols.
|
|
@@ -395,8 +392,7 @@ function getRepositoryNameFromURL(url) {
|
|
|
395
392
|
if (httpsMatch && httpsMatch[1] && httpsMatch[2]) return `${httpsMatch[1]}/${httpsMatch[2]}`;
|
|
396
393
|
return null;
|
|
397
394
|
}
|
|
398
|
-
|
|
399
|
-
//#region src/ci-environment/services/buildkite.ts
|
|
395
|
+
// src/ci-environment/services/buildkite.ts
|
|
400
396
|
function getRepository$5(context) {
|
|
401
397
|
const { env } = context;
|
|
402
398
|
if (env.BUILDKITE_REPO) return getRepositoryNameFromURL(env.BUILDKITE_REPO);
|
|
@@ -436,8 +432,7 @@ const service$6 = {
|
|
|
436
432
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
437
433
|
listAncestorCommits: listAncestorCommits$1
|
|
438
434
|
};
|
|
439
|
-
|
|
440
|
-
//#region src/ci-environment/services/heroku.ts
|
|
435
|
+
// src/ci-environment/services/heroku.ts
|
|
441
436
|
const service$5 = {
|
|
442
437
|
name: "Heroku",
|
|
443
438
|
key: "heroku",
|
|
@@ -459,8 +454,7 @@ const service$5 = {
|
|
|
459
454
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
460
455
|
listAncestorCommits: listAncestorCommits$1
|
|
461
456
|
};
|
|
462
|
-
|
|
463
|
-
//#region src/ci-environment/github.ts
|
|
457
|
+
// src/ci-environment/github.ts
|
|
464
458
|
/**
|
|
465
459
|
* Get the full repository name (account/repo) from environment variable.
|
|
466
460
|
*/
|
|
@@ -568,8 +562,7 @@ function getPRNumberFromMergeGroupBranch(branch) {
|
|
|
568
562
|
if (prMatch) return Number(prMatch[1]);
|
|
569
563
|
return null;
|
|
570
564
|
}
|
|
571
|
-
|
|
572
|
-
//#region src/ci-environment/services/github-actions.ts
|
|
565
|
+
// src/ci-environment/services/github-actions.ts
|
|
573
566
|
/**
|
|
574
567
|
* Read the event payload.
|
|
575
568
|
*/
|
|
@@ -786,8 +779,7 @@ const service$4 = {
|
|
|
786
779
|
getMergeBaseCommitSha: getMergeBaseCommitSha$1,
|
|
787
780
|
listAncestorCommits: listAncestorCommits$1
|
|
788
781
|
};
|
|
789
|
-
|
|
790
|
-
//#region src/ci-environment/services/circleci.ts
|
|
782
|
+
// src/ci-environment/services/circleci.ts
|
|
791
783
|
function getPrNumber$1(context) {
|
|
792
784
|
const { env } = context;
|
|
793
785
|
const matches = /pull\/(\d+)/.exec(env.CIRCLE_PULL_REQUEST || "");
|
|
@@ -827,8 +819,7 @@ const service$3 = {
|
|
|
827
819
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
828
820
|
listAncestorCommits: listAncestorCommits$1
|
|
829
821
|
};
|
|
830
|
-
|
|
831
|
-
//#region src/ci-environment/services/travis.ts
|
|
822
|
+
// src/ci-environment/services/travis.ts
|
|
832
823
|
function getRepository$2(context) {
|
|
833
824
|
const { env } = context;
|
|
834
825
|
if (env.TRAVIS_PULL_REQUEST_SLUG) return env.TRAVIS_PULL_REQUEST_SLUG;
|
|
@@ -866,8 +857,7 @@ const service$2 = {
|
|
|
866
857
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
867
858
|
listAncestorCommits: listAncestorCommits$1
|
|
868
859
|
};
|
|
869
|
-
|
|
870
|
-
//#region src/ci-environment/services/gitlab.ts
|
|
860
|
+
// src/ci-environment/services/gitlab.ts
|
|
871
861
|
function getRepository$1(context) {
|
|
872
862
|
const { env } = context;
|
|
873
863
|
if (env.CI_MERGE_REQUEST_PROJECT_PATH) return env.CI_MERGE_REQUEST_PROJECT_PATH;
|
|
@@ -900,15 +890,13 @@ const service$1 = {
|
|
|
900
890
|
getMergeBaseCommitSha: getMergeBaseCommitSha$2,
|
|
901
891
|
listAncestorCommits: listAncestorCommits$1
|
|
902
892
|
};
|
|
903
|
-
|
|
904
|
-
//#region src/ci-environment/services/git.ts
|
|
893
|
+
// src/ci-environment/services/git.ts
|
|
905
894
|
function getRepository() {
|
|
906
895
|
const repositoryURL = getRepositoryURL();
|
|
907
896
|
if (!repositoryURL) return null;
|
|
908
897
|
return getRepositoryNameFromURL(repositoryURL);
|
|
909
898
|
}
|
|
910
|
-
|
|
911
|
-
//#region src/ci-environment/index.ts
|
|
899
|
+
// src/ci-environment/index.ts
|
|
912
900
|
const services = [
|
|
913
901
|
service$5,
|
|
914
902
|
service$4,
|
|
@@ -992,8 +980,7 @@ async function getCiEnvironment() {
|
|
|
992
980
|
debug("No CI service matched");
|
|
993
981
|
return null;
|
|
994
982
|
}
|
|
995
|
-
|
|
996
|
-
//#region src/config.ts
|
|
983
|
+
// src/config.ts
|
|
997
984
|
const mustBeApiBaseUrl = (value) => {
|
|
998
985
|
if (!/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/.test(value)) throw new Error("Invalid Argos API base URL");
|
|
999
986
|
};
|
|
@@ -1268,8 +1255,7 @@ async function getConfigFromOptions({ parallel, ...options }, readOptions) {
|
|
|
1268
1255
|
parallelIndex: parallel ? parallel.index : void 0
|
|
1269
1256
|
}, readOptions);
|
|
1270
1257
|
}
|
|
1271
|
-
|
|
1272
|
-
//#region src/hashing.ts
|
|
1258
|
+
// src/hashing.ts
|
|
1273
1259
|
const hashFile = async (filepath) => {
|
|
1274
1260
|
const fileStream = createReadStream(filepath);
|
|
1275
1261
|
const hash = createHash("sha256");
|
|
@@ -1281,8 +1267,7 @@ const hashFile = async (filepath) => {
|
|
|
1281
1267
|
});
|
|
1282
1268
|
return hash.digest("hex");
|
|
1283
1269
|
};
|
|
1284
|
-
|
|
1285
|
-
//#region src/s3.ts
|
|
1270
|
+
// src/s3.ts
|
|
1286
1271
|
/**
|
|
1287
1272
|
* On failure, S3 responds with an XML body describing the error, e.g.:
|
|
1288
1273
|
*
|
|
@@ -1347,8 +1332,7 @@ async function uploadFileWithPresignedPost(input) {
|
|
|
1347
1332
|
});
|
|
1348
1333
|
if (!response.ok) throw await createUploadError(input.url, response);
|
|
1349
1334
|
}
|
|
1350
|
-
|
|
1351
|
-
//#region src/util/chunk.ts
|
|
1335
|
+
// src/util/chunk.ts
|
|
1352
1336
|
/**
|
|
1353
1337
|
* Split an array into chunks of a given size.
|
|
1354
1338
|
*/
|
|
@@ -1391,8 +1375,7 @@ async function mapInChunks(collection, size, mapper) {
|
|
|
1391
1375
|
for (const items of chunk(collection, size)) results.push(...await Promise.all(items.map(mapper)));
|
|
1392
1376
|
return results;
|
|
1393
1377
|
}
|
|
1394
|
-
|
|
1395
|
-
//#region src/github-actions-oidc.ts
|
|
1378
|
+
// src/github-actions-oidc.ts
|
|
1396
1379
|
/**
|
|
1397
1380
|
* Check if GitHub Actions OIDC is available for auto-detection.
|
|
1398
1381
|
*/
|
|
@@ -1404,13 +1387,23 @@ async function fetchOidcToken(args) {
|
|
|
1404
1387
|
if (!process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN) throw new Error(`ACTIONS_ID_TOKEN_REQUEST_TOKEN not found`);
|
|
1405
1388
|
const url = new URL(process.env.ACTIONS_ID_TOKEN_REQUEST_URL);
|
|
1406
1389
|
url.searchParams.set("audience", args.audience);
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1390
|
+
const data = await (await pRetry(async () => {
|
|
1391
|
+
const response = await fetch(url.toString(), { headers: {
|
|
1392
|
+
Authorization: `Bearer ${process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN}`,
|
|
1393
|
+
Accept: "application/json; api-version=2.0",
|
|
1394
|
+
"Content-Type": "application/json"
|
|
1395
|
+
} });
|
|
1396
|
+
if (!response.ok) {
|
|
1397
|
+
const message = `Failed to fetch GitHub Actions OIDC token: ${response.status} ${response.statusText}`;
|
|
1398
|
+
throw response.status >= 500 ? new Error(message) : new AbortError(message);
|
|
1399
|
+
}
|
|
1400
|
+
return response;
|
|
1401
|
+
}, {
|
|
1402
|
+
retries: 3,
|
|
1403
|
+
onFailedAttempt: ({ error, retriesLeft, retryDelay }) => {
|
|
1404
|
+
if (retriesLeft > 0) debug(`${error.message}, retrying in ${retryDelay}ms (${retriesLeft} left)`);
|
|
1405
|
+
}
|
|
1406
|
+
})).json();
|
|
1414
1407
|
if (!data.value) throw new Error("Invalid GitHub Actions OIDC token response: missing 'value' field");
|
|
1415
1408
|
return data.value;
|
|
1416
1409
|
}
|
|
@@ -1431,8 +1424,7 @@ async function exchangeGitHubActionsOidcToken(args) {
|
|
|
1431
1424
|
if (result.error) throwAPIError(result.error, result.response);
|
|
1432
1425
|
return result.data.token;
|
|
1433
1426
|
}
|
|
1434
|
-
|
|
1435
|
-
//#region src/github-actions-tokenless.ts
|
|
1427
|
+
// src/github-actions-tokenless.ts
|
|
1436
1428
|
const base64Encode = (obj) => Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
|
|
1437
1429
|
/**
|
|
1438
1430
|
* Check if GitHub Actions tokenless authentication is available for auto-detection.
|
|
@@ -1471,8 +1463,7 @@ async function exchangeGitHubActionsTokenlessToken(args) {
|
|
|
1471
1463
|
if (result.error) throwAPIError(result.error, result.response);
|
|
1472
1464
|
return result.data.token;
|
|
1473
1465
|
}
|
|
1474
|
-
|
|
1475
|
-
//#region src/auth.ts
|
|
1466
|
+
// src/auth.ts
|
|
1476
1467
|
/**
|
|
1477
1468
|
* Resolve the Argos authentication token.
|
|
1478
1469
|
* Priority: ARGOS_TOKEN > GitHub Actions OIDC > GitHub Actions tokenless exchange.
|
|
@@ -1504,8 +1495,7 @@ async function resolveArgosToken(config) {
|
|
|
1504
1495
|
}
|
|
1505
1496
|
throw new Error("Missing Argos repository token 'ARGOS_TOKEN'");
|
|
1506
1497
|
}
|
|
1507
|
-
|
|
1508
|
-
//#region src/deploy.ts
|
|
1498
|
+
// src/deploy.ts
|
|
1509
1499
|
const CHUNK_SIZE$1 = 10;
|
|
1510
1500
|
function getContentType(filePath) {
|
|
1511
1501
|
return mime.lookup(filePath) || "application/octet-stream";
|
|
@@ -1544,6 +1534,7 @@ async function deploy(params) {
|
|
|
1544
1534
|
const filesByPath = new Map(files.map((file) => [file.path, file]));
|
|
1545
1535
|
debug("Creating deployment");
|
|
1546
1536
|
const createResponse = await apiClient.POST("/deployments", { body: {
|
|
1537
|
+
project: config.project ?? void 0,
|
|
1547
1538
|
commit: config.commit ?? null,
|
|
1548
1539
|
branch: config.branch ?? null,
|
|
1549
1540
|
prNumber: config.prNumber ?? null,
|
|
@@ -1584,8 +1575,7 @@ async function deploy(params) {
|
|
|
1584
1575
|
if (finalizeResponse.error) throwAPIError(finalizeResponse.error, finalizeResponse.response);
|
|
1585
1576
|
return finalizeResponse.data;
|
|
1586
1577
|
}
|
|
1587
|
-
|
|
1588
|
-
//#region src/version.ts
|
|
1578
|
+
// src/version.ts
|
|
1589
1579
|
const require = createRequire(import.meta.url);
|
|
1590
1580
|
/**
|
|
1591
1581
|
* Get the version of the @argos-ci/core package.
|
|
@@ -1594,8 +1584,7 @@ async function getArgosCoreSDKIdentifier() {
|
|
|
1594
1584
|
const pkgPath = require.resolve("@argos-ci/core/package.json");
|
|
1595
1585
|
return `@argos-ci/core@${await readVersionFromPackage(pkgPath)}`;
|
|
1596
1586
|
}
|
|
1597
|
-
|
|
1598
|
-
//#region src/skip.ts
|
|
1587
|
+
// src/skip.ts
|
|
1599
1588
|
/**
|
|
1600
1589
|
* Mark a build as skipped.
|
|
1601
1590
|
*/
|
|
@@ -1606,6 +1595,7 @@ async function skip(params) {
|
|
|
1606
1595
|
baseUrl: config.apiBaseUrl,
|
|
1607
1596
|
authToken
|
|
1608
1597
|
}).POST("/builds", { body: {
|
|
1598
|
+
project: config.project ?? void 0,
|
|
1609
1599
|
commit: config.commit,
|
|
1610
1600
|
branch: config.branch,
|
|
1611
1601
|
name: config.buildName,
|
|
@@ -1626,8 +1616,7 @@ async function skip(params) {
|
|
|
1626
1616
|
if (createBuildResponse.error) throwAPIError(createBuildResponse.error, createBuildResponse.response);
|
|
1627
1617
|
return { build: createBuildResponse.data.build };
|
|
1628
1618
|
}
|
|
1629
|
-
|
|
1630
|
-
//#region src/finalize.ts
|
|
1619
|
+
// src/finalize.ts
|
|
1631
1620
|
/**
|
|
1632
1621
|
* Finalize pending builds.
|
|
1633
1622
|
*/
|
|
@@ -1635,6 +1624,7 @@ async function finalize(params) {
|
|
|
1635
1624
|
const config = await readConfig({
|
|
1636
1625
|
apiBaseUrl: params.apiBaseUrl,
|
|
1637
1626
|
token: params.token,
|
|
1627
|
+
project: params.project,
|
|
1638
1628
|
parallelNonce: params.parallel?.nonce
|
|
1639
1629
|
});
|
|
1640
1630
|
const authToken = await resolveArgosToken(config);
|
|
@@ -1643,13 +1633,17 @@ async function finalize(params) {
|
|
|
1643
1633
|
authToken
|
|
1644
1634
|
});
|
|
1645
1635
|
if (!config.parallelNonce) throw new Error("parallel.nonce is required to finalize the build");
|
|
1646
|
-
const finalizeBuildsResult = await apiClient.POST("/builds/finalize", { body: {
|
|
1636
|
+
const finalizeBuildsResult = await apiClient.POST("/builds/finalize", { body: {
|
|
1637
|
+
parallelNonce: config.parallelNonce,
|
|
1638
|
+
project: config.project ?? void 0
|
|
1639
|
+
} });
|
|
1647
1640
|
if (finalizeBuildsResult.error) throwAPIError(finalizeBuildsResult.error, finalizeBuildsResult.response);
|
|
1648
1641
|
const { builds } = finalizeBuildsResult.data;
|
|
1649
1642
|
if (builds.length === 0 && params.skipIfEmpty) {
|
|
1650
1643
|
const { build } = await skip({
|
|
1651
1644
|
apiBaseUrl: params.apiBaseUrl,
|
|
1652
1645
|
token: params.token,
|
|
1646
|
+
project: params.project,
|
|
1653
1647
|
buildName: params.buildName
|
|
1654
1648
|
});
|
|
1655
1649
|
return {
|
|
@@ -1662,8 +1656,7 @@ async function finalize(params) {
|
|
|
1662
1656
|
skippedBuild: null
|
|
1663
1657
|
};
|
|
1664
1658
|
}
|
|
1665
|
-
|
|
1666
|
-
//#region src/media-compress.ts
|
|
1659
|
+
// src/media-compress.ts
|
|
1667
1660
|
/**
|
|
1668
1661
|
* Content types converted to WebP before upload.
|
|
1669
1662
|
*
|
|
@@ -1720,7 +1713,7 @@ const PNG_HEAD_BYTES = 4096;
|
|
|
1720
1713
|
async function compressMediaToWebp(source) {
|
|
1721
1714
|
const keepOriginal = {
|
|
1722
1715
|
source,
|
|
1723
|
-
cleanup: () => {}
|
|
1716
|
+
cleanup: async () => {}
|
|
1724
1717
|
};
|
|
1725
1718
|
if (!COMPRESSIBLE_CONTENT_TYPES.has(source.contentType)) {
|
|
1726
1719
|
debug(`Not compressing ${source.path}: ${source.contentType} is left as-is`);
|
|
@@ -1746,7 +1739,7 @@ async function compressMediaToWebp(source) {
|
|
|
1746
1739
|
const { size } = await sharp(source.path).rotate().webp({ quality: WEBP_QUALITY }).toFile(temporary.path);
|
|
1747
1740
|
if (size >= originalStats.size) {
|
|
1748
1741
|
debug(`Not compressing ${source.path}: WebP is larger (${size} >= ${originalStats.size} bytes)`);
|
|
1749
|
-
temporary.remove();
|
|
1742
|
+
await temporary.remove();
|
|
1750
1743
|
return keepOriginal;
|
|
1751
1744
|
}
|
|
1752
1745
|
debug(`Compressed ${source.path} to WebP: ${originalStats.size} → ${size} bytes`);
|
|
@@ -1761,7 +1754,7 @@ async function compressMediaToWebp(source) {
|
|
|
1761
1754
|
} catch (error) {
|
|
1762
1755
|
const message = error instanceof Error ? error.message : "Unknown Error";
|
|
1763
1756
|
debug(`Not compressing ${source.path}: ${message}`);
|
|
1764
|
-
temporary?.remove();
|
|
1757
|
+
await temporary?.remove();
|
|
1765
1758
|
return keepOriginal;
|
|
1766
1759
|
}
|
|
1767
1760
|
}
|
|
@@ -1772,6 +1765,11 @@ async function compressMediaToWebp(source) {
|
|
|
1772
1765
|
* open descriptor and the remove callback, which leaks one of each per file —
|
|
1773
1766
|
* `tmp` only cleans up at exit when `setGracefulCleanup()` was called, and even
|
|
1774
1767
|
* then it would hold every file for the whole run.
|
|
1768
|
+
*
|
|
1769
|
+
* The callback from the async `tmp.file()` deletes with `fs.unlink`, so it returns
|
|
1770
|
+
* before the file is gone; `remove` waits for the unlink to report back.
|
|
1771
|
+
* Otherwise a caller that exits right after an upload drops the pending unlink
|
|
1772
|
+
* and leaves the file behind.
|
|
1775
1773
|
*/
|
|
1776
1774
|
function createTemporaryFile() {
|
|
1777
1775
|
return new Promise((resolve, reject) => {
|
|
@@ -1784,12 +1782,22 @@ function createTemporaryFile() {
|
|
|
1784
1782
|
reject(error);
|
|
1785
1783
|
return;
|
|
1786
1784
|
}
|
|
1785
|
+
const removeAsync = removeCallback;
|
|
1786
|
+
let removal = null;
|
|
1787
1787
|
resolve({
|
|
1788
1788
|
path,
|
|
1789
1789
|
remove: () => {
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1790
|
+
removal ??= new Promise((settle) => {
|
|
1791
|
+
try {
|
|
1792
|
+
removeAsync((removeError) => {
|
|
1793
|
+
if (removeError) debug(`Could not delete ${path}: ${removeError.message}`);
|
|
1794
|
+
settle();
|
|
1795
|
+
});
|
|
1796
|
+
} catch {
|
|
1797
|
+
settle();
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
1800
|
+
return removal;
|
|
1793
1801
|
}
|
|
1794
1802
|
});
|
|
1795
1803
|
});
|
|
@@ -1811,8 +1819,7 @@ async function checkIsAnimatedPng(source) {
|
|
|
1811
1819
|
await file.close();
|
|
1812
1820
|
}
|
|
1813
1821
|
}
|
|
1814
|
-
|
|
1815
|
-
//#region src/media.ts
|
|
1822
|
+
// src/media.ts
|
|
1816
1823
|
/**
|
|
1817
1824
|
* Content types Argos accepts for a standalone media upload. Kept here so a
|
|
1818
1825
|
* caller learns the file is unsupported before anything is uploaded.
|
|
@@ -1890,7 +1897,7 @@ async function uploadOne(args) {
|
|
|
1890
1897
|
source: compressed?.source ?? args.source
|
|
1891
1898
|
});
|
|
1892
1899
|
} finally {
|
|
1893
|
-
compressed?.cleanup();
|
|
1900
|
+
await compressed?.cleanup();
|
|
1894
1901
|
}
|
|
1895
1902
|
}
|
|
1896
1903
|
async function registerAndUpload(args) {
|
|
@@ -2034,8 +2041,7 @@ function assertDistinctIdentities(files, identities) {
|
|
|
2034
2041
|
seen.set(key, filepath);
|
|
2035
2042
|
}
|
|
2036
2043
|
}
|
|
2037
|
-
|
|
2038
|
-
//#region src/mime-type.ts
|
|
2044
|
+
// src/mime-type.ts
|
|
2039
2045
|
/**
|
|
2040
2046
|
* Get the mime type of a snapshot file based on its extension.
|
|
2041
2047
|
*/
|
|
@@ -2044,8 +2050,7 @@ function getSnapshotMimeType(filepath) {
|
|
|
2044
2050
|
if (!type) throw new Error(`Unable to determine snapshot file type for: ${filepath}`);
|
|
2045
2051
|
return type;
|
|
2046
2052
|
}
|
|
2047
|
-
|
|
2048
|
-
//#region src/discovery.ts
|
|
2053
|
+
// src/discovery.ts
|
|
2049
2054
|
/**
|
|
2050
2055
|
* Discover snapshots in the given root directory matching the provided patterns.
|
|
2051
2056
|
*/
|
|
@@ -2070,8 +2075,7 @@ function checkIsValidImageFile(filename) {
|
|
|
2070
2075
|
const lowerFilename = extname(filename).toLowerCase();
|
|
2071
2076
|
return lowerFilename === ".png" || lowerFilename === ".jpg" || lowerFilename === ".jpeg";
|
|
2072
2077
|
}
|
|
2073
|
-
|
|
2074
|
-
//#region src/optimize.ts
|
|
2078
|
+
// src/optimize.ts
|
|
2075
2079
|
const tmpFile = promisify(tmp.file);
|
|
2076
2080
|
/**
|
|
2077
2081
|
* Maximum number of pixels allowed in a screenshot.
|
|
@@ -2213,8 +2217,7 @@ async function resolveBaseline(params) {
|
|
|
2213
2217
|
parentCommits
|
|
2214
2218
|
};
|
|
2215
2219
|
}
|
|
2216
|
-
|
|
2217
|
-
//#region src/upload.ts
|
|
2220
|
+
// src/upload.ts
|
|
2218
2221
|
/**
|
|
2219
2222
|
* Size of the chunks used to process and upload screenshots.
|
|
2220
2223
|
* Limits concurrency to avoid memory pressure when handling many screenshots.
|
|
@@ -2285,8 +2288,9 @@ async function upload(params) {
|
|
|
2285
2288
|
contentType
|
|
2286
2289
|
};
|
|
2287
2290
|
});
|
|
2291
|
+
const project = config.project ?? void 0;
|
|
2288
2292
|
debug("Fetch project");
|
|
2289
|
-
const projectResponse = await apiClient.GET("/project");
|
|
2293
|
+
const projectResponse = await apiClient.GET("/project", { params: { query: { project } } });
|
|
2290
2294
|
if (projectResponse.error) throwAPIError(projectResponse.error, projectResponse.response);
|
|
2291
2295
|
debug("Project fetched", projectResponse.data);
|
|
2292
2296
|
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
@@ -2317,6 +2321,7 @@ async function upload(params) {
|
|
|
2317
2321
|
listCommits,
|
|
2318
2322
|
findBaseline: async (commits) => {
|
|
2319
2323
|
const response = await apiClient.POST("/baseline", { body: {
|
|
2324
|
+
project,
|
|
2320
2325
|
commits,
|
|
2321
2326
|
name: config.buildName ?? void 0,
|
|
2322
2327
|
mode: config.mode ?? void 0
|
|
@@ -2337,6 +2342,7 @@ async function upload(params) {
|
|
|
2337
2342
|
});
|
|
2338
2343
|
}
|
|
2339
2344
|
const createBuildResponse = await apiClient.POST("/builds", { body: {
|
|
2345
|
+
project,
|
|
2340
2346
|
commit: config.commit,
|
|
2341
2347
|
branch: config.branch,
|
|
2342
2348
|
name: config.buildName,
|
|
@@ -2444,5 +2450,4 @@ function formatPreviewUrl(url, formatter) {
|
|
|
2444
2450
|
const urlObj = new URL(url);
|
|
2445
2451
|
return new URL(urlObj.pathname + urlObj.search + urlObj.hash, formatter.baseUrl).href;
|
|
2446
2452
|
}
|
|
2447
|
-
//#endregion
|
|
2448
2453
|
export { DEFAULT_API_BASE_URL, deploy, finalize, getConfigFromOptions, getSnapshotMimeType, readConfig, skip, upload, uploadMedia };
|
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.
|
|
4
|
+
"version": "6.9.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -27,20 +27,23 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"keywords": [
|
|
30
|
+
"argos",
|
|
31
|
+
"argos-ci",
|
|
30
32
|
"sdk",
|
|
31
33
|
"node",
|
|
32
|
-
"argos",
|
|
33
34
|
"testing",
|
|
34
|
-
"visual
|
|
35
|
-
"regression",
|
|
36
|
-
"visual
|
|
35
|
+
"visual-testing",
|
|
36
|
+
"visual-regression",
|
|
37
|
+
"visual-regression-testing",
|
|
38
|
+
"screenshot-testing",
|
|
39
|
+
"continuous-integration"
|
|
37
40
|
],
|
|
38
41
|
"publishConfig": {
|
|
39
42
|
"access": "public"
|
|
40
43
|
},
|
|
41
44
|
"dependencies": {
|
|
42
|
-
"@argos-ci/api-client": "0.
|
|
43
|
-
"@argos-ci/util": "4.
|
|
45
|
+
"@argos-ci/api-client": "0.32.0",
|
|
46
|
+
"@argos-ci/util": "4.3.0",
|
|
44
47
|
"convict": "^6.2.5",
|
|
45
48
|
"debug": "^4.4.3",
|
|
46
49
|
"fast-glob": "^3.3.3",
|
|
@@ -68,5 +71,5 @@
|
|
|
68
71
|
"lint": "eslint .",
|
|
69
72
|
"test": "vitest"
|
|
70
73
|
},
|
|
71
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "96ca00234edc12d322416295a4abebbc8471b696"
|
|
72
75
|
}
|