@argos-ci/core 4.4.0 → 5.0.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 +16 -6
- package/dist/index.js +157 -100
- package/package.json +9 -7
- package/LICENSE +0 -7
package/dist/index.d.ts
CHANGED
|
@@ -116,6 +116,10 @@ interface Config {
|
|
|
116
116
|
* No screenshots are uploaded, and the commit status is marked as success.
|
|
117
117
|
*/
|
|
118
118
|
skipped?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Whether the environment is a merge queue.
|
|
121
|
+
*/
|
|
122
|
+
mergeQueue?: boolean;
|
|
119
123
|
}
|
|
120
124
|
declare function readConfig(options?: Partial<Config>): Promise<Config>;
|
|
121
125
|
declare function getConfigFromOptions({ parallel, ...options }: Omit<Partial<Config>, "parallel"> & {
|
|
@@ -145,6 +149,7 @@ interface components {
|
|
|
145
149
|
key: string;
|
|
146
150
|
name: string;
|
|
147
151
|
baseName?: string | null;
|
|
152
|
+
parentName?: string | null;
|
|
148
153
|
metadata?: {
|
|
149
154
|
/**
|
|
150
155
|
* @description Ignored. Can be set to get completions, validations and documentation in some editors.
|
|
@@ -227,6 +232,8 @@ interface components {
|
|
|
227
232
|
} | null;
|
|
228
233
|
pwTraceKey?: string | null;
|
|
229
234
|
threshold?: number | null;
|
|
235
|
+
/** @default image/png */
|
|
236
|
+
contentType: string;
|
|
230
237
|
};
|
|
231
238
|
/** @description Build metadata */
|
|
232
239
|
BuildMetadata: {
|
|
@@ -394,11 +401,6 @@ interface UploadParameters {
|
|
|
394
401
|
previewUrl?: {
|
|
395
402
|
baseUrl: string;
|
|
396
403
|
} | ((url: string) => string);
|
|
397
|
-
/**
|
|
398
|
-
* Mark this build as skipped.
|
|
399
|
-
* No screenshots are uploaded, and the commit status is marked as success.
|
|
400
|
-
*/
|
|
401
|
-
skipped?: boolean;
|
|
402
404
|
}
|
|
403
405
|
interface Screenshot {
|
|
404
406
|
hash: string;
|
|
@@ -421,4 +423,12 @@ declare function upload(params: UploadParameters): Promise<{
|
|
|
421
423
|
screenshots: Screenshot[];
|
|
422
424
|
}>;
|
|
423
425
|
|
|
424
|
-
|
|
426
|
+
type SkipParameters = Pick<UploadParameters, "apiBaseUrl" | "commit" | "branch" | "token" | "prNumber" | "buildName" | "metadata">;
|
|
427
|
+
/**
|
|
428
|
+
* Mark a build as skipped.
|
|
429
|
+
*/
|
|
430
|
+
declare function skip(params: SkipParameters): Promise<{
|
|
431
|
+
build: ArgosAPISchema.components["schemas"]["Build"];
|
|
432
|
+
}>;
|
|
433
|
+
|
|
434
|
+
export { type Config, type FinalizeParameters, type UploadParameters, finalize, getConfigFromOptions, readConfig, skip, upload };
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ function gitMergeBase(input) {
|
|
|
66
66
|
}
|
|
67
67
|
function gitFetch(input) {
|
|
68
68
|
execSync(
|
|
69
|
-
`git fetch --update-head-ok --depth ${input.depth} origin ${input.ref}:${input.
|
|
69
|
+
`git fetch --force --update-head-ok --depth ${input.depth} origin ${input.ref}:${input.target}`
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
72
|
function checkIsExecError(error) {
|
|
@@ -74,18 +74,23 @@ function checkIsExecError(error) {
|
|
|
74
74
|
}
|
|
75
75
|
function getMergeBaseCommitSha(input) {
|
|
76
76
|
let depth = 200;
|
|
77
|
+
const argosBaseRef = `argos/${input.base}`;
|
|
78
|
+
const argosHeadRef = `argos/${input.head}`;
|
|
77
79
|
while (depth < 1e3) {
|
|
78
|
-
gitFetch({ ref: input.head, depth });
|
|
79
|
-
gitFetch({ ref: input.base, depth });
|
|
80
|
-
const mergeBase = gitMergeBase(
|
|
80
|
+
gitFetch({ ref: input.head, depth, target: argosHeadRef });
|
|
81
|
+
gitFetch({ ref: input.base, depth, target: argosBaseRef });
|
|
82
|
+
const mergeBase = gitMergeBase({
|
|
83
|
+
base: argosBaseRef,
|
|
84
|
+
head: argosHeadRef
|
|
85
|
+
});
|
|
81
86
|
if (mergeBase) {
|
|
82
87
|
return mergeBase;
|
|
83
88
|
}
|
|
84
89
|
depth += 200;
|
|
85
90
|
}
|
|
86
91
|
if (isDebugEnabled) {
|
|
87
|
-
const headShas = listShas(
|
|
88
|
-
const baseShas = listShas(
|
|
92
|
+
const headShas = listShas(argosHeadRef);
|
|
93
|
+
const baseShas = listShas(argosBaseRef);
|
|
89
94
|
debug(
|
|
90
95
|
`No merge base found for ${input.head} and ${input.base} with depth ${depth}`
|
|
91
96
|
);
|
|
@@ -106,7 +111,13 @@ function listShas(path, maxCount) {
|
|
|
106
111
|
}
|
|
107
112
|
function listParentCommits(input) {
|
|
108
113
|
const limit = 200;
|
|
109
|
-
|
|
114
|
+
try {
|
|
115
|
+
execSync(`git fetch --depth=${limit} origin ${input.sha}`);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (error instanceof Error && error.message.includes("not our ref")) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
110
121
|
return listShas(input.sha, limit);
|
|
111
122
|
}
|
|
112
123
|
|
|
@@ -140,7 +151,8 @@ var service = {
|
|
|
140
151
|
prNumber: getPrNumber({ env }),
|
|
141
152
|
prHeadCommit: null,
|
|
142
153
|
prBaseBranch: null,
|
|
143
|
-
nonce: env.BITRISEIO_PIPELINE_ID || null
|
|
154
|
+
nonce: env.BITRISEIO_PIPELINE_ID || null,
|
|
155
|
+
mergeQueue: false
|
|
144
156
|
};
|
|
145
157
|
},
|
|
146
158
|
getMergeBaseCommitSha,
|
|
@@ -190,7 +202,8 @@ var service2 = {
|
|
|
190
202
|
prNumber: env.BUILDKITE_PULL_REQUEST ? Number(env.BUILDKITE_PULL_REQUEST) : null,
|
|
191
203
|
prHeadCommit: null,
|
|
192
204
|
prBaseBranch: null,
|
|
193
|
-
nonce: env.BUILDKITE_BUILD_ID || null
|
|
205
|
+
nonce: env.BUILDKITE_BUILD_ID || null,
|
|
206
|
+
mergeQueue: false
|
|
194
207
|
};
|
|
195
208
|
},
|
|
196
209
|
getMergeBaseCommitSha,
|
|
@@ -215,7 +228,8 @@ var service3 = {
|
|
|
215
228
|
prNumber: null,
|
|
216
229
|
prHeadCommit: null,
|
|
217
230
|
prBaseBranch: null,
|
|
218
|
-
nonce: env.HEROKU_TEST_RUN_ID || null
|
|
231
|
+
nonce: env.HEROKU_TEST_RUN_ID || null,
|
|
232
|
+
mergeQueue: false
|
|
219
233
|
}),
|
|
220
234
|
getMergeBaseCommitSha,
|
|
221
235
|
listParentCommits
|
|
@@ -342,19 +356,16 @@ function getPullRequestFromPayload(payload) {
|
|
|
342
356
|
return null;
|
|
343
357
|
}
|
|
344
358
|
function getVercelDeploymentPayload(payload) {
|
|
345
|
-
if (
|
|
346
|
-
return
|
|
347
|
-
}
|
|
348
|
-
if (process.env.GITHUB_EVENT_NAME !== "repository_dispatch") {
|
|
349
|
-
return null;
|
|
359
|
+
if (process.env.GITHUB_EVENT_NAME === "repository_dispatch" && payload && "action" in payload && payload.action === "vercel.deployment.success") {
|
|
360
|
+
return payload;
|
|
350
361
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
if (payload.action
|
|
355
|
-
return
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
function getMergeGroupPayload(payload) {
|
|
365
|
+
if (payload && process.env.GITHUB_EVENT_NAME === "merge_group" && "action" in payload && payload.action === "checks_requested") {
|
|
366
|
+
return payload;
|
|
356
367
|
}
|
|
357
|
-
return
|
|
368
|
+
return null;
|
|
358
369
|
}
|
|
359
370
|
function getSha(context, vercelPayload) {
|
|
360
371
|
if (vercelPayload) {
|
|
@@ -373,6 +384,7 @@ var service4 = {
|
|
|
373
384
|
const { env } = context;
|
|
374
385
|
const payload = readEventPayload(context);
|
|
375
386
|
const vercelPayload = getVercelDeploymentPayload(payload);
|
|
387
|
+
const mergeGroupPayload = getMergeGroupPayload(payload);
|
|
376
388
|
const sha = getSha(context, vercelPayload);
|
|
377
389
|
const pullRequest = payload && !vercelPayload ? getPullRequestFromPayload(payload) : await getPullRequestFromHeadSha(context, sha);
|
|
378
390
|
return {
|
|
@@ -386,7 +398,8 @@ var service4 = {
|
|
|
386
398
|
branch: vercelPayload?.client_payload?.git?.ref || getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null,
|
|
387
399
|
prNumber: pullRequest?.number || null,
|
|
388
400
|
prHeadCommit: pullRequest?.head.sha ?? null,
|
|
389
|
-
prBaseBranch: pullRequest?.base.ref ?? null
|
|
401
|
+
prBaseBranch: pullRequest?.base.ref ?? null,
|
|
402
|
+
mergeQueue: mergeGroupPayload?.action === "checks_requested"
|
|
390
403
|
};
|
|
391
404
|
},
|
|
392
405
|
getMergeBaseCommitSha,
|
|
@@ -434,7 +447,8 @@ var service5 = {
|
|
|
434
447
|
prNumber: getPrNumber2({ env }),
|
|
435
448
|
prHeadCommit: null,
|
|
436
449
|
prBaseBranch: null,
|
|
437
|
-
nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null
|
|
450
|
+
nonce: env.CIRCLE_WORKFLOW_ID || env.CIRCLE_BUILD_NUM || null,
|
|
451
|
+
mergeQueue: false
|
|
438
452
|
};
|
|
439
453
|
},
|
|
440
454
|
getMergeBaseCommitSha,
|
|
@@ -478,7 +492,8 @@ var service6 = {
|
|
|
478
492
|
prNumber: getPrNumber3(ctx),
|
|
479
493
|
prHeadCommit: null,
|
|
480
494
|
prBaseBranch: null,
|
|
481
|
-
nonce: env.TRAVIS_BUILD_ID || null
|
|
495
|
+
nonce: env.TRAVIS_BUILD_ID || null,
|
|
496
|
+
mergeQueue: false
|
|
482
497
|
};
|
|
483
498
|
},
|
|
484
499
|
getMergeBaseCommitSha,
|
|
@@ -515,7 +530,8 @@ var service7 = {
|
|
|
515
530
|
prNumber: null,
|
|
516
531
|
prHeadCommit: null,
|
|
517
532
|
prBaseBranch: null,
|
|
518
|
-
nonce: env.CI_PIPELINE_ID || null
|
|
533
|
+
nonce: env.CI_PIPELINE_ID || null,
|
|
534
|
+
mergeQueue: false
|
|
519
535
|
};
|
|
520
536
|
},
|
|
521
537
|
getMergeBaseCommitSha,
|
|
@@ -548,7 +564,8 @@ var service8 = {
|
|
|
548
564
|
prNumber: null,
|
|
549
565
|
prHeadCommit: null,
|
|
550
566
|
prBaseBranch: null,
|
|
551
|
-
nonce: null
|
|
567
|
+
nonce: null,
|
|
568
|
+
mergeQueue: false
|
|
552
569
|
};
|
|
553
570
|
},
|
|
554
571
|
getMergeBaseCommitSha,
|
|
@@ -840,7 +857,8 @@ async function readConfig(options = {}) {
|
|
|
840
857
|
mode: options.mode || defaultConfig.mode || null,
|
|
841
858
|
ciProvider: ciEnv?.key || null,
|
|
842
859
|
previewBaseUrl: defaultConfig.previewBaseUrl || null,
|
|
843
|
-
skipped: options.skipped ?? defaultConfig.skipped ?? false
|
|
860
|
+
skipped: options.skipped ?? defaultConfig.skipped ?? false,
|
|
861
|
+
mergeQueue: ciEnv?.mergeQueue ?? false
|
|
844
862
|
});
|
|
845
863
|
if (!config.get("branch") || !config.get("commit")) {
|
|
846
864
|
throw new Error(
|
|
@@ -926,14 +944,14 @@ async function finalize(params) {
|
|
|
926
944
|
}
|
|
927
945
|
|
|
928
946
|
// src/upload.ts
|
|
929
|
-
import { createClient as
|
|
947
|
+
import { createClient as createClient3, throwAPIError as throwAPIError3 } from "@argos-ci/api-client";
|
|
930
948
|
|
|
931
949
|
// src/discovery.ts
|
|
932
|
-
import { resolve } from "path";
|
|
950
|
+
import { extname, resolve } from "path";
|
|
933
951
|
import glob from "fast-glob";
|
|
934
|
-
|
|
952
|
+
async function discoverSnapshots(patterns, { root = process.cwd(), ignore } = {}) {
|
|
935
953
|
debug(
|
|
936
|
-
`Discovering
|
|
954
|
+
`Discovering snapshots with patterns: ${Array.isArray(patterns) ? patterns.join(", ") : patterns} in ${root}`
|
|
937
955
|
);
|
|
938
956
|
const matches = await glob(patterns, { onlyFiles: true, ignore, cwd: root });
|
|
939
957
|
return matches.map((match) => {
|
|
@@ -944,7 +962,11 @@ var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}
|
|
|
944
962
|
path
|
|
945
963
|
};
|
|
946
964
|
});
|
|
947
|
-
}
|
|
965
|
+
}
|
|
966
|
+
function checkIsValidImageFile(filename) {
|
|
967
|
+
const lowerFilename = extname(filename).toLowerCase();
|
|
968
|
+
return lowerFilename === ".png" || lowerFilename === ".jpg" || lowerFilename === ".jpeg";
|
|
969
|
+
}
|
|
948
970
|
|
|
949
971
|
// src/optimize.ts
|
|
950
972
|
import { promisify } from "util";
|
|
@@ -954,7 +976,10 @@ import tmp from "tmp";
|
|
|
954
976
|
var tmpFile = promisify(tmp.file);
|
|
955
977
|
var MAX_PIXELS = 8e7;
|
|
956
978
|
var DEFAULT_MAX_WIDTH = 2048;
|
|
957
|
-
|
|
979
|
+
async function optimizeScreenshot(filepath) {
|
|
980
|
+
if (!checkIsValidImageFile(filepath)) {
|
|
981
|
+
return filepath;
|
|
982
|
+
}
|
|
958
983
|
try {
|
|
959
984
|
const [resultFilePath, metadata] = await Promise.all([
|
|
960
985
|
tmpFile(),
|
|
@@ -1010,7 +1035,7 @@ var optimizeScreenshot = async (filepath) => {
|
|
|
1010
1035
|
cause: error
|
|
1011
1036
|
});
|
|
1012
1037
|
}
|
|
1013
|
-
}
|
|
1038
|
+
}
|
|
1014
1039
|
|
|
1015
1040
|
// src/hashing.ts
|
|
1016
1041
|
import { createReadStream } from "fs";
|
|
@@ -1074,6 +1099,54 @@ async function getArgosCoreSDKIdentifier() {
|
|
|
1074
1099
|
return `@argos-ci/core@${version}`;
|
|
1075
1100
|
}
|
|
1076
1101
|
|
|
1102
|
+
// src/mime-type.ts
|
|
1103
|
+
import mime from "mime-types";
|
|
1104
|
+
function getSnapshotMimeType(filepath) {
|
|
1105
|
+
const type = mime.lookup(filepath);
|
|
1106
|
+
if (!type) {
|
|
1107
|
+
throw new Error(`Unable to determine snapshot file type for: ${filepath}`);
|
|
1108
|
+
}
|
|
1109
|
+
return type;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// src/skip.ts
|
|
1113
|
+
import { createClient as createClient2, throwAPIError as throwAPIError2 } from "@argos-ci/api-client";
|
|
1114
|
+
async function skip(params) {
|
|
1115
|
+
const [config, argosSdk] = await Promise.all([
|
|
1116
|
+
getConfigFromOptions(params),
|
|
1117
|
+
getArgosCoreSDKIdentifier()
|
|
1118
|
+
]);
|
|
1119
|
+
const authToken = getAuthToken(config);
|
|
1120
|
+
const apiClient = createClient2({
|
|
1121
|
+
baseUrl: config.apiBaseUrl,
|
|
1122
|
+
authToken
|
|
1123
|
+
});
|
|
1124
|
+
const createBuildResponse = await apiClient.POST("/builds", {
|
|
1125
|
+
body: {
|
|
1126
|
+
commit: config.commit,
|
|
1127
|
+
branch: config.branch,
|
|
1128
|
+
name: config.buildName,
|
|
1129
|
+
mode: config.mode,
|
|
1130
|
+
prNumber: config.prNumber,
|
|
1131
|
+
prHeadCommit: config.prHeadCommit,
|
|
1132
|
+
referenceBranch: config.referenceBranch,
|
|
1133
|
+
referenceCommit: config.referenceCommit,
|
|
1134
|
+
argosSdk,
|
|
1135
|
+
ciProvider: config.ciProvider,
|
|
1136
|
+
runId: config.runId,
|
|
1137
|
+
runAttempt: config.runAttempt,
|
|
1138
|
+
skipped: true,
|
|
1139
|
+
screenshotKeys: [],
|
|
1140
|
+
pwTraceKeys: [],
|
|
1141
|
+
parentCommits: []
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
if (createBuildResponse.error) {
|
|
1145
|
+
throwAPIError2(createBuildResponse.error);
|
|
1146
|
+
}
|
|
1147
|
+
return { build: createBuildResponse.data.build };
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1077
1150
|
// src/upload.ts
|
|
1078
1151
|
var CHUNK_SIZE = 10;
|
|
1079
1152
|
async function upload(params) {
|
|
@@ -1083,52 +1156,29 @@ async function upload(params) {
|
|
|
1083
1156
|
getArgosCoreSDKIdentifier()
|
|
1084
1157
|
]);
|
|
1085
1158
|
const authToken = getAuthToken(config);
|
|
1086
|
-
const apiClient =
|
|
1159
|
+
const apiClient = createClient3({
|
|
1087
1160
|
baseUrl: config.apiBaseUrl,
|
|
1088
1161
|
authToken
|
|
1089
1162
|
});
|
|
1090
1163
|
if (config.skipped) {
|
|
1091
|
-
const
|
|
1092
|
-
|
|
1093
|
-
commit: config.commit,
|
|
1094
|
-
branch: config.branch,
|
|
1095
|
-
name: config.buildName,
|
|
1096
|
-
mode: config.mode,
|
|
1097
|
-
parallel: config.parallel,
|
|
1098
|
-
parallelNonce: config.parallelNonce,
|
|
1099
|
-
prNumber: config.prNumber,
|
|
1100
|
-
prHeadCommit: config.prHeadCommit,
|
|
1101
|
-
referenceBranch: config.referenceBranch,
|
|
1102
|
-
referenceCommit: config.referenceCommit,
|
|
1103
|
-
argosSdk,
|
|
1104
|
-
ciProvider: config.ciProvider,
|
|
1105
|
-
runId: config.runId,
|
|
1106
|
-
runAttempt: config.runAttempt,
|
|
1107
|
-
skipped: true,
|
|
1108
|
-
screenshotKeys: [],
|
|
1109
|
-
pwTraceKeys: [],
|
|
1110
|
-
parentCommits: []
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
if (createBuildResponse2.error) {
|
|
1114
|
-
throwAPIError2(createBuildResponse2.error);
|
|
1115
|
-
}
|
|
1116
|
-
return { build: createBuildResponse2.data.build, screenshots: [] };
|
|
1164
|
+
const { build } = await skip(params);
|
|
1165
|
+
return { build, screenshots: [] };
|
|
1117
1166
|
}
|
|
1118
1167
|
const previewUrlFormatter = params.previewUrl ?? (config.previewBaseUrl ? { baseUrl: config.previewBaseUrl } : void 0);
|
|
1119
|
-
const
|
|
1120
|
-
debug("Using config and files", config,
|
|
1121
|
-
const
|
|
1168
|
+
const globs = params.files ?? ["**/*.{png,jpg,jpeg}"];
|
|
1169
|
+
debug("Using config and files", config, globs);
|
|
1170
|
+
const files = await discoverSnapshots(globs, {
|
|
1122
1171
|
root: params.root,
|
|
1123
1172
|
ignore: params.ignore
|
|
1124
1173
|
});
|
|
1125
|
-
debug("Found
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1174
|
+
debug("Found snapshots", files);
|
|
1175
|
+
const snapshots = await Promise.all(
|
|
1176
|
+
files.map(async (snapshot) => {
|
|
1177
|
+
const contentType = getSnapshotMimeType(snapshot.path);
|
|
1128
1178
|
const [metadata, pwTracePath, optimizedPath] = await Promise.all([
|
|
1129
|
-
readMetadata(
|
|
1130
|
-
getPlaywrightTracePath(
|
|
1131
|
-
optimizeScreenshot(
|
|
1179
|
+
readMetadata(snapshot.path),
|
|
1180
|
+
getPlaywrightTracePath(snapshot.path),
|
|
1181
|
+
contentType.startsWith("image/") ? optimizeScreenshot(snapshot.path) : snapshot.path
|
|
1132
1182
|
]);
|
|
1133
1183
|
const [hash, pwTraceHash] = await Promise.all([
|
|
1134
1184
|
hashFile(optimizedPath),
|
|
@@ -1136,6 +1186,7 @@ async function upload(params) {
|
|
|
1136
1186
|
]);
|
|
1137
1187
|
const threshold = metadata?.transient?.threshold ?? null;
|
|
1138
1188
|
const baseName = metadata?.transient?.baseName ?? null;
|
|
1189
|
+
const parentName = metadata?.transient?.parentName ?? null;
|
|
1139
1190
|
if (metadata) {
|
|
1140
1191
|
delete metadata.transient;
|
|
1141
1192
|
if (metadata.url && previewUrlFormatter) {
|
|
@@ -1146,20 +1197,22 @@ async function upload(params) {
|
|
|
1146
1197
|
}
|
|
1147
1198
|
}
|
|
1148
1199
|
return {
|
|
1149
|
-
...
|
|
1200
|
+
...snapshot,
|
|
1150
1201
|
hash,
|
|
1151
1202
|
optimizedPath,
|
|
1152
1203
|
metadata,
|
|
1153
1204
|
threshold,
|
|
1154
1205
|
baseName,
|
|
1155
|
-
|
|
1206
|
+
parentName,
|
|
1207
|
+
pwTrace: pwTracePath && pwTraceHash ? { path: pwTracePath, hash: pwTraceHash } : null,
|
|
1208
|
+
contentType
|
|
1156
1209
|
};
|
|
1157
1210
|
})
|
|
1158
1211
|
);
|
|
1159
1212
|
debug("Fetch project");
|
|
1160
1213
|
const projectResponse = await apiClient.GET("/project");
|
|
1161
1214
|
if (projectResponse.error) {
|
|
1162
|
-
|
|
1215
|
+
throwAPIError3(projectResponse.error);
|
|
1163
1216
|
}
|
|
1164
1217
|
debug("Project fetched", projectResponse.data);
|
|
1165
1218
|
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
@@ -1196,15 +1249,15 @@ async function upload(params) {
|
|
|
1196
1249
|
return null;
|
|
1197
1250
|
})();
|
|
1198
1251
|
debug("Creating build");
|
|
1199
|
-
const [pwTraceKeys,
|
|
1200
|
-
([pwTraceKeys2,
|
|
1201
|
-
if (
|
|
1202
|
-
pwTraceKeys2.push(
|
|
1252
|
+
const [pwTraceKeys, snapshotKeys] = snapshots.reduce(
|
|
1253
|
+
([pwTraceKeys2, snapshotKeys2], snapshot) => {
|
|
1254
|
+
if (snapshot.pwTrace && !pwTraceKeys2.includes(snapshot.pwTrace.hash)) {
|
|
1255
|
+
pwTraceKeys2.push(snapshot.pwTrace.hash);
|
|
1203
1256
|
}
|
|
1204
|
-
if (!
|
|
1205
|
-
|
|
1257
|
+
if (!snapshotKeys2.includes(snapshot.hash)) {
|
|
1258
|
+
snapshotKeys2.push(snapshot.hash);
|
|
1206
1259
|
}
|
|
1207
|
-
return [pwTraceKeys2,
|
|
1260
|
+
return [pwTraceKeys2, snapshotKeys2];
|
|
1208
1261
|
},
|
|
1209
1262
|
[[], []]
|
|
1210
1263
|
);
|
|
@@ -1216,7 +1269,7 @@ async function upload(params) {
|
|
|
1216
1269
|
mode: config.mode,
|
|
1217
1270
|
parallel: config.parallel,
|
|
1218
1271
|
parallelNonce: config.parallelNonce,
|
|
1219
|
-
screenshotKeys,
|
|
1272
|
+
screenshotKeys: snapshotKeys,
|
|
1220
1273
|
pwTraceKeys,
|
|
1221
1274
|
prNumber: config.prNumber,
|
|
1222
1275
|
prHeadCommit: config.prHeadCommit,
|
|
@@ -1226,36 +1279,37 @@ async function upload(params) {
|
|
|
1226
1279
|
argosSdk,
|
|
1227
1280
|
ciProvider: config.ciProvider,
|
|
1228
1281
|
runId: config.runId,
|
|
1229
|
-
runAttempt: config.runAttempt
|
|
1282
|
+
runAttempt: config.runAttempt,
|
|
1283
|
+
mergeQueue: config.mergeQueue
|
|
1230
1284
|
}
|
|
1231
1285
|
});
|
|
1232
1286
|
if (createBuildResponse.error) {
|
|
1233
|
-
|
|
1287
|
+
throwAPIError3(createBuildResponse.error);
|
|
1234
1288
|
}
|
|
1235
1289
|
const result = createBuildResponse.data;
|
|
1236
1290
|
debug("Got uploads url", result);
|
|
1237
1291
|
const uploadFiles = [
|
|
1238
1292
|
...result.screenshots.map(({ key, putUrl }) => {
|
|
1239
|
-
const
|
|
1240
|
-
if (!
|
|
1241
|
-
throw new Error(`Invariant:
|
|
1293
|
+
const snapshot = snapshots.find((s) => s.hash === key);
|
|
1294
|
+
if (!snapshot) {
|
|
1295
|
+
throw new Error(`Invariant: snapshot with hash ${key} not found`);
|
|
1242
1296
|
}
|
|
1243
1297
|
return {
|
|
1244
1298
|
url: putUrl,
|
|
1245
|
-
path:
|
|
1246
|
-
contentType:
|
|
1299
|
+
path: snapshot.optimizedPath,
|
|
1300
|
+
contentType: snapshot.contentType
|
|
1247
1301
|
};
|
|
1248
1302
|
}),
|
|
1249
1303
|
...result.pwTraces?.map(({ key, putUrl }) => {
|
|
1250
|
-
const
|
|
1304
|
+
const snapshot = snapshots.find(
|
|
1251
1305
|
(s) => s.pwTrace && s.pwTrace.hash === key
|
|
1252
1306
|
);
|
|
1253
|
-
if (!
|
|
1307
|
+
if (!snapshot || !snapshot.pwTrace) {
|
|
1254
1308
|
throw new Error(`Invariant: trace with ${key} not found`);
|
|
1255
1309
|
}
|
|
1256
1310
|
return {
|
|
1257
1311
|
url: putUrl,
|
|
1258
|
-
path:
|
|
1312
|
+
path: snapshot.pwTrace.path,
|
|
1259
1313
|
contentType: "application/json"
|
|
1260
1314
|
};
|
|
1261
1315
|
}) ?? []
|
|
@@ -1269,13 +1323,15 @@ async function upload(params) {
|
|
|
1269
1323
|
}
|
|
1270
1324
|
},
|
|
1271
1325
|
body: {
|
|
1272
|
-
screenshots:
|
|
1273
|
-
key:
|
|
1274
|
-
name:
|
|
1275
|
-
metadata:
|
|
1276
|
-
pwTraceKey:
|
|
1277
|
-
threshold:
|
|
1278
|
-
baseName:
|
|
1326
|
+
screenshots: snapshots.map((snapshot) => ({
|
|
1327
|
+
key: snapshot.hash,
|
|
1328
|
+
name: snapshot.name,
|
|
1329
|
+
metadata: snapshot.metadata,
|
|
1330
|
+
pwTraceKey: snapshot.pwTrace?.hash ?? null,
|
|
1331
|
+
threshold: snapshot.threshold ?? config?.threshold ?? null,
|
|
1332
|
+
baseName: snapshot.baseName,
|
|
1333
|
+
parentName: snapshot.parentName,
|
|
1334
|
+
contentType: snapshot.contentType
|
|
1279
1335
|
})),
|
|
1280
1336
|
parallel: config.parallel,
|
|
1281
1337
|
parallelTotal: config.parallelTotal,
|
|
@@ -1284,9 +1340,9 @@ async function upload(params) {
|
|
|
1284
1340
|
}
|
|
1285
1341
|
});
|
|
1286
1342
|
if (uploadBuildResponse.error) {
|
|
1287
|
-
|
|
1343
|
+
throwAPIError3(uploadBuildResponse.error);
|
|
1288
1344
|
}
|
|
1289
|
-
return { build: uploadBuildResponse.data.build, screenshots };
|
|
1345
|
+
return { build: uploadBuildResponse.data.build, screenshots: snapshots };
|
|
1290
1346
|
}
|
|
1291
1347
|
async function uploadFilesToS3(files) {
|
|
1292
1348
|
debug(`Split files in chunks of ${CHUNK_SIZE}`);
|
|
@@ -1326,5 +1382,6 @@ export {
|
|
|
1326
1382
|
finalize,
|
|
1327
1383
|
getConfigFromOptions,
|
|
1328
1384
|
readConfig,
|
|
1385
|
+
skip,
|
|
1329
1386
|
upload
|
|
1330
1387
|
};
|
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": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"exports": {
|
|
@@ -40,21 +40,23 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/api-client": "0.
|
|
44
|
-
"@argos-ci/util": "3.
|
|
43
|
+
"@argos-ci/api-client": "0.15.0",
|
|
44
|
+
"@argos-ci/util": "3.2.0",
|
|
45
45
|
"convict": "^6.2.4",
|
|
46
46
|
"debug": "^4.4.3",
|
|
47
47
|
"fast-glob": "^3.3.3",
|
|
48
|
-
"
|
|
48
|
+
"mime-types": "^3.0.2",
|
|
49
|
+
"sharp": "^0.34.5",
|
|
49
50
|
"tmp": "^0.2.5"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@octokit/webhooks": "^14.
|
|
53
|
+
"@octokit/webhooks": "^14.2.0",
|
|
53
54
|
"@types/convict": "^6.1.6",
|
|
54
55
|
"@types/debug": "^4.1.12",
|
|
56
|
+
"@types/mime-types": "^3.0.1",
|
|
55
57
|
"@types/tmp": "^0.2.6",
|
|
56
58
|
"@vercel/repository-dispatch": "^0.1.0",
|
|
57
|
-
"msw": "^2.
|
|
59
|
+
"msw": "^2.12.4",
|
|
58
60
|
"vitest": "catalog:"
|
|
59
61
|
},
|
|
60
62
|
"scripts": {
|
|
@@ -65,5 +67,5 @@
|
|
|
65
67
|
"lint": "eslint .",
|
|
66
68
|
"test": "vitest"
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "d460ccc12fe75b1d9389d58647f1906bee7d5e0d"
|
|
69
71
|
}
|
package/LICENSE
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright 2022 Smooth Code
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|