@argos-ci/core 6.1.0 → 6.2.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 +13 -0
- package/dist/index.mjs +67 -7
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,13 @@ interface Config {
|
|
|
22
22
|
* Argos repository access token.
|
|
23
23
|
*/
|
|
24
24
|
token: string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Argos project slug used for tokenless authentication.
|
|
27
|
+
* Useful to disambiguate when multiple Argos projects are linked
|
|
28
|
+
* to the same repository.
|
|
29
|
+
* @example "my-org/my-project"
|
|
30
|
+
*/
|
|
31
|
+
project: string | null;
|
|
25
32
|
/**
|
|
26
33
|
* Custom build name.
|
|
27
34
|
* Useful for multi-build setups on the same commit.
|
|
@@ -275,6 +282,12 @@ interface UploadParameters {
|
|
|
275
282
|
* Argos repository access token.
|
|
276
283
|
*/
|
|
277
284
|
token?: string;
|
|
285
|
+
/**
|
|
286
|
+
* Argos project slug (`account/project`).
|
|
287
|
+
* Used to disambiguate tokenless authentication when multiple
|
|
288
|
+
* Argos projects are linked to the same repository.
|
|
289
|
+
*/
|
|
290
|
+
project?: string;
|
|
278
291
|
/**
|
|
279
292
|
* Pull request number associated with the build.
|
|
280
293
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -793,6 +793,12 @@ const schema = {
|
|
|
793
793
|
default: null,
|
|
794
794
|
format: mustBeArgosToken
|
|
795
795
|
},
|
|
796
|
+
project: {
|
|
797
|
+
env: "ARGOS_PROJECT",
|
|
798
|
+
default: null,
|
|
799
|
+
format: String,
|
|
800
|
+
nullable: true
|
|
801
|
+
},
|
|
796
802
|
buildName: {
|
|
797
803
|
env: "ARGOS_BUILD_NAME",
|
|
798
804
|
default: null,
|
|
@@ -942,6 +948,7 @@ async function readConfig(options = {}) {
|
|
|
942
948
|
commit: options.commit || defaultConfig.commit || ciEnv?.commit || null,
|
|
943
949
|
branch: options.branch || defaultConfig.branch || ciEnv?.branch || null,
|
|
944
950
|
token: options.token || defaultConfig.token || null,
|
|
951
|
+
project: options.project || defaultConfig.project || null,
|
|
945
952
|
buildName: options.buildName || defaultConfig.buildName || null,
|
|
946
953
|
prNumber: options.prNumber || defaultConfig.prNumber || ciEnv?.prNumber || null,
|
|
947
954
|
prHeadCommit: defaultConfig.prHeadCommit || ciEnv?.prHeadCommit || null,
|
|
@@ -992,6 +999,43 @@ const hashFile = async (filepath) => {
|
|
|
992
999
|
};
|
|
993
1000
|
//#endregion
|
|
994
1001
|
//#region src/s3.ts
|
|
1002
|
+
/**
|
|
1003
|
+
* On failure, S3 responds with an XML body describing the error, e.g.:
|
|
1004
|
+
*
|
|
1005
|
+
* <?xml version="1.0" encoding="UTF-8"?>
|
|
1006
|
+
* <Error>
|
|
1007
|
+
* <Code>AccessDenied</Code>
|
|
1008
|
+
* <Message>Request has expired</Message>
|
|
1009
|
+
* ...
|
|
1010
|
+
* </Error>
|
|
1011
|
+
*
|
|
1012
|
+
* Extract the `Code` and `Message` so the user gets the actual reason for the
|
|
1013
|
+
* failure instead of a generic HTTP status. Returns `null` when the body
|
|
1014
|
+
* cannot be read or does not look like an S3 error document.
|
|
1015
|
+
*/
|
|
1016
|
+
async function readS3ErrorMessage(response) {
|
|
1017
|
+
try {
|
|
1018
|
+
const body = await response.text();
|
|
1019
|
+
const code = body.match(/<Code>([\s\S]*?)<\/Code>/)?.[1]?.trim();
|
|
1020
|
+
const message = body.match(/<Message>([\s\S]*?)<\/Message>/)?.[1]?.trim();
|
|
1021
|
+
if (code && message) return `${code}: ${message}`;
|
|
1022
|
+
return message || code || null;
|
|
1023
|
+
} catch {
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
/**
|
|
1028
|
+
* Build an error for a failed upload, including the S3 error details when
|
|
1029
|
+
* available so the user can understand why the upload was rejected.
|
|
1030
|
+
*/
|
|
1031
|
+
async function createUploadError(url, response) {
|
|
1032
|
+
const detail = await readS3ErrorMessage(response);
|
|
1033
|
+
const status = response.statusText ? `${response.status} ${response.statusText}` : `${response.status}`;
|
|
1034
|
+
return /* @__PURE__ */ new Error(`Failed to upload file to ${url}: ${status}${detail ? ` — ${detail}` : ""}`);
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Upload a file to S3 using a presigned PUT URL.
|
|
1038
|
+
*/
|
|
995
1039
|
async function uploadFile(input) {
|
|
996
1040
|
const file = await readFile(input.path);
|
|
997
1041
|
const response = await fetch(input.url, {
|
|
@@ -1000,8 +1044,13 @@ async function uploadFile(input) {
|
|
|
1000
1044
|
signal: AbortSignal.timeout(3e4),
|
|
1001
1045
|
body: new Uint8Array(file)
|
|
1002
1046
|
});
|
|
1003
|
-
if (!response.ok) throw
|
|
1047
|
+
if (!response.ok) throw await createUploadError(input.url, response);
|
|
1004
1048
|
}
|
|
1049
|
+
/**
|
|
1050
|
+
* Upload a file to S3 using a presigned POST. Unlike a presigned PUT, this
|
|
1051
|
+
* sends the file as multipart form data alongside the policy `fields`
|
|
1052
|
+
* provided by S3.
|
|
1053
|
+
*/
|
|
1005
1054
|
async function uploadFileWithPresignedPost(input) {
|
|
1006
1055
|
const file = await readFile(input.path);
|
|
1007
1056
|
const formData = new FormData();
|
|
@@ -1012,7 +1061,7 @@ async function uploadFileWithPresignedPost(input) {
|
|
|
1012
1061
|
signal: AbortSignal.timeout(3e4),
|
|
1013
1062
|
body: formData
|
|
1014
1063
|
});
|
|
1015
|
-
if (!response.ok) throw
|
|
1064
|
+
if (!response.ok) throw await createUploadError(input.url, response);
|
|
1016
1065
|
}
|
|
1017
1066
|
//#endregion
|
|
1018
1067
|
//#region src/util/chunk.ts
|
|
@@ -1028,6 +1077,15 @@ const chunk = (collection, size) => {
|
|
|
1028
1077
|
}
|
|
1029
1078
|
return result;
|
|
1030
1079
|
};
|
|
1080
|
+
/**
|
|
1081
|
+
* Map over a collection asynchronously, processing at most `size` items
|
|
1082
|
+
* concurrently to limit memory pressure.
|
|
1083
|
+
*/
|
|
1084
|
+
async function mapInChunks(collection, size, mapper) {
|
|
1085
|
+
const results = [];
|
|
1086
|
+
for (const items of chunk(collection, size)) results.push(...await Promise.all(items.map(mapper)));
|
|
1087
|
+
return results;
|
|
1088
|
+
}
|
|
1031
1089
|
//#endregion
|
|
1032
1090
|
//#region src/github-actions-oidc.ts
|
|
1033
1091
|
/**
|
|
@@ -1081,7 +1139,7 @@ function isGitHubActionsTokenlessAvailable(config) {
|
|
|
1081
1139
|
* Build a tokenless GitHub Actions bearer token from the CI environment.
|
|
1082
1140
|
*/
|
|
1083
1141
|
function getTokenlessBearerToken(config) {
|
|
1084
|
-
const { originalRepository: repository, jobId, runId, prNumber } = config;
|
|
1142
|
+
const { originalRepository: repository, jobId, runId, prNumber, project } = config;
|
|
1085
1143
|
if (!repository || !jobId || !runId) throw new Error(`Automatic GitHub Actions variables detection failed. Please set ARGOS_TOKEN.`);
|
|
1086
1144
|
const [owner, repo] = repository.split("/");
|
|
1087
1145
|
return `tokenless-github-${base64Encode({
|
|
@@ -1089,7 +1147,8 @@ function getTokenlessBearerToken(config) {
|
|
|
1089
1147
|
repository: repo,
|
|
1090
1148
|
jobId,
|
|
1091
1149
|
runId,
|
|
1092
|
-
prNumber: prNumber ?? void 0
|
|
1150
|
+
prNumber: prNumber ?? void 0,
|
|
1151
|
+
project: project ?? void 0
|
|
1093
1152
|
})}`;
|
|
1094
1153
|
}
|
|
1095
1154
|
/**
|
|
@@ -1370,7 +1429,8 @@ async function skip(params) {
|
|
|
1370
1429
|
//#endregion
|
|
1371
1430
|
//#region src/upload.ts
|
|
1372
1431
|
/**
|
|
1373
|
-
* Size of the chunks used to upload screenshots
|
|
1432
|
+
* Size of the chunks used to process and upload screenshots.
|
|
1433
|
+
* Limits concurrency to avoid memory pressure when handling many screenshots.
|
|
1374
1434
|
*/
|
|
1375
1435
|
const CHUNK_SIZE = 10;
|
|
1376
1436
|
const PLAYWRIGHT_TRACE_CONTENT_TYPE = "application/zip";
|
|
@@ -1400,7 +1460,7 @@ async function upload(params) {
|
|
|
1400
1460
|
ignore: params.ignore
|
|
1401
1461
|
});
|
|
1402
1462
|
debug("Found snapshots", files);
|
|
1403
|
-
const snapshots = await
|
|
1463
|
+
const snapshots = await mapInChunks(files, CHUNK_SIZE, async (snapshot) => {
|
|
1404
1464
|
const contentType = getSnapshotMimeType(snapshot.path);
|
|
1405
1465
|
const [metadata, pwTracePath, optimizedPath] = await Promise.all([
|
|
1406
1466
|
readMetadata(snapshot.path),
|
|
@@ -1429,7 +1489,7 @@ async function upload(params) {
|
|
|
1429
1489
|
} : null,
|
|
1430
1490
|
contentType
|
|
1431
1491
|
};
|
|
1432
|
-
})
|
|
1492
|
+
});
|
|
1433
1493
|
debug("Fetch project");
|
|
1434
1494
|
const projectResponse = await apiClient.GET("/project");
|
|
1435
1495
|
if (projectResponse.error) throwAPIError(projectResponse.error);
|
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.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"lint": "eslint .",
|
|
68
68
|
"test": "vitest"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "1787fe78cba46f408493e02114150f2d73f47fa4"
|
|
71
71
|
}
|