@argos-ci/core 2.11.0 → 2.12.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.
Files changed (3) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +41 -34
  3. package/package.json +5 -4
package/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  <p align="center">
2
2
  <a href="https://argos-ci.com/?utm_source=github&utm_medium=logo" target="_blank">
3
- <img src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/logo-github-readme.png" alt="Argos" width="300" height="61">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/github-readme-logo-dark.png">
5
+ <img alt="Argos" src="https://raw.githubusercontent.com/argos-ci/argos/main/resources/logos/github-readme-logo-light.png" width="360" height="70">
6
+ </picture>
4
7
  </a>
5
8
  </p>
6
9
 
7
- _Argos is a visual testing solution that fits in your workflow to avoid visual regression. Takes screenshots on each commit and be notified if something changes._
10
+ <p align="center"><strong>The open source visual testing plaform for modern engineering teams.</strong></p>
8
11
 
9
12
  # Argos JavaScript SDK Core
10
13
 
package/dist/index.js CHANGED
@@ -181,12 +181,16 @@ async function getPullRequestFromHeadSha({ env }, sha) {
181
181
  if (!env.DISABLE_GITHUB_TOKEN_WARNING) {
182
182
  console.log(
183
183
  `
184
- Running argos from a "deployment_status" event requires a GITHUB_TOKEN.
185
- Please add \`GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}\` as environment variable.
184
+ Argos couldn\u2019t find a relevant pull request in the current environment.
185
+ To resolve this, Argos requires a GITHUB_TOKEN to fetch the pull request associated with the head SHA. Please ensure the following environment variable is added:
186
186
 
187
- Read more at https://argos-ci.com/docs/run-on-preview-deployment
187
+ GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
188
188
 
189
- To disable this warning, add \`DISABLE_GITHUB_TOKEN_WARNING: true\` as environment variable.
189
+ For more details, check out the documentation: Read more at https://argos-ci.com/docs/run-on-preview-deployment
190
+
191
+ If you want to disable this warning, you can set the following environment variable:
192
+
193
+ DISABLE_GITHUB_TOKEN_WARNING: true
190
194
  `.trim()
191
195
  );
192
196
  }
@@ -225,10 +229,7 @@ To disable this warning, add \`DISABLE_GITHUB_TOKEN_WARNING: true\` as environme
225
229
  return null;
226
230
  }
227
231
  }
228
- function getBranch(context, eventPayload) {
229
- if (eventPayload?.pull_request?.head.ref) {
230
- return eventPayload.pull_request.head.ref;
231
- }
232
+ function getBranchFromContext(context) {
232
233
  const { env } = context;
233
234
  if (env.GITHUB_HEAD_REF) {
234
235
  return env.GITHUB_HEAD_REF;
@@ -240,7 +241,16 @@ function getBranch(context, eventPayload) {
240
241
  const matches = branchRegex.exec(env.GITHUB_REF);
241
242
  return matches?.[1] ?? null;
242
243
  }
243
- function getRepository({ env }) {
244
+ function getBranchFromPayload(payload) {
245
+ if ("workflow_run" in payload && payload.workflow_run) {
246
+ return payload.workflow_run.head_branch;
247
+ }
248
+ if ("deployment" in payload && payload.deployment) {
249
+ return payload.deployment.environment;
250
+ }
251
+ return null;
252
+ }
253
+ function getRepositoryFromContext({ env }) {
244
254
  if (!env.GITHUB_REPOSITORY) return null;
245
255
  return env.GITHUB_REPOSITORY.split("/")[1] || null;
246
256
  }
@@ -249,6 +259,18 @@ function readEventPayload({ env }) {
249
259
  if (!existsSync(env.GITHUB_EVENT_PATH)) return null;
250
260
  return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf-8"));
251
261
  }
262
+ function getPullRequestFromPayload(payload) {
263
+ if ("pull_request" in payload && payload.pull_request && payload.pull_request) {
264
+ return payload.pull_request;
265
+ }
266
+ if ("workflow_run" in payload && payload.workflow_run && payload.workflow_run.pull_requests[0]) {
267
+ return payload.workflow_run.pull_requests[0];
268
+ }
269
+ if ("check_run" in payload && payload.check_run && "pull_requests" in payload.check_run && payload.check_run.pull_requests[0]) {
270
+ return payload.check_run.pull_requests[0];
271
+ }
272
+ return null;
273
+ }
252
274
  var service4 = {
253
275
  name: "GitHub Actions",
254
276
  key: "github-actions",
@@ -260,34 +282,19 @@ var service4 = {
260
282
  if (!sha) {
261
283
  throw new Error(`GITHUB_SHA is missing`);
262
284
  }
263
- const commonConfig = {
285
+ const pullRequest = payload ? getPullRequestFromPayload(payload) : await getPullRequestFromHeadSha(context, sha);
286
+ return {
264
287
  commit: sha,
265
288
  owner: env.GITHUB_REPOSITORY_OWNER || null,
266
- repository: getRepository(context),
289
+ repository: getRepositoryFromContext(context),
267
290
  jobId: env.GITHUB_JOB || null,
268
291
  runId: env.GITHUB_RUN_ID || null,
269
292
  runAttempt: env.GITHUB_RUN_ATTEMPT ? Number(env.GITHUB_RUN_ATTEMPT) : null,
270
- nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null
271
- };
272
- if (payload?.deployment) {
273
- debug("Deployment event detected");
274
- const pullRequest = await getPullRequestFromHeadSha(context, sha);
275
- return {
276
- ...commonConfig,
277
- // If no pull request is found, we fallback to the deployment environment as branch name
278
- // Branch name is required to create a build but has no real impact on the build.
279
- branch: pullRequest?.head.ref || payload.deployment.environment || null,
280
- prNumber: pullRequest?.number || null,
281
- prHeadCommit: pullRequest?.head.sha || null,
282
- prBaseBranch: null
283
- };
284
- }
285
- return {
286
- ...commonConfig,
287
- branch: payload?.pull_request?.head.ref || getBranch(context, payload) || null,
288
- prNumber: payload?.pull_request?.number || null,
289
- prHeadCommit: payload?.pull_request?.head.sha ?? null,
290
- prBaseBranch: payload?.pull_request?.base.ref ?? null
293
+ nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null,
294
+ branch: getBranchFromContext(context) || pullRequest?.head.ref || (payload ? getBranchFromPayload(payload) : null) || null,
295
+ prNumber: pullRequest?.number || null,
296
+ prHeadCommit: pullRequest?.head.sha ?? null,
297
+ prBaseBranch: pullRequest?.base.ref ?? null
291
298
  };
292
299
  },
293
300
  getMergeBaseCommitSha,
@@ -333,7 +340,7 @@ var getOwner = ({ env }) => {
333
340
  if (!env.TRAVIS_REPO_SLUG) return null;
334
341
  return env.TRAVIS_REPO_SLUG.split("/")[0] || null;
335
342
  };
336
- var getRepository2 = ({ env }) => {
343
+ var getRepository = ({ env }) => {
337
344
  if (!env.TRAVIS_REPO_SLUG) return null;
338
345
  return env.TRAVIS_REPO_SLUG.split("/")[1] || null;
339
346
  };
@@ -351,7 +358,7 @@ var service6 = {
351
358
  commit: env.TRAVIS_COMMIT || null,
352
359
  branch: env.TRAVIS_BRANCH || null,
353
360
  owner: getOwner(ctx),
354
- repository: getRepository2(ctx),
361
+ repository: getRepository(ctx),
355
362
  jobId: null,
356
363
  runId: null,
357
364
  runAttempt: null,
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": "2.11.0",
4
+ "version": "2.12.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
7
7
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@argos-ci/api-client": "0.7.0",
44
- "@argos-ci/util": "2.2.0",
43
+ "@argos-ci/api-client": "0.7.1",
44
+ "@argos-ci/util": "2.2.1",
45
45
  "axios": "^1.7.7",
46
46
  "convict": "^6.2.4",
47
47
  "debug": "^4.3.7",
@@ -50,6 +50,7 @@
50
50
  "tmp": "^0.2.3"
51
51
  },
52
52
  "devDependencies": {
53
+ "@octokit/webhooks": "^13.4.1",
53
54
  "@types/convict": "^6.1.6",
54
55
  "@types/debug": "^4.1.12",
55
56
  "@types/tmp": "^0.2.6",
@@ -59,5 +60,5 @@
59
60
  "build": "tsup && cp ./src/index.cjs ./dist",
60
61
  "e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
61
62
  },
62
- "gitHead": "a1782b8aa412c3814da4e51d6ef603916a4c7e62"
63
+ "gitHead": "88672d5cd06a792974844d1cb798641cec6e0562"
63
64
  }