@argos-ci/core 1.2.0 → 1.3.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.mjs +82 -48
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -12,6 +12,29 @@ import axios from 'axios';
|
|
|
12
12
|
import { readFile } from 'node:fs/promises';
|
|
13
13
|
import { readMetadata, getPlaywrightTracePath } from '@argos-ci/util';
|
|
14
14
|
|
|
15
|
+
const getPrNumber$2 = ({ env })=>{
|
|
16
|
+
return env.BITRISE_PULL_REQUEST ? Number(env.BITRISE_PULL_REQUEST) : null;
|
|
17
|
+
};
|
|
18
|
+
const service$7 = {
|
|
19
|
+
name: "Bitrise",
|
|
20
|
+
detect: ({ env })=>Boolean(env.BITRISE_IO),
|
|
21
|
+
config: ({ env })=>{
|
|
22
|
+
return {
|
|
23
|
+
commit: env.BITRISE_GIT_COMMIT || null,
|
|
24
|
+
branch: env.BITRISE_GIT_BRANCH || null,
|
|
25
|
+
owner: env.BITRISEIO_GIT_REPOSITORY_OWNER || null,
|
|
26
|
+
repository: env.BITRISEIO_GIT_REPOSITORY_SLUG || null,
|
|
27
|
+
jobId: null,
|
|
28
|
+
runId: null,
|
|
29
|
+
prNumber: getPrNumber$2({
|
|
30
|
+
env
|
|
31
|
+
}),
|
|
32
|
+
prHeadCommit: null,
|
|
33
|
+
nonce: env.BITRISEIO_PIPELINE_ID || null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
15
38
|
/**
|
|
16
39
|
* Check if the current directory is a git repository.
|
|
17
40
|
*/ const checkIsGitRepository = ()=>{
|
|
@@ -207,7 +230,6 @@ const service = {
|
|
|
207
230
|
detect: ()=>checkIsGitRepository(),
|
|
208
231
|
config: ()=>{
|
|
209
232
|
return {
|
|
210
|
-
// Buildkite doesn't work well so we fallback to git to ensure we have commit and branch
|
|
211
233
|
commit: head() || null,
|
|
212
234
|
branch: branch() || null,
|
|
213
235
|
owner: null,
|
|
@@ -236,6 +258,8 @@ const debugTimeEnd = (arg)=>{
|
|
|
236
258
|
}
|
|
237
259
|
};
|
|
238
260
|
|
|
261
|
+
// List of services ordered by usage
|
|
262
|
+
// "git" must be the last one
|
|
239
263
|
const services = [
|
|
240
264
|
service$5,
|
|
241
265
|
service$4,
|
|
@@ -243,6 +267,7 @@ const services = [
|
|
|
243
267
|
service$2,
|
|
244
268
|
service$6,
|
|
245
269
|
service$1,
|
|
270
|
+
service$7,
|
|
246
271
|
service
|
|
247
272
|
];
|
|
248
273
|
const getCiEnvironment = ({ env = process.env } = {})=>{
|
|
@@ -558,9 +583,29 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
|
|
|
558
583
|
});
|
|
559
584
|
return config;
|
|
560
585
|
};
|
|
586
|
+
async function uploadFilesToS3(files) {
|
|
587
|
+
debug(`Split files in chunks of ${CHUNK_SIZE}`);
|
|
588
|
+
const chunks = chunk(files, CHUNK_SIZE);
|
|
589
|
+
debug(`Starting upload of ${chunks.length} chunks`);
|
|
590
|
+
for(let i = 0; i < chunks.length; i++){
|
|
591
|
+
// Upload files
|
|
592
|
+
debug(`Uploading chunk ${i + 1}/${chunks.length}`);
|
|
593
|
+
const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
|
|
594
|
+
debugTime(timeLabel);
|
|
595
|
+
await Promise.all(chunks[i].map(async ({ url, path, contentType })=>{
|
|
596
|
+
await upload$1({
|
|
597
|
+
url,
|
|
598
|
+
path,
|
|
599
|
+
contentType
|
|
600
|
+
});
|
|
601
|
+
}));
|
|
602
|
+
debugTimeEnd(timeLabel);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
561
605
|
/**
|
|
562
606
|
* Upload screenshots to argos-ci.com.
|
|
563
607
|
*/ const upload = async (params)=>{
|
|
608
|
+
var _result_pwTraces;
|
|
564
609
|
debug("Starting upload with params", params);
|
|
565
610
|
// Read config
|
|
566
611
|
const config = getConfigFromOptions(params);
|
|
@@ -602,20 +647,21 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
|
|
|
602
647
|
}));
|
|
603
648
|
// Create build
|
|
604
649
|
debug("Creating build");
|
|
605
|
-
const screenshotKeys =
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (!screenshot) {
|
|
609
|
-
throw new Error(`Invariant: screenshot with hash ${key} not found`);
|
|
650
|
+
const [pwTraceKeys, screenshotKeys] = screenshots.reduce(([pwTraceKeys, screenshotKeys], screenshot)=>{
|
|
651
|
+
if (screenshot.pwTrace && !pwTraceKeys.includes(screenshot.pwTrace.hash)) {
|
|
652
|
+
pwTraceKeys.push(screenshot.pwTrace.hash);
|
|
610
653
|
}
|
|
611
|
-
if (screenshot.
|
|
612
|
-
|
|
613
|
-
screenshotKey: screenshot.hash,
|
|
614
|
-
traceKey: screenshot.pwTrace.hash
|
|
615
|
-
});
|
|
654
|
+
if (!screenshotKeys.includes(screenshot.hash)) {
|
|
655
|
+
screenshotKeys.push(screenshot.hash);
|
|
616
656
|
}
|
|
617
|
-
return
|
|
618
|
-
|
|
657
|
+
return [
|
|
658
|
+
pwTraceKeys,
|
|
659
|
+
screenshotKeys
|
|
660
|
+
];
|
|
661
|
+
}, [
|
|
662
|
+
[],
|
|
663
|
+
[]
|
|
664
|
+
]);
|
|
619
665
|
const result = await apiClient.createBuild({
|
|
620
666
|
commit: config.commit,
|
|
621
667
|
branch: config.branch,
|
|
@@ -623,50 +669,38 @@ const getConfigFromOptions = ({ parallel, ...options })=>{
|
|
|
623
669
|
parallel: config.parallel,
|
|
624
670
|
parallelNonce: config.parallelNonce,
|
|
625
671
|
screenshotKeys,
|
|
626
|
-
|
|
672
|
+
pwTraceKeys,
|
|
627
673
|
prNumber: config.prNumber,
|
|
628
674
|
prHeadCommit: config.prHeadCommit,
|
|
629
675
|
referenceBranch: config.referenceBranch,
|
|
630
676
|
referenceCommit: config.referenceCommit
|
|
631
677
|
});
|
|
632
|
-
debug("Got
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
debug(`Starting upload of ${chunks.length} chunks`);
|
|
636
|
-
for(let i = 0; i < chunks.length; i++){
|
|
637
|
-
// Upload screenshots
|
|
638
|
-
debug(`Uploading chunk ${i + 1}/${chunks.length}`);
|
|
639
|
-
const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
|
|
640
|
-
debugTime(timeLabel);
|
|
641
|
-
await Promise.all(chunks[i].map(async ({ key, putUrl, putTraceUrl })=>{
|
|
678
|
+
debug("Got uploads url", result);
|
|
679
|
+
const uploadFiles = [
|
|
680
|
+
...result.screenshots.map(({ key, putUrl })=>{
|
|
642
681
|
const screenshot = screenshots.find((s)=>s.hash === key);
|
|
643
682
|
if (!screenshot) {
|
|
644
683
|
throw new Error(`Invariant: screenshot with hash ${key} not found`);
|
|
645
684
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
})()
|
|
666
|
-
]);
|
|
667
|
-
}));
|
|
668
|
-
debugTimeEnd(timeLabel);
|
|
669
|
-
}
|
|
685
|
+
return {
|
|
686
|
+
url: putUrl,
|
|
687
|
+
path: screenshot.optimizedPath,
|
|
688
|
+
contentType: "image/png"
|
|
689
|
+
};
|
|
690
|
+
}),
|
|
691
|
+
...((_result_pwTraces = result.pwTraces) === null || _result_pwTraces === void 0 ? void 0 : _result_pwTraces.map(({ key, putUrl })=>{
|
|
692
|
+
const screenshot = screenshots.find((s)=>s.pwTrace && s.pwTrace.hash === key);
|
|
693
|
+
if (!screenshot || !screenshot.pwTrace) {
|
|
694
|
+
throw new Error(`Invariant: trace with ${key} not found`);
|
|
695
|
+
}
|
|
696
|
+
return {
|
|
697
|
+
url: putUrl,
|
|
698
|
+
path: screenshot.pwTrace.path,
|
|
699
|
+
contentType: "application/json"
|
|
700
|
+
};
|
|
701
|
+
})) ?? []
|
|
702
|
+
];
|
|
703
|
+
await uploadFilesToS3(uploadFiles);
|
|
670
704
|
// Update build
|
|
671
705
|
debug("Updating build");
|
|
672
706
|
await apiClient.updateBuild({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/core",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. The core component of Argos SDK that handles build creation.",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"build": "rollup -c",
|
|
60
60
|
"e2e": "node ./e2e/upload.cjs && node ./e2e/upload.mjs"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "8022e7391f8bd156e23a83b5da0ce452e28e324e"
|
|
63
63
|
}
|