@argos-ci/core 3.2.3 → 4.0.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.js +51 -47
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createClient, throwAPIError } from "@argos-ci/api-client";
|
|
|
5
5
|
import convict from "convict";
|
|
6
6
|
|
|
7
7
|
// src/ci-environment/git.ts
|
|
8
|
-
import { execSync } from "
|
|
8
|
+
import { execSync } from "child_process";
|
|
9
9
|
|
|
10
10
|
// src/debug.ts
|
|
11
11
|
import createDebug from "debug";
|
|
@@ -214,8 +214,7 @@ var service3 = {
|
|
|
214
214
|
var heroku_default = service3;
|
|
215
215
|
|
|
216
216
|
// src/ci-environment/services/github-actions.ts
|
|
217
|
-
import { existsSync, readFileSync } from "
|
|
218
|
-
import axios from "axios";
|
|
217
|
+
import { existsSync, readFileSync } from "fs";
|
|
219
218
|
async function getPullRequestFromHeadSha({ env }, sha) {
|
|
220
219
|
debug("Fetching pull request number from head sha", sha);
|
|
221
220
|
if (!env.GITHUB_REPOSITORY) {
|
|
@@ -241,27 +240,32 @@ DISABLE_GITHUB_TOKEN_WARNING: true
|
|
|
241
240
|
return null;
|
|
242
241
|
}
|
|
243
242
|
try {
|
|
244
|
-
const
|
|
245
|
-
`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls
|
|
246
|
-
{
|
|
247
|
-
params: {
|
|
248
|
-
state: "open",
|
|
249
|
-
sort: "updated",
|
|
250
|
-
per_page: 30,
|
|
251
|
-
page: 1
|
|
252
|
-
},
|
|
253
|
-
headers: {
|
|
254
|
-
Accept: "application/vnd.github+json",
|
|
255
|
-
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
|
256
|
-
"X-GitHub-Api-Version": "2022-11-28"
|
|
257
|
-
}
|
|
258
|
-
}
|
|
243
|
+
const url = new URL(
|
|
244
|
+
`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls`
|
|
259
245
|
);
|
|
260
|
-
|
|
246
|
+
url.search = new URLSearchParams({
|
|
247
|
+
state: "open",
|
|
248
|
+
sort: "updated",
|
|
249
|
+
per_page: "30",
|
|
250
|
+
page: "1"
|
|
251
|
+
}).toString();
|
|
252
|
+
const response = await fetch(url, {
|
|
253
|
+
headers: {
|
|
254
|
+
Accept: "application/vnd.github+json",
|
|
255
|
+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
|
256
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
257
|
+
},
|
|
258
|
+
signal: AbortSignal.timeout(1e4)
|
|
259
|
+
});
|
|
260
|
+
if (!response.ok) {
|
|
261
|
+
throw new Error(`Failed to fetch pull requests: ${response.statusText}`);
|
|
262
|
+
}
|
|
263
|
+
const result = await response.json();
|
|
264
|
+
if (result.length === 0) {
|
|
261
265
|
debug("Aborting because no pull request found");
|
|
262
266
|
return null;
|
|
263
267
|
}
|
|
264
|
-
const matchingPr = result.
|
|
268
|
+
const matchingPr = result.find((pr) => pr.head.sha === sha);
|
|
265
269
|
if (matchingPr) {
|
|
266
270
|
debug("Pull request found", matchingPr);
|
|
267
271
|
return matchingPr;
|
|
@@ -688,11 +692,6 @@ var schema = {
|
|
|
688
692
|
default: null,
|
|
689
693
|
nullable: true
|
|
690
694
|
},
|
|
691
|
-
owner: {
|
|
692
|
-
format: String,
|
|
693
|
-
default: null,
|
|
694
|
-
nullable: true
|
|
695
|
-
},
|
|
696
695
|
repository: {
|
|
697
696
|
format: String,
|
|
698
697
|
default: null,
|
|
@@ -752,7 +751,7 @@ async function readConfig(options = {}) {
|
|
|
752
751
|
}
|
|
753
752
|
|
|
754
753
|
// src/discovery.ts
|
|
755
|
-
import { resolve } from "
|
|
754
|
+
import { resolve } from "path";
|
|
756
755
|
import glob from "fast-glob";
|
|
757
756
|
var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}) => {
|
|
758
757
|
debug(
|
|
@@ -770,8 +769,8 @@ var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}
|
|
|
770
769
|
};
|
|
771
770
|
|
|
772
771
|
// src/optimize.ts
|
|
773
|
-
import { promisify } from "
|
|
774
|
-
import { basename } from "
|
|
772
|
+
import { promisify } from "util";
|
|
773
|
+
import { basename } from "path";
|
|
775
774
|
import sharp from "sharp";
|
|
776
775
|
import tmp from "tmp";
|
|
777
776
|
var tmpFile = promisify(tmp.file);
|
|
@@ -836,8 +835,8 @@ var optimizeScreenshot = async (filepath) => {
|
|
|
836
835
|
};
|
|
837
836
|
|
|
838
837
|
// src/hashing.ts
|
|
839
|
-
import { createReadStream } from "
|
|
840
|
-
import { createHash } from "
|
|
838
|
+
import { createReadStream } from "fs";
|
|
839
|
+
import { createHash } from "crypto";
|
|
841
840
|
var hashFile = async (filepath) => {
|
|
842
841
|
const fileStream = createReadStream(filepath);
|
|
843
842
|
const hash = createHash("sha256");
|
|
@@ -855,7 +854,6 @@ var base64Encode = (obj) => Buffer.from(JSON.stringify(obj), "utf8").toString("b
|
|
|
855
854
|
function getAuthToken({
|
|
856
855
|
token,
|
|
857
856
|
ciProvider,
|
|
858
|
-
owner,
|
|
859
857
|
repository,
|
|
860
858
|
jobId,
|
|
861
859
|
runId,
|
|
@@ -866,17 +864,18 @@ function getAuthToken({
|
|
|
866
864
|
}
|
|
867
865
|
switch (ciProvider) {
|
|
868
866
|
case "github-actions": {
|
|
869
|
-
if (!
|
|
867
|
+
if (!repository || !jobId || !runId) {
|
|
870
868
|
throw new Error(
|
|
871
869
|
`Automatic GitHub Actions variables detection failed. Please add the 'ARGOS_TOKEN'`
|
|
872
870
|
);
|
|
873
871
|
}
|
|
872
|
+
const [owner, repo] = repository.split("/");
|
|
874
873
|
return `tokenless-github-${base64Encode({
|
|
875
874
|
owner,
|
|
876
|
-
repository,
|
|
875
|
+
repository: repo,
|
|
877
876
|
jobId,
|
|
878
877
|
runId,
|
|
879
|
-
prNumber
|
|
878
|
+
prNumber: prNumber ?? void 0
|
|
880
879
|
})}`;
|
|
881
880
|
}
|
|
882
881
|
default:
|
|
@@ -885,19 +884,24 @@ function getAuthToken({
|
|
|
885
884
|
}
|
|
886
885
|
|
|
887
886
|
// src/s3.ts
|
|
888
|
-
import { readFile } from "
|
|
889
|
-
|
|
890
|
-
var upload = async (input) => {
|
|
887
|
+
import { readFile } from "fs/promises";
|
|
888
|
+
async function uploadFile(input) {
|
|
891
889
|
const file = await readFile(input.path);
|
|
892
|
-
await
|
|
890
|
+
const response = await fetch(input.url, {
|
|
893
891
|
method: "PUT",
|
|
894
|
-
url: input.url,
|
|
895
|
-
data: file,
|
|
896
892
|
headers: {
|
|
897
|
-
"Content-Type": input.contentType
|
|
898
|
-
|
|
893
|
+
"Content-Type": input.contentType,
|
|
894
|
+
"Content-Length": file.length.toString()
|
|
895
|
+
},
|
|
896
|
+
signal: AbortSignal.timeout(3e4),
|
|
897
|
+
body: new Uint8Array(file)
|
|
899
898
|
});
|
|
900
|
-
|
|
899
|
+
if (!response.ok) {
|
|
900
|
+
throw new Error(
|
|
901
|
+
`Failed to upload file to ${input.url}: ${response.status} ${response.statusText}`
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
901
905
|
|
|
902
906
|
// src/util/chunk.ts
|
|
903
907
|
var chunk = (collection, size) => {
|
|
@@ -915,7 +919,7 @@ import { getPlaywrightTracePath, readMetadata } from "@argos-ci/util";
|
|
|
915
919
|
|
|
916
920
|
// src/version.ts
|
|
917
921
|
import { readVersionFromPackage } from "@argos-ci/util";
|
|
918
|
-
import { createRequire } from "
|
|
922
|
+
import { createRequire } from "module";
|
|
919
923
|
var require2 = createRequire(import.meta.url);
|
|
920
924
|
async function getArgosCoreSDKIdentifier() {
|
|
921
925
|
const pkgPath = require2.resolve("@argos-ci/core/package.json");
|
|
@@ -951,7 +955,7 @@ async function uploadFilesToS3(files) {
|
|
|
951
955
|
}
|
|
952
956
|
await Promise.all(
|
|
953
957
|
chunk2.map(async ({ url, path, contentType }) => {
|
|
954
|
-
await
|
|
958
|
+
await uploadFile({
|
|
955
959
|
url,
|
|
956
960
|
path,
|
|
957
961
|
contentType
|
|
@@ -971,7 +975,7 @@ function formatPreviewUrl(url, formatter) {
|
|
|
971
975
|
formatter.baseUrl
|
|
972
976
|
).href;
|
|
973
977
|
}
|
|
974
|
-
async function
|
|
978
|
+
async function upload(params) {
|
|
975
979
|
debug("Starting upload with params", params);
|
|
976
980
|
const [config, argosSdk] = await Promise.all([
|
|
977
981
|
getConfigFromOptions(params),
|
|
@@ -1183,5 +1187,5 @@ async function finalize(params) {
|
|
|
1183
1187
|
export {
|
|
1184
1188
|
finalize,
|
|
1185
1189
|
readConfig,
|
|
1186
|
-
|
|
1190
|
+
upload
|
|
1187
1191
|
};
|
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": "4.0.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"exports": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "https://github.com/argos-ci/argos-javascript/issues"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
28
|
},
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"keywords": [
|
|
@@ -40,21 +40,20 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/api-client": "0.
|
|
44
|
-
"@argos-ci/util": "
|
|
45
|
-
"axios": "^1.8.4",
|
|
43
|
+
"@argos-ci/api-client": "0.9.0",
|
|
44
|
+
"@argos-ci/util": "3.0.0",
|
|
46
45
|
"convict": "^6.2.4",
|
|
47
46
|
"debug": "^4.4.0",
|
|
48
47
|
"fast-glob": "^3.3.3",
|
|
49
|
-
"sharp": "^0.
|
|
48
|
+
"sharp": "^0.34.3",
|
|
50
49
|
"tmp": "^0.2.3"
|
|
51
50
|
},
|
|
52
51
|
"devDependencies": {
|
|
53
|
-
"@octokit/webhooks": "^
|
|
52
|
+
"@octokit/webhooks": "^14.1.3",
|
|
54
53
|
"@types/convict": "^6.1.6",
|
|
55
54
|
"@types/debug": "^4.1.12",
|
|
56
55
|
"@types/tmp": "^0.2.6",
|
|
57
|
-
"msw": "^2.
|
|
56
|
+
"msw": "^2.10.4",
|
|
58
57
|
"vitest": "catalog:"
|
|
59
58
|
},
|
|
60
59
|
"scripts": {
|
|
@@ -65,5 +64,5 @@
|
|
|
65
64
|
"lint": "eslint .",
|
|
66
65
|
"test": "vitest"
|
|
67
66
|
},
|
|
68
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "db55659eaaffc6a3a92655f621be0d6344901da2"
|
|
69
68
|
}
|