@argos-ci/core 6.2.1 → 6.2.3
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.mjs +62 -27
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import convict from "convict";
|
|
3
|
-
import { execFileSync, execSync } from "node:child_process";
|
|
3
|
+
import { execFile, execFileSync, execSync } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import pRetry from "p-retry";
|
|
4
6
|
import createDebug from "debug";
|
|
5
7
|
import { createReadStream, existsSync, readFileSync } from "node:fs";
|
|
6
8
|
import { readFile, stat } from "node:fs/promises";
|
|
@@ -9,7 +11,6 @@ import glob from "fast-glob";
|
|
|
9
11
|
import mime from "mime-types";
|
|
10
12
|
import { createClient, throwAPIError } from "@argos-ci/api-client";
|
|
11
13
|
import { createHash } from "node:crypto";
|
|
12
|
-
import { promisify } from "node:util";
|
|
13
14
|
import sharp from "sharp";
|
|
14
15
|
import tmp from "tmp";
|
|
15
16
|
import { getPlaywrightTracePath, readMetadata, readVersionFromPackage } from "@argos-ci/util";
|
|
@@ -25,6 +26,7 @@ const debugTimeEnd = (arg) => {
|
|
|
25
26
|
};
|
|
26
27
|
//#endregion
|
|
27
28
|
//#region src/ci-environment/git.ts
|
|
29
|
+
const execFileAsync = promisify(execFile);
|
|
28
30
|
/**
|
|
29
31
|
* Check if the current directory is a git repository.
|
|
30
32
|
*/
|
|
@@ -83,11 +85,45 @@ function gitMergeBase(input) {
|
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
/**
|
|
88
|
+
* Combine an error's message and stderr into a single searchable string.
|
|
89
|
+
*/
|
|
90
|
+
function getGitErrorOutput(error) {
|
|
91
|
+
if (!(error instanceof Error)) return "";
|
|
92
|
+
const stderr = "stderr" in error ? String(error.stderr ?? "") : "";
|
|
93
|
+
return `${error.message}\n${stderr}`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Check whether a git error is a `.git/*.lock` contention error.
|
|
97
|
+
* This happens when another git process is running concurrently (e.g. parallel
|
|
98
|
+
* CI shards fetching the same repository) or when a stale lock was left behind
|
|
99
|
+
* by a crashed git process.
|
|
100
|
+
*/
|
|
101
|
+
function checkIsGitLockError(error) {
|
|
102
|
+
const output = getGitErrorOutput(error);
|
|
103
|
+
return output.includes(".lock': File exists") || output.includes("Another git process seems to be running");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Run `git fetch` with the given arguments.
|
|
107
|
+
*
|
|
108
|
+
* Retries on lock contention (`.git/shallow.lock` "File exists") with an
|
|
109
|
+
* exponential backoff, since this is usually a transient conflict with another
|
|
110
|
+
* git process and resolves once that process releases the lock.
|
|
111
|
+
*/
|
|
112
|
+
function runGitFetch(args) {
|
|
113
|
+
return pRetry(() => execFileAsync("git", ["fetch", ...args]), {
|
|
114
|
+
retries: 3,
|
|
115
|
+
minTimeout: 500,
|
|
116
|
+
shouldRetry: ({ error }) => checkIsGitLockError(error),
|
|
117
|
+
onFailedAttempt: ({ error, retriesLeft, retryDelay }) => {
|
|
118
|
+
if (checkIsGitLockError(error) && retriesLeft > 0) debug(`git fetch failed on lock contention, retrying in ${retryDelay}ms (${retriesLeft} left)`);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
86
123
|
* Run git fetch with a specific ref and depth.
|
|
87
124
|
*/
|
|
88
|
-
function gitFetch(input) {
|
|
89
|
-
|
|
90
|
-
"fetch",
|
|
125
|
+
async function gitFetch(input) {
|
|
126
|
+
await runGitFetch([
|
|
91
127
|
"--force",
|
|
92
128
|
"--update-head-ok",
|
|
93
129
|
"--depth",
|
|
@@ -107,17 +143,17 @@ function checkIsExecError(error) {
|
|
|
107
143
|
* Fetch both base and head with depth and then run merge base.
|
|
108
144
|
* Try to find a merge base with a depth of 1000 max.
|
|
109
145
|
*/
|
|
110
|
-
function getMergeBaseCommitSha$1(input) {
|
|
146
|
+
async function getMergeBaseCommitSha$1(input) {
|
|
111
147
|
let depth = 200;
|
|
112
148
|
const argosBaseRef = `argos/${input.base}`;
|
|
113
149
|
const argosHeadRef = `argos/${input.head}`;
|
|
114
150
|
while (depth < 1e3) {
|
|
115
|
-
gitFetch({
|
|
151
|
+
await gitFetch({
|
|
116
152
|
ref: input.head,
|
|
117
153
|
depth,
|
|
118
154
|
target: argosHeadRef
|
|
119
155
|
});
|
|
120
|
-
gitFetch({
|
|
156
|
+
await gitFetch({
|
|
121
157
|
ref: input.base,
|
|
122
158
|
depth,
|
|
123
159
|
target: argosBaseRef
|
|
@@ -144,17 +180,16 @@ function listShas(path, maxCount) {
|
|
|
144
180
|
args.push(path);
|
|
145
181
|
return execFileSync("git", args).toString().trim().split("\n");
|
|
146
182
|
}
|
|
147
|
-
function listParentCommits$1(input) {
|
|
183
|
+
async function listParentCommits$1(input) {
|
|
148
184
|
const limit = 200;
|
|
149
185
|
try {
|
|
150
|
-
|
|
151
|
-
"fetch",
|
|
186
|
+
await runGitFetch([
|
|
152
187
|
`--depth=${limit}`,
|
|
153
188
|
"origin",
|
|
154
189
|
input.sha
|
|
155
190
|
]);
|
|
156
191
|
} catch (error) {
|
|
157
|
-
if (error
|
|
192
|
+
if (getGitErrorOutput(error).includes("not our ref")) return [];
|
|
158
193
|
}
|
|
159
194
|
return listShas(input.sha, limit);
|
|
160
195
|
}
|
|
@@ -704,7 +739,7 @@ function getCiService(context) {
|
|
|
704
739
|
function getMergeBaseCommitSha(input) {
|
|
705
740
|
const context = createContext();
|
|
706
741
|
const service = getCiService(context);
|
|
707
|
-
if (!service) return null;
|
|
742
|
+
if (!service) return Promise.resolve(null);
|
|
708
743
|
return service.getMergeBaseCommitSha(input, context);
|
|
709
744
|
}
|
|
710
745
|
/**
|
|
@@ -713,7 +748,7 @@ function getMergeBaseCommitSha(input) {
|
|
|
713
748
|
function listParentCommits(input) {
|
|
714
749
|
const context = createContext();
|
|
715
750
|
const service = getCiService(context);
|
|
716
|
-
if (!service) return null;
|
|
751
|
+
if (!service) return Promise.resolve(null);
|
|
717
752
|
return service.listParentCommits(input, context);
|
|
718
753
|
}
|
|
719
754
|
/**
|
|
@@ -1143,7 +1178,7 @@ async function exchangeGitHubActionsOidcToken(args) {
|
|
|
1143
1178
|
branch: config.branch,
|
|
1144
1179
|
pullRequestNumber: config.prNumber ?? void 0
|
|
1145
1180
|
} });
|
|
1146
|
-
if (result.error) throwAPIError(result.error);
|
|
1181
|
+
if (result.error) throwAPIError(result.error, result.response);
|
|
1147
1182
|
return result.data.token;
|
|
1148
1183
|
}
|
|
1149
1184
|
//#endregion
|
|
@@ -1183,7 +1218,7 @@ async function exchangeGitHubActionsTokenlessToken(args) {
|
|
|
1183
1218
|
commit,
|
|
1184
1219
|
branch: config.branch
|
|
1185
1220
|
} });
|
|
1186
|
-
if (result.error) throwAPIError(result.error);
|
|
1221
|
+
if (result.error) throwAPIError(result.error, result.response);
|
|
1187
1222
|
return result.data.token;
|
|
1188
1223
|
}
|
|
1189
1224
|
//#endregion
|
|
@@ -1270,7 +1305,7 @@ async function deploy(params) {
|
|
|
1270
1305
|
contentType
|
|
1271
1306
|
}))
|
|
1272
1307
|
} });
|
|
1273
|
-
if (createResponse.error) throwAPIError(createResponse.error);
|
|
1308
|
+
if (createResponse.error) throwAPIError(createResponse.error, createResponse.response);
|
|
1274
1309
|
const { deploymentId, uploadFiles: filesToUpload } = createResponse.data;
|
|
1275
1310
|
debug(`Deployment created: ${deploymentId}, files to upload: ${filesToUpload.length}`);
|
|
1276
1311
|
const uploadChunks = chunk(filesToUpload.map(({ path, uploadUrl }) => {
|
|
@@ -1294,7 +1329,7 @@ async function deploy(params) {
|
|
|
1294
1329
|
}
|
|
1295
1330
|
debug("Finalizing deployment");
|
|
1296
1331
|
const finalizeResponse = await apiClient.POST("/deployments/{deploymentId}/finalize", { params: { path: { deploymentId } } });
|
|
1297
|
-
if (finalizeResponse.error) throwAPIError(finalizeResponse.error);
|
|
1332
|
+
if (finalizeResponse.error) throwAPIError(finalizeResponse.error, finalizeResponse.response);
|
|
1298
1333
|
return finalizeResponse.data;
|
|
1299
1334
|
}
|
|
1300
1335
|
//#endregion
|
|
@@ -1311,7 +1346,7 @@ async function finalize(params) {
|
|
|
1311
1346
|
});
|
|
1312
1347
|
if (!config.parallelNonce) throw new Error("parallel.nonce is required to finalize the build");
|
|
1313
1348
|
const finalizeBuildsResult = await apiClient.POST("/builds/finalize", { body: { parallelNonce: config.parallelNonce } });
|
|
1314
|
-
if (finalizeBuildsResult.error) throwAPIError(finalizeBuildsResult.error);
|
|
1349
|
+
if (finalizeBuildsResult.error) throwAPIError(finalizeBuildsResult.error, finalizeBuildsResult.response);
|
|
1315
1350
|
return finalizeBuildsResult.data;
|
|
1316
1351
|
}
|
|
1317
1352
|
//#endregion
|
|
@@ -1443,7 +1478,7 @@ async function skip(params) {
|
|
|
1443
1478
|
pwTraceKeys: [],
|
|
1444
1479
|
parentCommits: []
|
|
1445
1480
|
} });
|
|
1446
|
-
if (createBuildResponse.error) throwAPIError(createBuildResponse.error);
|
|
1481
|
+
if (createBuildResponse.error) throwAPIError(createBuildResponse.error, createBuildResponse.response);
|
|
1447
1482
|
return { build: createBuildResponse.data.build };
|
|
1448
1483
|
}
|
|
1449
1484
|
//#endregion
|
|
@@ -1512,16 +1547,16 @@ async function upload(params) {
|
|
|
1512
1547
|
});
|
|
1513
1548
|
debug("Fetch project");
|
|
1514
1549
|
const projectResponse = await apiClient.GET("/project");
|
|
1515
|
-
if (projectResponse.error) throwAPIError(projectResponse.error);
|
|
1550
|
+
if (projectResponse.error) throwAPIError(projectResponse.error, projectResponse.response);
|
|
1516
1551
|
debug("Project fetched", projectResponse.data);
|
|
1517
1552
|
const { defaultBaseBranch, hasRemoteContentAccess } = projectResponse.data;
|
|
1518
|
-
const referenceCommit = (() => {
|
|
1553
|
+
const referenceCommit = await (async () => {
|
|
1519
1554
|
if (config.referenceCommit) {
|
|
1520
1555
|
debug("Found reference commit in config", config.referenceCommit);
|
|
1521
1556
|
return config.referenceCommit;
|
|
1522
1557
|
}
|
|
1523
1558
|
if (hasRemoteContentAccess) return null;
|
|
1524
|
-
const sha = getMergeBaseCommitSha({
|
|
1559
|
+
const sha = await getMergeBaseCommitSha({
|
|
1525
1560
|
base: config.referenceBranch || config.prBaseBranch || defaultBaseBranch,
|
|
1526
1561
|
head: config.branch
|
|
1527
1562
|
});
|
|
@@ -1529,10 +1564,10 @@ async function upload(params) {
|
|
|
1529
1564
|
else debug("No merge base found");
|
|
1530
1565
|
return sha;
|
|
1531
1566
|
})();
|
|
1532
|
-
const parentCommits = (() => {
|
|
1567
|
+
const parentCommits = await (async () => {
|
|
1533
1568
|
if (hasRemoteContentAccess) return null;
|
|
1534
1569
|
if (referenceCommit) {
|
|
1535
|
-
const commits = listParentCommits({ sha: referenceCommit });
|
|
1570
|
+
const commits = await listParentCommits({ sha: referenceCommit });
|
|
1536
1571
|
if (commits) debug("Found parent commits", commits);
|
|
1537
1572
|
else debug("No parent commits found");
|
|
1538
1573
|
return commits;
|
|
@@ -1571,7 +1606,7 @@ async function upload(params) {
|
|
|
1571
1606
|
mergeQueuePrNumbers: config.mergeQueuePrNumbers,
|
|
1572
1607
|
subset: config.subset
|
|
1573
1608
|
} });
|
|
1574
|
-
if (createBuildResponse.error) throwAPIError(createBuildResponse.error);
|
|
1609
|
+
if (createBuildResponse.error) throwAPIError(createBuildResponse.error, createBuildResponse.response);
|
|
1575
1610
|
const result = createBuildResponse.data;
|
|
1576
1611
|
debug("Got uploads url", result);
|
|
1577
1612
|
await uploadFilesToS3([...result.screenshots.map((upload) => {
|
|
@@ -1609,7 +1644,7 @@ async function upload(params) {
|
|
|
1609
1644
|
metadata: params.metadata
|
|
1610
1645
|
}
|
|
1611
1646
|
});
|
|
1612
|
-
if (uploadBuildResponse.error) throwAPIError(uploadBuildResponse.error);
|
|
1647
|
+
if (uploadBuildResponse.error) throwAPIError(uploadBuildResponse.error, uploadBuildResponse.response);
|
|
1613
1648
|
return {
|
|
1614
1649
|
build: uploadBuildResponse.data.build,
|
|
1615
1650
|
screenshots: snapshots
|
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.2.
|
|
4
|
+
"version": "6.2.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -39,12 +39,13 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@argos-ci/api-client": "0.22.
|
|
42
|
+
"@argos-ci/api-client": "0.22.1",
|
|
43
43
|
"@argos-ci/util": "4.0.0",
|
|
44
44
|
"convict": "^6.2.5",
|
|
45
45
|
"debug": "^4.4.3",
|
|
46
46
|
"fast-glob": "^3.3.3",
|
|
47
47
|
"mime-types": "^3.0.2",
|
|
48
|
+
"p-retry": "^8.0.0",
|
|
48
49
|
"sharp": "^0.35.2",
|
|
49
50
|
"tmp": "^0.2.7"
|
|
50
51
|
},
|
|
@@ -67,5 +68,5 @@
|
|
|
67
68
|
"lint": "eslint .",
|
|
68
69
|
"test": "vitest"
|
|
69
70
|
},
|
|
70
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "70ab43ebd8cbeeb25bb95e978556bbe754b8c073"
|
|
71
72
|
}
|