@argos-ci/core 3.2.2 → 4.0.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.ts CHANGED
@@ -288,7 +288,6 @@ interface Config {
288
288
  parallelTotal: number | null;
289
289
  referenceBranch: string | null;
290
290
  referenceCommit: string | null;
291
- owner: string | null;
292
291
  repository: string | null;
293
292
  jobId: string | null;
294
293
  runId: string | null;
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 "node:child_process";
8
+ import { execSync } from "child_process";
9
9
 
10
10
  // src/debug.ts
11
11
  import createDebug from "debug";
@@ -49,6 +49,14 @@ function branch() {
49
49
  return null;
50
50
  }
51
51
  }
52
+ function getRepositoryURL() {
53
+ try {
54
+ const url = execSync("git config --get remote.origin.url").toString().trim();
55
+ return url;
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
52
60
  function getMergeBaseCommitShaWithDepth(input) {
53
61
  execSync(
54
62
  `git fetch --update-head-ok --depth ${input.depth} origin ${input.head}:${input.head}`
@@ -99,19 +107,27 @@ function listParentCommits(input) {
99
107
  }
100
108
 
101
109
  // src/ci-environment/services/bitrise.ts
102
- var getPrNumber = ({ env }) => {
110
+ function getPrNumber(context) {
111
+ const { env } = context;
103
112
  return env.BITRISE_PULL_REQUEST ? Number(env.BITRISE_PULL_REQUEST) : null;
104
- };
113
+ }
114
+ function getRepository(context) {
115
+ const { env } = context;
116
+ if (env.BITRISEIO_GIT_REPOSITORY_OWNER && env.BITRISEIO_GIT_REPOSITORY_SLUG) {
117
+ return `${env.BITRISEIO_GIT_REPOSITORY_OWNER}/${env.BITRISEIO_GIT_REPOSITORY_SLUG}`;
118
+ }
119
+ return null;
120
+ }
105
121
  var service = {
106
122
  name: "Bitrise",
107
123
  key: "bitrise",
108
124
  detect: ({ env }) => Boolean(env.BITRISE_IO),
109
- config: ({ env }) => {
125
+ config: (context) => {
126
+ const { env } = context;
110
127
  return {
111
128
  commit: env.BITRISE_GIT_COMMIT || null,
112
129
  branch: env.BITRISE_GIT_BRANCH || null,
113
- owner: env.BITRISEIO_GIT_REPOSITORY_OWNER || null,
114
- repository: env.BITRISEIO_GIT_REPOSITORY_SLUG || null,
130
+ repository: getRepository(context),
115
131
  jobId: null,
116
132
  runId: null,
117
133
  runAttempt: null,
@@ -126,18 +142,40 @@ var service = {
126
142
  };
127
143
  var bitrise_default = service;
128
144
 
145
+ // src/util/url.ts
146
+ function getRepositoryNameFromURL(url) {
147
+ const sshMatch = url.match(/^git@[^:]+:([^/]+)\/(.+?)(?:\.git)?$/);
148
+ if (sshMatch && sshMatch[1] && sshMatch[2]) {
149
+ return `${sshMatch[1]}/${sshMatch[2]}`;
150
+ }
151
+ const httpsMatch = url.match(
152
+ /^(?:https?|git):\/\/[^/]+\/([^/]+)\/(.+?)(?:\.git)?$/
153
+ );
154
+ if (httpsMatch && httpsMatch[1] && httpsMatch[2]) {
155
+ return `${httpsMatch[1]}/${httpsMatch[2]}`;
156
+ }
157
+ return null;
158
+ }
159
+
129
160
  // src/ci-environment/services/buildkite.ts
161
+ function getRepository2(context) {
162
+ const { env } = context;
163
+ if (env.BUILDKITE_REPO) {
164
+ return getRepositoryNameFromURL(env.BUILDKITE_REPO);
165
+ }
166
+ return null;
167
+ }
130
168
  var service2 = {
131
169
  name: "Buildkite",
132
170
  key: "buildkite",
133
171
  detect: ({ env }) => Boolean(env.BUILDKITE),
134
- config: ({ env }) => {
172
+ config: (context) => {
173
+ const { env } = context;
135
174
  return {
136
175
  // Buildkite doesn't work well so we fallback to git to ensure we have commit and branch
137
176
  commit: env.BUILDKITE_COMMIT || head() || null,
138
177
  branch: env.BUILDKITE_BRANCH || branch() || null,
139
- owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
140
- repository: env.BUILDKITE_PROJECT_SLUG || null,
178
+ repository: getRepository2(context),
141
179
  jobId: null,
142
180
  runId: null,
143
181
  runAttempt: null,
@@ -176,8 +214,7 @@ var service3 = {
176
214
  var heroku_default = service3;
177
215
 
178
216
  // src/ci-environment/services/github-actions.ts
179
- import { existsSync, readFileSync } from "node:fs";
180
- import axios from "axios";
217
+ import { existsSync, readFileSync } from "fs";
181
218
  async function getPullRequestFromHeadSha({ env }, sha) {
182
219
  debug("Fetching pull request number from head sha", sha);
183
220
  if (!env.GITHUB_REPOSITORY) {
@@ -203,27 +240,32 @@ DISABLE_GITHUB_TOKEN_WARNING: true
203
240
  return null;
204
241
  }
205
242
  try {
206
- const result = await axios.get(
207
- `https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls`,
208
- {
209
- params: {
210
- state: "open",
211
- sort: "updated",
212
- per_page: 30,
213
- page: 1
214
- },
215
- headers: {
216
- Accept: "application/vnd.github+json",
217
- Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
218
- "X-GitHub-Api-Version": "2022-11-28"
219
- }
220
- }
243
+ const url = new URL(
244
+ `https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls`
221
245
  );
222
- if (result.data.length === 0) {
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) {
223
265
  debug("Aborting because no pull request found");
224
266
  return null;
225
267
  }
226
- const matchingPr = result.data.find((pr) => pr.head.sha === sha);
268
+ const matchingPr = result.find((pr) => pr.head.sha === sha);
227
269
  if (matchingPr) {
228
270
  debug("Pull request found", matchingPr);
229
271
  return matchingPr;
@@ -256,11 +298,15 @@ function getBranchFromPayload(payload) {
256
298
  }
257
299
  return null;
258
300
  }
259
- function getRepositoryFromContext({ env }) {
260
- if (!env.GITHUB_REPOSITORY) {
261
- return null;
301
+ function getRepository3(context, payload) {
302
+ const { env } = context;
303
+ if (payload && "pull_request" in payload && payload.pull_request) {
304
+ const pr = payload.pull_request;
305
+ if (pr.head && pr.head.repo && pr.head.repo.full_name) {
306
+ return pr.head.repo.full_name;
307
+ }
262
308
  }
263
- return env.GITHUB_REPOSITORY.split("/")[1] || null;
309
+ return env.GITHUB_REPOSITORY || null;
264
310
  }
265
311
  function readEventPayload({ env }) {
266
312
  if (!env.GITHUB_EVENT_PATH) {
@@ -297,8 +343,7 @@ var service4 = {
297
343
  const pullRequest = payload ? getPullRequestFromPayload(payload) : await getPullRequestFromHeadSha(context, sha);
298
344
  return {
299
345
  commit: sha,
300
- owner: env.GITHUB_REPOSITORY_OWNER || null,
301
- repository: getRepositoryFromContext(context),
346
+ repository: getRepository3(context, payload),
302
347
  jobId: env.GITHUB_JOB || null,
303
348
  runId: env.GITHUB_RUN_ID || null,
304
349
  runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null,
@@ -315,24 +360,34 @@ var service4 = {
315
360
  var github_actions_default = service4;
316
361
 
317
362
  // src/ci-environment/services/circleci.ts
318
- var getPrNumber2 = ({ env }) => {
319
- const branchRegex = /pull\/(\d+)/;
320
- const matches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
363
+ function getPrNumber2(context) {
364
+ const { env } = context;
365
+ const matches = /pull\/(\d+)/.exec(env.CIRCLE_PULL_REQUEST || "");
321
366
  if (matches) {
322
367
  return Number(matches[1]);
323
368
  }
324
369
  return null;
325
- };
370
+ }
371
+ function getRepository4(context) {
372
+ const { env } = context;
373
+ if (env.CIRCLE_PR_REPONAME && env.CIRCLE_PR_USERNAME) {
374
+ return `${env.CIRCLE_PR_USERNAME}/${env.CIRCLE_PR_REPONAME}`;
375
+ }
376
+ if (env.CIRCLE_PROJECT_USERNAME && env.CIRCLE_PROJECT_REPONAME) {
377
+ return `${env.CIRCLE_PROJECT_USERNAME}/${env.CIRCLE_PROJECT_REPONAME}`;
378
+ }
379
+ return null;
380
+ }
326
381
  var service5 = {
327
382
  name: "CircleCI",
328
383
  key: "circleci",
329
384
  detect: ({ env }) => Boolean(env.CIRCLECI),
330
- config: ({ env }) => {
385
+ config: (context) => {
386
+ const { env } = context;
331
387
  return {
332
388
  commit: env.CIRCLE_SHA1 || null,
333
389
  branch: env.CIRCLE_BRANCH || null,
334
- owner: env.CIRCLE_PROJECT_USERNAME || null,
335
- repository: env.CIRCLE_PROJECT_REPONAME || null,
390
+ repository: getRepository4(context),
336
391
  jobId: null,
337
392
  runId: null,
338
393
  runAttempt: null,
@@ -348,24 +403,23 @@ var service5 = {
348
403
  var circleci_default = service5;
349
404
 
350
405
  // src/ci-environment/services/travis.ts
351
- var getOwner = ({ env }) => {
352
- if (!env.TRAVIS_REPO_SLUG) {
353
- return null;
406
+ function getRepository5(context) {
407
+ const { env } = context;
408
+ if (env.TRAVIS_PULL_REQUEST_SLUG) {
409
+ return env.TRAVIS_PULL_REQUEST_SLUG;
354
410
  }
355
- return env.TRAVIS_REPO_SLUG.split("/")[0] || null;
356
- };
357
- var getRepository = ({ env }) => {
358
- if (!env.TRAVIS_REPO_SLUG) {
359
- return null;
411
+ if (env.TRAVIS_REPO_SLUG) {
412
+ return env.TRAVIS_REPO_SLUG;
360
413
  }
361
- return env.TRAVIS_REPO_SLUG.split("/")[1] || null;
362
- };
363
- var getPrNumber3 = ({ env }) => {
414
+ return null;
415
+ }
416
+ function getPrNumber3(context) {
417
+ const { env } = context;
364
418
  if (env.TRAVIS_PULL_REQUEST) {
365
419
  return Number(env.TRAVIS_PULL_REQUEST);
366
420
  }
367
421
  return null;
368
- };
422
+ }
369
423
  var service6 = {
370
424
  name: "Travis CI",
371
425
  key: "travis",
@@ -375,8 +429,7 @@ var service6 = {
375
429
  return {
376
430
  commit: env.TRAVIS_COMMIT || null,
377
431
  branch: env.TRAVIS_BRANCH || null,
378
- owner: getOwner(ctx),
379
- repository: getRepository(ctx),
432
+ repository: getRepository5(ctx),
380
433
  jobId: null,
381
434
  runId: null,
382
435
  runAttempt: null,
@@ -392,16 +445,23 @@ var service6 = {
392
445
  var travis_default = service6;
393
446
 
394
447
  // src/ci-environment/services/gitlab.ts
448
+ function getRepository6(context) {
449
+ const { env } = context;
450
+ if (env.CI_MERGE_REQUEST_PROJECT_PATH) {
451
+ return env.CI_MERGE_REQUEST_PROJECT_PATH;
452
+ }
453
+ return env.CI_PROJECT_PATH || null;
454
+ }
395
455
  var service7 = {
396
456
  name: "GitLab",
397
457
  key: "gitlab",
398
458
  detect: ({ env }) => env.GITLAB_CI === "true",
399
- config: ({ env }) => {
459
+ config: (context) => {
460
+ const { env } = context;
400
461
  return {
401
462
  commit: env.CI_COMMIT_SHA || null,
402
463
  branch: env.CI_COMMIT_REF_NAME || null,
403
- owner: null,
404
- repository: null,
464
+ repository: getRepository6(context),
405
465
  jobId: null,
406
466
  runId: null,
407
467
  runAttempt: null,
@@ -417,6 +477,13 @@ var service7 = {
417
477
  var gitlab_default = service7;
418
478
 
419
479
  // src/ci-environment/services/git.ts
480
+ function getRepository7() {
481
+ const repositoryURL = getRepositoryURL();
482
+ if (!repositoryURL) {
483
+ return null;
484
+ }
485
+ return getRepositoryNameFromURL(repositoryURL);
486
+ }
420
487
  var service8 = {
421
488
  name: "Git",
422
489
  key: "git",
@@ -425,8 +492,7 @@ var service8 = {
425
492
  return {
426
493
  commit: head() || null,
427
494
  branch: branch() || null,
428
- owner: null,
429
- repository: null,
495
+ repository: getRepository7(),
430
496
  jobId: null,
431
497
  runId: null,
432
498
  runAttempt: null,
@@ -673,7 +739,6 @@ async function readConfig(options = {}) {
673
739
  prBaseBranch: config.get("prBaseBranch") || ciEnv?.prBaseBranch || null,
674
740
  referenceBranch: options.referenceBranch || config.get("referenceBranch") || null,
675
741
  referenceCommit: options.referenceCommit || config.get("referenceCommit") || null,
676
- owner: ciEnv?.owner || null,
677
742
  repository: ciEnv?.repository || null,
678
743
  jobId: ciEnv?.jobId || null,
679
744
  runId: ciEnv?.runId || null,
@@ -691,7 +756,7 @@ async function readConfig(options = {}) {
691
756
  }
692
757
 
693
758
  // src/discovery.ts
694
- import { resolve } from "node:path";
759
+ import { resolve } from "path";
695
760
  import glob from "fast-glob";
696
761
  var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}) => {
697
762
  debug(
@@ -709,8 +774,8 @@ var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}
709
774
  };
710
775
 
711
776
  // src/optimize.ts
712
- import { promisify } from "node:util";
713
- import { basename } from "node:path";
777
+ import { promisify } from "util";
778
+ import { basename } from "path";
714
779
  import sharp from "sharp";
715
780
  import tmp from "tmp";
716
781
  var tmpFile = promisify(tmp.file);
@@ -775,8 +840,8 @@ var optimizeScreenshot = async (filepath) => {
775
840
  };
776
841
 
777
842
  // src/hashing.ts
778
- import { createReadStream } from "node:fs";
779
- import { createHash } from "node:crypto";
843
+ import { createReadStream } from "fs";
844
+ import { createHash } from "crypto";
780
845
  var hashFile = async (filepath) => {
781
846
  const fileStream = createReadStream(filepath);
782
847
  const hash = createHash("sha256");
@@ -824,19 +889,24 @@ function getAuthToken({
824
889
  }
825
890
 
826
891
  // src/s3.ts
827
- import { readFile } from "node:fs/promises";
828
- import axios2 from "axios";
829
- var upload = async (input) => {
892
+ import { readFile } from "fs/promises";
893
+ async function uploadFile(input) {
830
894
  const file = await readFile(input.path);
831
- await axios2({
895
+ const response = await fetch(input.url, {
832
896
  method: "PUT",
833
- url: input.url,
834
- data: file,
835
897
  headers: {
836
- "Content-Type": input.contentType
837
- }
898
+ "Content-Type": input.contentType,
899
+ "Content-Length": file.length.toString()
900
+ },
901
+ signal: AbortSignal.timeout(3e4),
902
+ body: new Uint8Array(file)
838
903
  });
839
- };
904
+ if (!response.ok) {
905
+ throw new Error(
906
+ `Failed to upload file to ${input.url}: ${response.status} ${response.statusText}`
907
+ );
908
+ }
909
+ }
840
910
 
841
911
  // src/util/chunk.ts
842
912
  var chunk = (collection, size) => {
@@ -854,7 +924,7 @@ import { getPlaywrightTracePath, readMetadata } from "@argos-ci/util";
854
924
 
855
925
  // src/version.ts
856
926
  import { readVersionFromPackage } from "@argos-ci/util";
857
- import { createRequire } from "node:module";
927
+ import { createRequire } from "module";
858
928
  var require2 = createRequire(import.meta.url);
859
929
  async function getArgosCoreSDKIdentifier() {
860
930
  const pkgPath = require2.resolve("@argos-ci/core/package.json");
@@ -890,7 +960,7 @@ async function uploadFilesToS3(files) {
890
960
  }
891
961
  await Promise.all(
892
962
  chunk2.map(async ({ url, path, contentType }) => {
893
- await upload({
963
+ await uploadFile({
894
964
  url,
895
965
  path,
896
966
  contentType
@@ -910,7 +980,7 @@ function formatPreviewUrl(url, formatter) {
910
980
  formatter.baseUrl
911
981
  ).href;
912
982
  }
913
- async function upload2(params) {
983
+ async function upload(params) {
914
984
  debug("Starting upload with params", params);
915
985
  const [config, argosSdk] = await Promise.all([
916
986
  getConfigFromOptions(params),
@@ -1122,5 +1192,5 @@ async function finalize(params) {
1122
1192
  export {
1123
1193
  finalize,
1124
1194
  readConfig,
1125
- upload2 as upload
1195
+ upload
1126
1196
  };
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": "3.2.2",
4
+ "version": "4.0.0",
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": ">=18.0.0"
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.8.2",
44
- "@argos-ci/util": "2.3.3",
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.33.5",
48
+ "sharp": "^0.34.3",
50
49
  "tmp": "^0.2.3"
51
50
  },
52
51
  "devDependencies": {
53
- "@octokit/webhooks": "^13.7.5",
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.7.3",
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": "ecab2281c36828d0c43728e3ed98e1eefe227c99"
67
+ "gitHead": "807e4a9f3c4bfddd4197ed7394b032a39bc1c58e"
69
68
  }