@argos-ci/core 6.1.1 → 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 +54 -4
- 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
|
|
@@ -1090,7 +1139,7 @@ function isGitHubActionsTokenlessAvailable(config) {
|
|
|
1090
1139
|
* Build a tokenless GitHub Actions bearer token from the CI environment.
|
|
1091
1140
|
*/
|
|
1092
1141
|
function getTokenlessBearerToken(config) {
|
|
1093
|
-
const { originalRepository: repository, jobId, runId, prNumber } = config;
|
|
1142
|
+
const { originalRepository: repository, jobId, runId, prNumber, project } = config;
|
|
1094
1143
|
if (!repository || !jobId || !runId) throw new Error(`Automatic GitHub Actions variables detection failed. Please set ARGOS_TOKEN.`);
|
|
1095
1144
|
const [owner, repo] = repository.split("/");
|
|
1096
1145
|
return `tokenless-github-${base64Encode({
|
|
@@ -1098,7 +1147,8 @@ function getTokenlessBearerToken(config) {
|
|
|
1098
1147
|
repository: repo,
|
|
1099
1148
|
jobId,
|
|
1100
1149
|
runId,
|
|
1101
|
-
prNumber: prNumber ?? void 0
|
|
1150
|
+
prNumber: prNumber ?? void 0,
|
|
1151
|
+
project: project ?? void 0
|
|
1102
1152
|
})}`;
|
|
1103
1153
|
}
|
|
1104
1154
|
/**
|
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
|
}
|