@argos-ci/core 6.1.1 → 6.2.1
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 +79 -9
- package/package.json +4 -4
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import convict from "convict";
|
|
3
|
-
import { execSync } from "node:child_process";
|
|
3
|
+
import { execFileSync, execSync } from "node:child_process";
|
|
4
4
|
import createDebug from "debug";
|
|
5
5
|
import { createReadStream, existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { readFile, stat } from "node:fs/promises";
|
|
@@ -72,7 +72,11 @@ function getRepositoryURL() {
|
|
|
72
72
|
*/
|
|
73
73
|
function gitMergeBase(input) {
|
|
74
74
|
try {
|
|
75
|
-
return
|
|
75
|
+
return execFileSync("git", [
|
|
76
|
+
"merge-base",
|
|
77
|
+
input.head,
|
|
78
|
+
input.base
|
|
79
|
+
]).toString().trim();
|
|
76
80
|
} catch (error) {
|
|
77
81
|
if (checkIsExecError(error) && error.status === 1 && error.stderr.toString() === "") return null;
|
|
78
82
|
throw error;
|
|
@@ -82,7 +86,15 @@ function gitMergeBase(input) {
|
|
|
82
86
|
* Run git fetch with a specific ref and depth.
|
|
83
87
|
*/
|
|
84
88
|
function gitFetch(input) {
|
|
85
|
-
|
|
89
|
+
execFileSync("git", [
|
|
90
|
+
"fetch",
|
|
91
|
+
"--force",
|
|
92
|
+
"--update-head-ok",
|
|
93
|
+
"--depth",
|
|
94
|
+
String(input.depth),
|
|
95
|
+
"origin",
|
|
96
|
+
`${input.ref}:${input.target}`
|
|
97
|
+
]);
|
|
86
98
|
}
|
|
87
99
|
/**
|
|
88
100
|
* Check if an error is an exec error that includes stderr.
|
|
@@ -127,12 +139,20 @@ function getMergeBaseCommitSha$1(input) {
|
|
|
127
139
|
return null;
|
|
128
140
|
}
|
|
129
141
|
function listShas(path, maxCount) {
|
|
130
|
-
|
|
142
|
+
const args = ["log", "--format=%H"];
|
|
143
|
+
if (maxCount) args.push(`--max-count=${maxCount}`);
|
|
144
|
+
args.push(path);
|
|
145
|
+
return execFileSync("git", args).toString().trim().split("\n");
|
|
131
146
|
}
|
|
132
147
|
function listParentCommits$1(input) {
|
|
133
148
|
const limit = 200;
|
|
134
149
|
try {
|
|
135
|
-
|
|
150
|
+
execFileSync("git", [
|
|
151
|
+
"fetch",
|
|
152
|
+
`--depth=${limit}`,
|
|
153
|
+
"origin",
|
|
154
|
+
input.sha
|
|
155
|
+
]);
|
|
136
156
|
} catch (error) {
|
|
137
157
|
if (error instanceof Error && error.message.includes("not our ref")) return [];
|
|
138
158
|
}
|
|
@@ -793,6 +813,12 @@ const schema = {
|
|
|
793
813
|
default: null,
|
|
794
814
|
format: mustBeArgosToken
|
|
795
815
|
},
|
|
816
|
+
project: {
|
|
817
|
+
env: "ARGOS_PROJECT",
|
|
818
|
+
default: null,
|
|
819
|
+
format: String,
|
|
820
|
+
nullable: true
|
|
821
|
+
},
|
|
796
822
|
buildName: {
|
|
797
823
|
env: "ARGOS_BUILD_NAME",
|
|
798
824
|
default: null,
|
|
@@ -942,6 +968,7 @@ async function readConfig(options = {}) {
|
|
|
942
968
|
commit: options.commit || defaultConfig.commit || ciEnv?.commit || null,
|
|
943
969
|
branch: options.branch || defaultConfig.branch || ciEnv?.branch || null,
|
|
944
970
|
token: options.token || defaultConfig.token || null,
|
|
971
|
+
project: options.project || defaultConfig.project || null,
|
|
945
972
|
buildName: options.buildName || defaultConfig.buildName || null,
|
|
946
973
|
prNumber: options.prNumber || defaultConfig.prNumber || ciEnv?.prNumber || null,
|
|
947
974
|
prHeadCommit: defaultConfig.prHeadCommit || ciEnv?.prHeadCommit || null,
|
|
@@ -992,6 +1019,43 @@ const hashFile = async (filepath) => {
|
|
|
992
1019
|
};
|
|
993
1020
|
//#endregion
|
|
994
1021
|
//#region src/s3.ts
|
|
1022
|
+
/**
|
|
1023
|
+
* On failure, S3 responds with an XML body describing the error, e.g.:
|
|
1024
|
+
*
|
|
1025
|
+
* <?xml version="1.0" encoding="UTF-8"?>
|
|
1026
|
+
* <Error>
|
|
1027
|
+
* <Code>AccessDenied</Code>
|
|
1028
|
+
* <Message>Request has expired</Message>
|
|
1029
|
+
* ...
|
|
1030
|
+
* </Error>
|
|
1031
|
+
*
|
|
1032
|
+
* Extract the `Code` and `Message` so the user gets the actual reason for the
|
|
1033
|
+
* failure instead of a generic HTTP status. Returns `null` when the body
|
|
1034
|
+
* cannot be read or does not look like an S3 error document.
|
|
1035
|
+
*/
|
|
1036
|
+
async function readS3ErrorMessage(response) {
|
|
1037
|
+
try {
|
|
1038
|
+
const body = await response.text();
|
|
1039
|
+
const code = body.match(/<Code>([\s\S]*?)<\/Code>/)?.[1]?.trim();
|
|
1040
|
+
const message = body.match(/<Message>([\s\S]*?)<\/Message>/)?.[1]?.trim();
|
|
1041
|
+
if (code && message) return `${code}: ${message}`;
|
|
1042
|
+
return message || code || null;
|
|
1043
|
+
} catch {
|
|
1044
|
+
return null;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Build an error for a failed upload, including the S3 error details when
|
|
1049
|
+
* available so the user can understand why the upload was rejected.
|
|
1050
|
+
*/
|
|
1051
|
+
async function createUploadError(url, response) {
|
|
1052
|
+
const detail = await readS3ErrorMessage(response);
|
|
1053
|
+
const status = response.statusText ? `${response.status} ${response.statusText}` : `${response.status}`;
|
|
1054
|
+
return /* @__PURE__ */ new Error(`Failed to upload file to ${url}: ${status}${detail ? ` — ${detail}` : ""}`);
|
|
1055
|
+
}
|
|
1056
|
+
/**
|
|
1057
|
+
* Upload a file to S3 using a presigned PUT URL.
|
|
1058
|
+
*/
|
|
995
1059
|
async function uploadFile(input) {
|
|
996
1060
|
const file = await readFile(input.path);
|
|
997
1061
|
const response = await fetch(input.url, {
|
|
@@ -1000,8 +1064,13 @@ async function uploadFile(input) {
|
|
|
1000
1064
|
signal: AbortSignal.timeout(3e4),
|
|
1001
1065
|
body: new Uint8Array(file)
|
|
1002
1066
|
});
|
|
1003
|
-
if (!response.ok) throw
|
|
1067
|
+
if (!response.ok) throw await createUploadError(input.url, response);
|
|
1004
1068
|
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Upload a file to S3 using a presigned POST. Unlike a presigned PUT, this
|
|
1071
|
+
* sends the file as multipart form data alongside the policy `fields`
|
|
1072
|
+
* provided by S3.
|
|
1073
|
+
*/
|
|
1005
1074
|
async function uploadFileWithPresignedPost(input) {
|
|
1006
1075
|
const file = await readFile(input.path);
|
|
1007
1076
|
const formData = new FormData();
|
|
@@ -1012,7 +1081,7 @@ async function uploadFileWithPresignedPost(input) {
|
|
|
1012
1081
|
signal: AbortSignal.timeout(3e4),
|
|
1013
1082
|
body: formData
|
|
1014
1083
|
});
|
|
1015
|
-
if (!response.ok) throw
|
|
1084
|
+
if (!response.ok) throw await createUploadError(input.url, response);
|
|
1016
1085
|
}
|
|
1017
1086
|
//#endregion
|
|
1018
1087
|
//#region src/util/chunk.ts
|
|
@@ -1090,7 +1159,7 @@ function isGitHubActionsTokenlessAvailable(config) {
|
|
|
1090
1159
|
* Build a tokenless GitHub Actions bearer token from the CI environment.
|
|
1091
1160
|
*/
|
|
1092
1161
|
function getTokenlessBearerToken(config) {
|
|
1093
|
-
const { originalRepository: repository, jobId, runId, prNumber } = config;
|
|
1162
|
+
const { originalRepository: repository, jobId, runId, prNumber, project } = config;
|
|
1094
1163
|
if (!repository || !jobId || !runId) throw new Error(`Automatic GitHub Actions variables detection failed. Please set ARGOS_TOKEN.`);
|
|
1095
1164
|
const [owner, repo] = repository.split("/");
|
|
1096
1165
|
return `tokenless-github-${base64Encode({
|
|
@@ -1098,7 +1167,8 @@ function getTokenlessBearerToken(config) {
|
|
|
1098
1167
|
repository: repo,
|
|
1099
1168
|
jobId,
|
|
1100
1169
|
runId,
|
|
1101
|
-
prNumber: prNumber ?? void 0
|
|
1170
|
+
prNumber: prNumber ?? void 0,
|
|
1171
|
+
project: project ?? void 0
|
|
1102
1172
|
})}`;
|
|
1103
1173
|
}
|
|
1104
1174
|
/**
|
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.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"debug": "^4.4.3",
|
|
46
46
|
"fast-glob": "^3.3.3",
|
|
47
47
|
"mime-types": "^3.0.2",
|
|
48
|
-
"sharp": "^0.
|
|
49
|
-
"tmp": "^0.2.
|
|
48
|
+
"sharp": "^0.35.2",
|
|
49
|
+
"tmp": "^0.2.7"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@octokit/webhooks": "^14.2.0",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"lint": "eslint .",
|
|
68
68
|
"test": "vitest"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b9d109dc1fa7d98c4fc2cafac2e310fc22b63c43"
|
|
71
71
|
}
|