@argos-ci/core 2.11.1 → 3.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.js +91 -39
- package/package.json +9 -8
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
|
-
|
|
185
|
-
|
|
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
|
-
|
|
187
|
+
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
|
|
188
188
|
|
|
189
|
-
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
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
|
|
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:
|
|
361
|
+
repository: getRepository(ctx),
|
|
355
362
|
jobId: null,
|
|
356
363
|
runId: null,
|
|
357
364
|
runAttempt: null,
|
|
@@ -678,16 +685,61 @@ var discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {}
|
|
|
678
685
|
|
|
679
686
|
// src/optimize.ts
|
|
680
687
|
import { promisify } from "node:util";
|
|
688
|
+
import { basename } from "node:path";
|
|
681
689
|
import sharp from "sharp";
|
|
682
690
|
import tmp from "tmp";
|
|
683
691
|
var tmpFile = promisify(tmp.file);
|
|
692
|
+
var MAX_PIXELS = 8e7;
|
|
693
|
+
var DEFAULT_MAX_WIDTH = 2048;
|
|
684
694
|
var optimizeScreenshot = async (filepath) => {
|
|
685
695
|
try {
|
|
686
|
-
const resultFilePath = await
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
696
|
+
const [resultFilePath, metadata] = await Promise.all([
|
|
697
|
+
tmpFile(),
|
|
698
|
+
sharp(filepath).metadata()
|
|
699
|
+
]);
|
|
700
|
+
const { width, height } = metadata;
|
|
701
|
+
const maxDimensions = (() => {
|
|
702
|
+
if (!width || !height) {
|
|
703
|
+
return {
|
|
704
|
+
width: DEFAULT_MAX_WIDTH,
|
|
705
|
+
height: Math.floor(MAX_PIXELS / DEFAULT_MAX_WIDTH)
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
const nbPixels = width * height;
|
|
709
|
+
if (nbPixels <= MAX_PIXELS) {
|
|
710
|
+
return null;
|
|
711
|
+
}
|
|
712
|
+
if (width < height) {
|
|
713
|
+
return {
|
|
714
|
+
width: DEFAULT_MAX_WIDTH,
|
|
715
|
+
height: Math.floor(MAX_PIXELS / DEFAULT_MAX_WIDTH)
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
const scaleFactor = Math.sqrt(MAX_PIXELS / nbPixels);
|
|
719
|
+
return {
|
|
720
|
+
width: Math.floor(width * scaleFactor),
|
|
721
|
+
height: Math.floor(height * scaleFactor)
|
|
722
|
+
};
|
|
723
|
+
})();
|
|
724
|
+
let operation = sharp(filepath);
|
|
725
|
+
if (maxDimensions) {
|
|
726
|
+
operation = operation.resize(maxDimensions.width, maxDimensions.height, {
|
|
727
|
+
fit: "inside",
|
|
728
|
+
withoutEnlargement: true
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
await operation.png({ force: true }).toFile(resultFilePath);
|
|
732
|
+
if (width && height && maxDimensions) {
|
|
733
|
+
const { width: maxWidth, height: maxHeight } = maxDimensions;
|
|
734
|
+
const widthRatio = maxWidth / width;
|
|
735
|
+
const heightRatio = maxHeight / height;
|
|
736
|
+
const scaleFactor = Math.min(widthRatio, heightRatio);
|
|
737
|
+
const newWidth = Math.floor(width * scaleFactor);
|
|
738
|
+
const newHeight = Math.floor(height * scaleFactor);
|
|
739
|
+
console.warn(
|
|
740
|
+
`Image ${basename(filepath)} resized from ${width}x${height} to ${newWidth}x${newHeight}.`
|
|
741
|
+
);
|
|
742
|
+
}
|
|
691
743
|
return resultFilePath;
|
|
692
744
|
} catch (error) {
|
|
693
745
|
const message = error instanceof Error ? error.message : "Unknown Error";
|
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": "3.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"exports": {
|
|
@@ -40,24 +40,25 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/api-client": "0.7.
|
|
44
|
-
"@argos-ci/util": "2.2.
|
|
45
|
-
"axios": "^1.7.
|
|
43
|
+
"@argos-ci/api-client": "0.7.2",
|
|
44
|
+
"@argos-ci/util": "2.2.2",
|
|
45
|
+
"axios": "^1.7.9",
|
|
46
46
|
"convict": "^6.2.4",
|
|
47
|
-
"debug": "^4.
|
|
48
|
-
"fast-glob": "^3.3.
|
|
47
|
+
"debug": "^4.4.0",
|
|
48
|
+
"fast-glob": "^3.3.3",
|
|
49
49
|
"sharp": "^0.33.5",
|
|
50
50
|
"tmp": "^0.2.3"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"@octokit/webhooks": "^13.4.2",
|
|
53
54
|
"@types/convict": "^6.1.6",
|
|
54
55
|
"@types/debug": "^4.1.12",
|
|
55
56
|
"@types/tmp": "^0.2.6",
|
|
56
|
-
"msw": "^2.
|
|
57
|
+
"msw": "^2.7.0"
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|
|
59
60
|
"build": "tsup && cp ./src/index.cjs ./dist",
|
|
60
61
|
"e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
|
|
61
62
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0c91306ae0cb8bec5ef93db79565635e405086f7"
|
|
63
64
|
}
|