@argos-ci/core 1.4.1 → 1.4.2-alpha.6
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 +2 -2
- package/dist/index.mjs +86 -37
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ interface UploadParameters {
|
|
|
32
32
|
/**
|
|
33
33
|
* Upload screenshots to argos-ci.com.
|
|
34
34
|
*/
|
|
35
|
-
declare
|
|
35
|
+
declare function upload(params: UploadParameters): Promise<{
|
|
36
36
|
build: {
|
|
37
37
|
id: string;
|
|
38
38
|
url: string;
|
|
@@ -67,5 +67,5 @@ interface Config {
|
|
|
67
67
|
prNumber: number | null;
|
|
68
68
|
prHeadCommit: string | null;
|
|
69
69
|
}
|
|
70
|
-
declare
|
|
70
|
+
declare function readConfig(options?: Partial<Config>): Promise<Config>;
|
|
71
71
|
export { UploadParameters, upload, Config, readConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import convict from 'convict';
|
|
2
2
|
import { execSync } from 'node:child_process';
|
|
3
3
|
import { existsSync, readFileSync, createReadStream } from 'node:fs';
|
|
4
|
+
import axios from 'axios';
|
|
4
5
|
import createDebug from 'debug';
|
|
5
6
|
import { resolve } from 'node:path';
|
|
6
7
|
import glob from 'fast-glob';
|
|
@@ -8,7 +9,6 @@ import { promisify } from 'node:util';
|
|
|
8
9
|
import sharp from 'sharp';
|
|
9
10
|
import tmp from 'tmp';
|
|
10
11
|
import { createHash } from 'node:crypto';
|
|
11
|
-
import axios from 'axios';
|
|
12
12
|
import { readFile } from 'node:fs/promises';
|
|
13
13
|
import { readMetadata, getPlaywrightTracePath } from '@argos-ci/util';
|
|
14
14
|
|
|
@@ -102,6 +102,53 @@ const service$5 = {
|
|
|
102
102
|
})
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
+
const KEY = "@argos-ci/core";
|
|
106
|
+
const debug = createDebug(KEY);
|
|
107
|
+
const debugTime = (arg)=>{
|
|
108
|
+
const enabled = createDebug.enabled(KEY);
|
|
109
|
+
if (enabled) {
|
|
110
|
+
console.time(arg);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
const debugTimeEnd = (arg)=>{
|
|
114
|
+
const enabled = createDebug.enabled(KEY);
|
|
115
|
+
if (enabled) {
|
|
116
|
+
console.timeEnd(arg);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* When triggered by a deployment we try to get the pull request number from the
|
|
122
|
+
* deployment sha.
|
|
123
|
+
*/ async function getPullRequestFromHeadSha({ env }, sha) {
|
|
124
|
+
debug("Fetching pull request number from head sha", sha);
|
|
125
|
+
if (!env.GITHUB_REPOSITORY || !env.GITHUB_TOKEN) {
|
|
126
|
+
debug("Aborting because GITHUB_REPOSITORY or GITHUB_TOKEN is missing");
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
const result = await axios.get(`https://api.github.com/repos/${env.GITHUB_REPOSITORY}/pulls`, {
|
|
131
|
+
params: {
|
|
132
|
+
head: sha
|
|
133
|
+
},
|
|
134
|
+
headers: {
|
|
135
|
+
Accept: "application/vnd.github+json",
|
|
136
|
+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
|
|
137
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (result.data.length === 0) {
|
|
141
|
+
debug("Aborting because no pull request found");
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const firstPr = result.data[0];
|
|
145
|
+
debug("PR found", firstPr);
|
|
146
|
+
return firstPr;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
debug("Error while fetching pull request number from head sha", error);
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
105
152
|
const getBranch = ({ env })=>{
|
|
106
153
|
if (env.GITHUB_HEAD_REF) {
|
|
107
154
|
return env.GITHUB_HEAD_REF;
|
|
@@ -125,26 +172,44 @@ const readEventPayload = ({ env })=>{
|
|
|
125
172
|
const service$4 = {
|
|
126
173
|
name: "GitHub Actions",
|
|
127
174
|
detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
|
|
128
|
-
config: ({ env })=>{
|
|
175
|
+
config: async ({ env })=>{
|
|
129
176
|
var _payload_pull_request, _payload_pull_request1, _payload_pull_request2;
|
|
130
177
|
const payload = readEventPayload({
|
|
131
178
|
env
|
|
132
179
|
});
|
|
133
|
-
|
|
134
|
-
commit: process.env.GITHUB_SHA || null,
|
|
135
|
-
branch: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request = payload.pull_request) === null || _payload_pull_request === void 0 ? void 0 : _payload_pull_request.head.ref) || getBranch({
|
|
136
|
-
env
|
|
137
|
-
}) || null,
|
|
180
|
+
const commonConfig = {
|
|
138
181
|
owner: env.GITHUB_REPOSITORY_OWNER || null,
|
|
139
182
|
repository: getRepository$1({
|
|
140
183
|
env
|
|
141
184
|
}),
|
|
142
185
|
jobId: env.GITHUB_JOB || null,
|
|
143
186
|
runId: env.GITHUB_RUN_ID || null,
|
|
144
|
-
prNumber: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request1 = payload.pull_request) === null || _payload_pull_request1 === void 0 ? void 0 : _payload_pull_request1.number) || null,
|
|
145
|
-
prHeadCommit: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request2 = payload.pull_request) === null || _payload_pull_request2 === void 0 ? void 0 : _payload_pull_request2.head.sha) ?? null,
|
|
146
187
|
nonce: `${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT}` || null
|
|
147
188
|
};
|
|
189
|
+
// If the job is triggered by from a "deployment" or a "deployment_status"
|
|
190
|
+
if (payload === null || payload === void 0 ? void 0 : payload.deployment) {
|
|
191
|
+
debug("Deployment event detected");
|
|
192
|
+
const { sha } = payload.deployment;
|
|
193
|
+
const pullRequest = await getPullRequestFromHeadSha({
|
|
194
|
+
env
|
|
195
|
+
}, sha);
|
|
196
|
+
return {
|
|
197
|
+
...commonConfig,
|
|
198
|
+
commit: payload.deployment.sha,
|
|
199
|
+
branch: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.ref) || payload.deployment.environment || null,
|
|
200
|
+
prNumber: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.number) || null,
|
|
201
|
+
prHeadCommit: (pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.head.sha) || null
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return {
|
|
205
|
+
...commonConfig,
|
|
206
|
+
commit: process.env.GITHUB_SHA || null,
|
|
207
|
+
branch: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request = payload.pull_request) === null || _payload_pull_request === void 0 ? void 0 : _payload_pull_request.head.ref) || getBranch({
|
|
208
|
+
env
|
|
209
|
+
}) || null,
|
|
210
|
+
prNumber: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request1 = payload.pull_request) === null || _payload_pull_request1 === void 0 ? void 0 : _payload_pull_request1.number) || null,
|
|
211
|
+
prHeadCommit: (payload === null || payload === void 0 ? void 0 : (_payload_pull_request2 = payload.pull_request) === null || _payload_pull_request2 === void 0 ? void 0 : _payload_pull_request2.head.sha) ?? null
|
|
212
|
+
};
|
|
148
213
|
}
|
|
149
214
|
};
|
|
150
215
|
|
|
@@ -243,21 +308,6 @@ const service = {
|
|
|
243
308
|
}
|
|
244
309
|
};
|
|
245
310
|
|
|
246
|
-
const KEY = "@argos-ci/core";
|
|
247
|
-
const debug = createDebug(KEY);
|
|
248
|
-
const debugTime = (arg)=>{
|
|
249
|
-
const enabled = createDebug.enabled(KEY);
|
|
250
|
-
if (enabled) {
|
|
251
|
-
console.time(arg);
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
const debugTimeEnd = (arg)=>{
|
|
255
|
-
const enabled = createDebug.enabled(KEY);
|
|
256
|
-
if (enabled) {
|
|
257
|
-
console.timeEnd(arg);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
|
|
261
311
|
// List of services ordered by usage
|
|
262
312
|
// "git" must be the last one
|
|
263
313
|
const services = [
|
|
@@ -270,7 +320,7 @@ const services = [
|
|
|
270
320
|
service$7,
|
|
271
321
|
service
|
|
272
322
|
];
|
|
273
|
-
|
|
323
|
+
async function getCiEnvironment({ env = process.env } = {}) {
|
|
274
324
|
const ctx = {
|
|
275
325
|
env
|
|
276
326
|
};
|
|
@@ -281,7 +331,7 @@ const getCiEnvironment = ({ env = process.env } = {})=>{
|
|
|
281
331
|
// Service matched
|
|
282
332
|
if (service) {
|
|
283
333
|
debug("Internal service matched", service.name);
|
|
284
|
-
const variables = service.config(ctx);
|
|
334
|
+
const variables = await service.config(ctx);
|
|
285
335
|
const ciEnvironment = {
|
|
286
336
|
name: service.name,
|
|
287
337
|
...variables
|
|
@@ -290,7 +340,7 @@ const getCiEnvironment = ({ env = process.env } = {})=>{
|
|
|
290
340
|
return ciEnvironment;
|
|
291
341
|
}
|
|
292
342
|
return null;
|
|
293
|
-
}
|
|
343
|
+
}
|
|
294
344
|
|
|
295
345
|
const mustBeApiBaseUrl = (value)=>{
|
|
296
346
|
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
|
@@ -412,9 +462,9 @@ const createConfig = ()=>{
|
|
|
412
462
|
args: []
|
|
413
463
|
});
|
|
414
464
|
};
|
|
415
|
-
|
|
465
|
+
async function readConfig(options = {}) {
|
|
416
466
|
const config = createConfig();
|
|
417
|
-
const ciEnv = getCiEnvironment();
|
|
467
|
+
const ciEnv = await getCiEnvironment();
|
|
418
468
|
config.load({
|
|
419
469
|
apiBaseUrl: options.apiBaseUrl ?? config.get("apiBaseUrl"),
|
|
420
470
|
commit: options.commit ?? config.get("commit") ?? (ciEnv === null || ciEnv === void 0 ? void 0 : ciEnv.commit) ?? null,
|
|
@@ -436,7 +486,7 @@ const readConfig = (options = {})=>{
|
|
|
436
486
|
});
|
|
437
487
|
config.validate();
|
|
438
488
|
return config.get();
|
|
439
|
-
}
|
|
489
|
+
}
|
|
440
490
|
|
|
441
491
|
const discoverScreenshots = async (patterns, { root = process.cwd(), ignore } = {})=>{
|
|
442
492
|
const matches = await glob(patterns, {
|
|
@@ -581,15 +631,14 @@ const upload$1 = async (input)=>{
|
|
|
581
631
|
/**
|
|
582
632
|
* Size of the chunks used to upload screenshots to Argos.
|
|
583
633
|
*/ const CHUNK_SIZE = 10;
|
|
584
|
-
|
|
585
|
-
|
|
634
|
+
async function getConfigFromOptions({ parallel, ...options }) {
|
|
635
|
+
return readConfig({
|
|
586
636
|
...options,
|
|
587
637
|
parallel: Boolean(parallel),
|
|
588
638
|
parallelNonce: parallel ? parallel.nonce : null,
|
|
589
639
|
parallelTotal: parallel ? parallel.total : null
|
|
590
640
|
});
|
|
591
|
-
|
|
592
|
-
};
|
|
641
|
+
}
|
|
593
642
|
async function uploadFilesToS3(files) {
|
|
594
643
|
debug(`Split files in chunks of ${CHUNK_SIZE}`);
|
|
595
644
|
const chunks = chunk(files, CHUNK_SIZE);
|
|
@@ -611,11 +660,11 @@ async function uploadFilesToS3(files) {
|
|
|
611
660
|
}
|
|
612
661
|
/**
|
|
613
662
|
* Upload screenshots to argos-ci.com.
|
|
614
|
-
*/
|
|
663
|
+
*/ async function upload(params) {
|
|
615
664
|
var _result_pwTraces;
|
|
616
665
|
debug("Starting upload with params", params);
|
|
617
666
|
// Read config
|
|
618
|
-
const config = getConfigFromOptions(params);
|
|
667
|
+
const config = await getConfigFromOptions(params);
|
|
619
668
|
const files = params.files ?? [
|
|
620
669
|
"**/*.{png,jpg,jpeg}"
|
|
621
670
|
];
|
|
@@ -728,6 +777,6 @@ async function uploadFilesToS3(files) {
|
|
|
728
777
|
build: result.build,
|
|
729
778
|
screenshots
|
|
730
779
|
};
|
|
731
|
-
}
|
|
780
|
+
}
|
|
732
781
|
|
|
733
782
|
export { readConfig, upload };
|
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.
|
|
4
|
+
"version": "1.4.2-alpha.6+505aabe",
|
|
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": "505aabe2ed2b8455172e9a8a473bccf683591a7c"
|
|
63
63
|
}
|