@argos-ci/core 0.7.0 → 0.7.1
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 +62 -52
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import convict from 'convict';
|
|
2
2
|
import envCi from 'env-ci';
|
|
3
3
|
import { execSync } from 'child_process';
|
|
4
|
+
import createDebug from 'debug';
|
|
4
5
|
import { resolve } from 'node:path';
|
|
5
6
|
import glob from 'fast-glob';
|
|
6
7
|
import { promisify } from 'node:util';
|
|
@@ -10,7 +11,6 @@ import { createReadStream } from 'node:fs';
|
|
|
10
11
|
import { createHash } from 'node:crypto';
|
|
11
12
|
import axios from 'axios';
|
|
12
13
|
import { readFile } from 'node:fs/promises';
|
|
13
|
-
import createDebug from 'debug';
|
|
14
14
|
|
|
15
15
|
const mustBeApiBaseUrl = (value)=>{
|
|
16
16
|
const URL_REGEX = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
|
@@ -41,14 +41,13 @@ const schema = {
|
|
|
41
41
|
},
|
|
42
42
|
commit: {
|
|
43
43
|
env: "ARGOS_COMMIT",
|
|
44
|
-
default:
|
|
44
|
+
default: null,
|
|
45
45
|
format: mustBeCommit
|
|
46
46
|
},
|
|
47
47
|
branch: {
|
|
48
48
|
env: "ARGOS_BRANCH",
|
|
49
49
|
default: null,
|
|
50
|
-
format: String
|
|
51
|
-
nullable: true
|
|
50
|
+
format: String
|
|
52
51
|
},
|
|
53
52
|
token: {
|
|
54
53
|
env: "ARGOS_TOKEN",
|
|
@@ -61,6 +60,12 @@ const schema = {
|
|
|
61
60
|
format: String,
|
|
62
61
|
nullable: true
|
|
63
62
|
},
|
|
63
|
+
prNumber: {
|
|
64
|
+
env: "ARGOS_PR_NUMBER",
|
|
65
|
+
format: Number,
|
|
66
|
+
default: null,
|
|
67
|
+
nullable: true
|
|
68
|
+
},
|
|
64
69
|
parallel: {
|
|
65
70
|
env: "ARGOS_PARALLEL",
|
|
66
71
|
default: false,
|
|
@@ -93,11 +98,6 @@ const schema = {
|
|
|
93
98
|
default: null,
|
|
94
99
|
nullable: true
|
|
95
100
|
},
|
|
96
|
-
prNumber: {
|
|
97
|
-
format: Number,
|
|
98
|
-
default: null,
|
|
99
|
-
nullable: true
|
|
100
|
-
},
|
|
101
101
|
owner: {
|
|
102
102
|
format: String,
|
|
103
103
|
default: null,
|
|
@@ -115,26 +115,14 @@ const createConfig = ()=>{
|
|
|
115
115
|
});
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
/**
|
|
119
|
-
* Omit undefined properties from an object.
|
|
120
|
-
*/ const omitUndefined = (obj)=>{
|
|
121
|
-
const result = {};
|
|
122
|
-
Object.keys(obj).forEach((key)=>{
|
|
123
|
-
if (obj[key] !== undefined) {
|
|
124
|
-
result[key] = obj[key];
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
return result;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
118
|
const service$4 = {
|
|
119
|
+
name: "Buildkite",
|
|
131
120
|
detect: ({ env })=>Boolean(env.BUILDKITE),
|
|
132
121
|
config: ({ env })=>{
|
|
133
122
|
const ciProps = envCiDetection({
|
|
134
123
|
env
|
|
135
124
|
});
|
|
136
125
|
return {
|
|
137
|
-
name: "Buildkite",
|
|
138
126
|
commit: ciProps?.commit || null,
|
|
139
127
|
branch: env.BUILDKITE_BRANCH || null,
|
|
140
128
|
owner: env.BUILDKITE_ORGANIZATION_SLUG || null,
|
|
@@ -147,9 +135,9 @@ const service$4 = {
|
|
|
147
135
|
};
|
|
148
136
|
|
|
149
137
|
const service$3 = {
|
|
138
|
+
name: "Heroku",
|
|
150
139
|
detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
|
|
151
140
|
config: ({ env })=>({
|
|
152
|
-
name: "Heroku",
|
|
153
141
|
commit: env.HEROKU_TEST_RUN_COMMIT_VERSION || null,
|
|
154
142
|
branch: env.HEROKU_TEST_RUN_BRANCH || null,
|
|
155
143
|
owner: null,
|
|
@@ -217,9 +205,9 @@ const getPrNumber$1 = ({ env })=>{
|
|
|
217
205
|
return null;
|
|
218
206
|
};
|
|
219
207
|
const service$2 = {
|
|
208
|
+
name: "GitHub Actions",
|
|
220
209
|
detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
|
|
221
210
|
config: ({ env })=>({
|
|
222
|
-
name: "GitHub Actions",
|
|
223
211
|
commit: getSha({
|
|
224
212
|
env
|
|
225
213
|
}),
|
|
@@ -247,13 +235,13 @@ const getPrNumber = ({ env })=>{
|
|
|
247
235
|
return null;
|
|
248
236
|
};
|
|
249
237
|
const service$1 = {
|
|
238
|
+
name: "CircleCI",
|
|
250
239
|
detect: ({ env })=>Boolean(env.CIRCLECI),
|
|
251
240
|
config: ({ env })=>{
|
|
252
241
|
const ciProps = envCiDetection({
|
|
253
242
|
env
|
|
254
243
|
});
|
|
255
244
|
return {
|
|
256
|
-
name: "CircleCI",
|
|
257
245
|
commit: ciProps?.commit || null,
|
|
258
246
|
branch: ciProps?.branch || null,
|
|
259
247
|
owner: ciProps?.owner || null,
|
|
@@ -268,13 +256,13 @@ const service$1 = {
|
|
|
268
256
|
};
|
|
269
257
|
|
|
270
258
|
const service = {
|
|
259
|
+
name: "Travis CI",
|
|
271
260
|
detect: ({ env })=>Boolean(env.TRAVIS),
|
|
272
261
|
config: ({ env })=>{
|
|
273
262
|
const ciProps = envCiDetection({
|
|
274
263
|
env
|
|
275
264
|
});
|
|
276
265
|
return {
|
|
277
|
-
name: "Travis CI",
|
|
278
266
|
commit: ciProps?.commit || null,
|
|
279
267
|
branch: ciProps?.branch || null,
|
|
280
268
|
owner: ciProps?.owner || null,
|
|
@@ -286,6 +274,8 @@ const service = {
|
|
|
286
274
|
}
|
|
287
275
|
};
|
|
288
276
|
|
|
277
|
+
const debug = createDebug("@argos-ci/core");
|
|
278
|
+
|
|
289
279
|
const services = [
|
|
290
280
|
service$3,
|
|
291
281
|
service$2,
|
|
@@ -319,12 +309,25 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
319
309
|
const ctx = {
|
|
320
310
|
env
|
|
321
311
|
};
|
|
312
|
+
debug("Detecting CI environment", {
|
|
313
|
+
env
|
|
314
|
+
});
|
|
322
315
|
const service = services.find((service)=>service.detect(ctx));
|
|
323
316
|
// Internal service matched
|
|
324
317
|
if (service) {
|
|
325
|
-
|
|
318
|
+
debug("Internal service matched", service.name);
|
|
319
|
+
const variables = service.config(ctx);
|
|
320
|
+
const ciEnvironment = {
|
|
321
|
+
name: service.name,
|
|
322
|
+
...variables
|
|
323
|
+
};
|
|
324
|
+
debug("CI environment", ciEnvironment);
|
|
325
|
+
return ciEnvironment;
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
debug("Falling back on env-ci");
|
|
328
|
+
const ciEnvironment1 = envCiDetection(ctx);
|
|
329
|
+
debug("CI environment", ciEnvironment1);
|
|
330
|
+
return ciEnvironment1;
|
|
328
331
|
};
|
|
329
332
|
|
|
330
333
|
const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } = {})=>{
|
|
@@ -395,11 +398,20 @@ const createArgosApiClient = (options)=>{
|
|
|
395
398
|
});
|
|
396
399
|
const call = async (method, path, data)=>{
|
|
397
400
|
try {
|
|
401
|
+
debug("Sending request", {
|
|
402
|
+
method,
|
|
403
|
+
path,
|
|
404
|
+
data
|
|
405
|
+
});
|
|
398
406
|
const response = await axiosInstance.request({
|
|
399
407
|
method,
|
|
400
408
|
url: path,
|
|
401
409
|
data
|
|
402
410
|
});
|
|
411
|
+
debug("Getting response", {
|
|
412
|
+
status: response.status,
|
|
413
|
+
data: response.data
|
|
414
|
+
});
|
|
403
415
|
return response.data;
|
|
404
416
|
} catch (error) {
|
|
405
417
|
if (error?.response?.data?.error?.message) {
|
|
@@ -434,45 +446,42 @@ const upload$1 = async (input)=>{
|
|
|
434
446
|
});
|
|
435
447
|
};
|
|
436
448
|
|
|
437
|
-
const debug = createDebug("@argos-ci/core");
|
|
438
|
-
|
|
439
449
|
const getConfigFromOptions = (options)=>{
|
|
440
450
|
const config = createConfig();
|
|
441
451
|
const ciEnv = getCiEnvironment();
|
|
442
|
-
|
|
443
|
-
config.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
452
|
+
config.load({
|
|
453
|
+
apiBaseUrl: config.get("apiBaseUrl") ?? options.apiBaseUrl,
|
|
454
|
+
commit: config.get("commit") ?? options.commit ?? ciEnv?.commit ?? null,
|
|
455
|
+
branch: config.get("branch") ?? options.branch ?? ciEnv?.branch ?? null,
|
|
456
|
+
token: config.get("token") ?? options.token ?? null,
|
|
457
|
+
buildName: config.get("buildName") ?? options.buildName ?? null,
|
|
458
|
+
prNumber: config.get("prNumber") ?? options.prNumber ?? ciEnv?.prNumber ?? null,
|
|
459
|
+
ciService: ciEnv?.name ?? null,
|
|
460
|
+
owner: ciEnv?.owner ?? null,
|
|
461
|
+
repository: ciEnv?.repository ?? null,
|
|
462
|
+
jobId: ciEnv?.jobId ?? null,
|
|
463
|
+
runId: ciEnv?.runId ?? null
|
|
464
|
+
});
|
|
465
|
+
if (options.parallel) {
|
|
466
|
+
config.load({
|
|
467
|
+
parallel: Boolean(options.parallel),
|
|
468
|
+
parallelNonce: options.parallel ? options.parallel.nonce : null,
|
|
469
|
+
parallelTotal: options.parallel ? options.parallel.total : null
|
|
470
|
+
});
|
|
453
471
|
}
|
|
454
|
-
config.load(omitUndefined({
|
|
455
|
-
apiBaseUrl: options.apiBaseUrl,
|
|
456
|
-
commit: options.commit,
|
|
457
|
-
branch: options.branch,
|
|
458
|
-
token: options.token,
|
|
459
|
-
prNumber: options.prNumber,
|
|
460
|
-
buildName: options.buildName,
|
|
461
|
-
parallel: Boolean(options.parallel),
|
|
462
|
-
parallelNonce: options.parallel ? options.parallel.nonce : null,
|
|
463
|
-
parallelTotal: options.parallel ? options.parallel.total : null
|
|
464
|
-
}));
|
|
465
472
|
config.validate();
|
|
466
473
|
return config.get();
|
|
467
474
|
};
|
|
468
475
|
/**
|
|
469
476
|
* Upload screenshots to argos-ci.com.
|
|
470
477
|
*/ const upload = async (params)=>{
|
|
478
|
+
debug("Starting upload with params", params);
|
|
471
479
|
// Read config
|
|
472
480
|
const config = getConfigFromOptions(params);
|
|
473
481
|
const files = params.files ?? [
|
|
474
482
|
"**/*.{png,jpg,jpeg}"
|
|
475
483
|
];
|
|
484
|
+
debug("Using config and files", config, files);
|
|
476
485
|
const apiClient = createArgosApiClient({
|
|
477
486
|
baseUrl: config.apiBaseUrl,
|
|
478
487
|
bearerToken: getBearerToken(config)
|
|
@@ -482,6 +491,7 @@ const getConfigFromOptions = (options)=>{
|
|
|
482
491
|
root: params.root,
|
|
483
492
|
ignore: params.ignore
|
|
484
493
|
});
|
|
494
|
+
debug("Found screenshots", foundScreenshots);
|
|
485
495
|
// Optimize & compute hashes
|
|
486
496
|
const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
|
|
487
497
|
const optimizedPath = await optimizeScreenshot(screenshot.path);
|
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": "0.7.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "rm -rf dist",
|
|
7
7
|
"build": "rollup -c",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"rollup-plugin-dts": "^4.2.3",
|
|
61
61
|
"rollup-plugin-swc3": "^0.6.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "0ae6b18c7728deb14beb7ffee85e9faf104c4365"
|
|
64
64
|
}
|