@argos-ci/core 0.6.1 → 0.6.3-alpha.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/README.md +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +102 -61
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import * as sharp from 'sharp';
|
|
2
|
-
|
|
3
1
|
interface UploadParameters {
|
|
4
2
|
/** Globs matching image file paths to upload */
|
|
5
3
|
files?: string[];
|
|
@@ -15,6 +13,8 @@ interface UploadParameters {
|
|
|
15
13
|
branch?: string;
|
|
16
14
|
/** Argos repository token */
|
|
17
15
|
token?: string;
|
|
16
|
+
/** Pull-request number */
|
|
17
|
+
prNumber?: number;
|
|
18
18
|
/** Name of the build used to trigger multiple Argos builds on one commit */
|
|
19
19
|
buildName?: string;
|
|
20
20
|
/** Parallel test suite mode */
|
|
@@ -35,8 +35,7 @@ declare const upload: (params: UploadParameters) => Promise<{
|
|
|
35
35
|
};
|
|
36
36
|
screenshots: {
|
|
37
37
|
optimizedPath: string;
|
|
38
|
-
|
|
39
|
-
hash: any;
|
|
38
|
+
hash: string;
|
|
40
39
|
name: string;
|
|
41
40
|
path: string;
|
|
42
41
|
}[];
|
package/dist/index.mjs
CHANGED
|
@@ -93,6 +93,11 @@ const schema = {
|
|
|
93
93
|
default: null,
|
|
94
94
|
nullable: true
|
|
95
95
|
},
|
|
96
|
+
prNumber: {
|
|
97
|
+
format: String,
|
|
98
|
+
default: null,
|
|
99
|
+
nullable: true
|
|
100
|
+
},
|
|
96
101
|
owner: {
|
|
97
102
|
format: String,
|
|
98
103
|
default: null,
|
|
@@ -122,7 +127,7 @@ const createConfig = ()=>{
|
|
|
122
127
|
return result;
|
|
123
128
|
};
|
|
124
129
|
|
|
125
|
-
const service$
|
|
130
|
+
const service$3 = {
|
|
126
131
|
detect: ({ env })=>Boolean(env.HEROKU_TEST_RUN_ID),
|
|
127
132
|
config: ({ env })=>({
|
|
128
133
|
name: "Heroku",
|
|
@@ -131,7 +136,8 @@ const service$1 = {
|
|
|
131
136
|
owner: null,
|
|
132
137
|
repository: null,
|
|
133
138
|
jobId: env.HEROKU_TEST_RUN_ID || null,
|
|
134
|
-
runId: null
|
|
139
|
+
runId: null,
|
|
140
|
+
prNumber: null
|
|
135
141
|
})
|
|
136
142
|
};
|
|
137
143
|
|
|
@@ -183,7 +189,15 @@ function getRepository({ env }) {
|
|
|
183
189
|
if (!env.GITHUB_REPOSITORY) return null;
|
|
184
190
|
return env.GITHUB_REPOSITORY.split("/")[1];
|
|
185
191
|
}
|
|
186
|
-
const
|
|
192
|
+
const getPrNumber$1 = ({ env })=>{
|
|
193
|
+
const branchRegex = /refs\/pull\/(\d+)/;
|
|
194
|
+
const branchMatches = branchRegex.exec(env.GITHUB_REF || "");
|
|
195
|
+
if (branchMatches) {
|
|
196
|
+
branchMatches[1];
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
};
|
|
200
|
+
const service$2 = {
|
|
187
201
|
detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
|
|
188
202
|
config: ({ env })=>({
|
|
189
203
|
name: "GitHub Actions",
|
|
@@ -198,24 +212,68 @@ const service = {
|
|
|
198
212
|
env
|
|
199
213
|
}),
|
|
200
214
|
jobId: env.GITHUB_JOB || null,
|
|
201
|
-
runId: env.GITHUB_RUN_ID || null
|
|
215
|
+
runId: env.GITHUB_RUN_ID || null,
|
|
216
|
+
prNumber: getPrNumber$1({
|
|
217
|
+
env
|
|
218
|
+
})
|
|
202
219
|
})
|
|
203
220
|
};
|
|
204
221
|
|
|
222
|
+
const getPrNumber = ({ env })=>{
|
|
223
|
+
const branchRegex = /pull\/(\d+)/;
|
|
224
|
+
const branchMatches = branchRegex.exec(env.CIRCLE_PULL_REQUEST || "");
|
|
225
|
+
if (branchMatches) {
|
|
226
|
+
branchMatches[1];
|
|
227
|
+
}
|
|
228
|
+
return null;
|
|
229
|
+
};
|
|
230
|
+
const service$1 = {
|
|
231
|
+
detect: ({ env })=>Boolean(env.CIRCLECI),
|
|
232
|
+
config: ({ env })=>{
|
|
233
|
+
const ciProps = envCiDetection({
|
|
234
|
+
env
|
|
235
|
+
});
|
|
236
|
+
return {
|
|
237
|
+
name: "CircleCI",
|
|
238
|
+
commit: ciProps?.commit || null,
|
|
239
|
+
branch: ciProps?.branch || null,
|
|
240
|
+
owner: ciProps?.owner || null,
|
|
241
|
+
repository: ciProps?.repository || null,
|
|
242
|
+
jobId: ciProps?.jobId || null,
|
|
243
|
+
runId: ciProps?.runId || null,
|
|
244
|
+
prNumber: getPrNumber({
|
|
245
|
+
env
|
|
246
|
+
})
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const service = {
|
|
252
|
+
detect: ({ env })=>Boolean(env.TRAVIS),
|
|
253
|
+
config: ({ env })=>{
|
|
254
|
+
const ciProps = envCiDetection({
|
|
255
|
+
env
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
name: "Travis CI",
|
|
259
|
+
commit: ciProps?.commit || null,
|
|
260
|
+
branch: ciProps?.branch || null,
|
|
261
|
+
owner: ciProps?.owner || null,
|
|
262
|
+
repository: ciProps?.repository || null,
|
|
263
|
+
jobId: ciProps?.jobId || null,
|
|
264
|
+
runId: ciProps?.runId || null,
|
|
265
|
+
prNumber: env.TRAVIS_PULL_REQUEST || null
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
205
270
|
const services = [
|
|
271
|
+
service$3,
|
|
272
|
+
service$2,
|
|
206
273
|
service$1,
|
|
207
274
|
service
|
|
208
275
|
];
|
|
209
|
-
const
|
|
210
|
-
const ctx = {
|
|
211
|
-
env
|
|
212
|
-
};
|
|
213
|
-
const service = services.find((service)=>service.detect(ctx));
|
|
214
|
-
// Internal service matched
|
|
215
|
-
if (service) {
|
|
216
|
-
return service.config(ctx);
|
|
217
|
-
}
|
|
218
|
-
// Fallback on env-ci detection
|
|
276
|
+
const envCiDetection = (ctx)=>{
|
|
219
277
|
const ciContext = envCi(ctx);
|
|
220
278
|
const name = ciContext.isCi ? ciContext.name ?? null : ciContext.commit ? "Git" : null;
|
|
221
279
|
const commit = ciContext.commit ?? null;
|
|
@@ -225,6 +283,7 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
225
283
|
const repository = slug ? slug[1] : null;
|
|
226
284
|
const jobId = ciContext.job ?? null;
|
|
227
285
|
const runId = null;
|
|
286
|
+
const prNumber = null;
|
|
228
287
|
return commit ? {
|
|
229
288
|
name,
|
|
230
289
|
commit,
|
|
@@ -232,9 +291,21 @@ const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
|
232
291
|
owner,
|
|
233
292
|
repository,
|
|
234
293
|
jobId,
|
|
235
|
-
runId
|
|
294
|
+
runId,
|
|
295
|
+
prNumber
|
|
236
296
|
} : null;
|
|
237
297
|
};
|
|
298
|
+
const getCiEnvironment = ({ env =process.env } = {})=>{
|
|
299
|
+
const ctx = {
|
|
300
|
+
env
|
|
301
|
+
};
|
|
302
|
+
const service = services.find((service)=>service.detect(ctx));
|
|
303
|
+
// Internal service matched
|
|
304
|
+
if (service) {
|
|
305
|
+
return service.config(ctx);
|
|
306
|
+
}
|
|
307
|
+
return envCiDetection(ctx);
|
|
308
|
+
};
|
|
238
309
|
|
|
239
310
|
const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } = {})=>{
|
|
240
311
|
const matches = await glob(patterns, {
|
|
@@ -249,33 +320,14 @@ const discoverScreenshots = async (patterns, { root =process.cwd() , ignore } =
|
|
|
249
320
|
};
|
|
250
321
|
|
|
251
322
|
const tmpFile = promisify(tmp.file);
|
|
252
|
-
const
|
|
253
|
-
const metadata = await sharp(filepath).metadata();
|
|
254
|
-
if (!metadata.format) {
|
|
255
|
-
throw new Error(`Could not get image format for ${filepath}`);
|
|
256
|
-
}
|
|
257
|
-
return metadata.format;
|
|
258
|
-
};
|
|
259
|
-
const optimizeScreenshot = async (filepath, format)=>{
|
|
323
|
+
const optimizeScreenshot = async (filepath)=>{
|
|
260
324
|
const resultFilePath = await tmpFile();
|
|
261
|
-
|
|
325
|
+
await sharp(filepath).resize(2048, 20480, {
|
|
262
326
|
fit: "inside",
|
|
263
327
|
withoutEnlargement: true
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
case "jpg":
|
|
268
|
-
{
|
|
269
|
-
optimization.jpeg();
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
case "png":
|
|
273
|
-
{
|
|
274
|
-
optimization.png();
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
await optimization.toFile(resultFilePath);
|
|
328
|
+
}).png({
|
|
329
|
+
force: true
|
|
330
|
+
}).toFile(resultFilePath);
|
|
279
331
|
return resultFilePath;
|
|
280
332
|
};
|
|
281
333
|
|
|
@@ -288,11 +340,11 @@ const hashFile = async (filepath)=>{
|
|
|
288
340
|
hash.on("finish", resolve);
|
|
289
341
|
fileStream.pipe(hash);
|
|
290
342
|
});
|
|
291
|
-
return hash.
|
|
343
|
+
return hash.digest("hex");
|
|
292
344
|
};
|
|
293
345
|
|
|
294
346
|
const base64Encode = (obj)=>Buffer.from(JSON.stringify(obj), "utf8").toString("base64");
|
|
295
|
-
const getBearerToken = ({ token , ciService , owner , repository , jobId , runId })=>{
|
|
347
|
+
const getBearerToken = ({ token , ciService , owner , repository , jobId , runId , prNumber })=>{
|
|
296
348
|
if (token) return `Bearer ${token}`;
|
|
297
349
|
switch(ciService){
|
|
298
350
|
case "GitHub Actions":
|
|
@@ -304,7 +356,8 @@ const getBearerToken = ({ token , ciService , owner , repository , jobId , runId
|
|
|
304
356
|
owner,
|
|
305
357
|
repository,
|
|
306
358
|
jobId,
|
|
307
|
-
runId
|
|
359
|
+
runId,
|
|
360
|
+
prNumber
|
|
308
361
|
})}`;
|
|
309
362
|
}
|
|
310
363
|
default:
|
|
@@ -349,17 +402,6 @@ const createArgosApiClient = (options)=>{
|
|
|
349
402
|
};
|
|
350
403
|
};
|
|
351
404
|
|
|
352
|
-
const formatToContentType = (format)=>{
|
|
353
|
-
switch(format){
|
|
354
|
-
case "jpeg":
|
|
355
|
-
case "jpg":
|
|
356
|
-
return "image/jpeg";
|
|
357
|
-
case "png":
|
|
358
|
-
return "image/png";
|
|
359
|
-
default:
|
|
360
|
-
throw new Error(`Unsupported format ${format}`);
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
405
|
const upload$1 = async (input)=>{
|
|
364
406
|
const file = await readFile(input.path);
|
|
365
407
|
await axios({
|
|
@@ -367,7 +409,7 @@ const upload$1 = async (input)=>{
|
|
|
367
409
|
url: input.url,
|
|
368
410
|
data: file,
|
|
369
411
|
headers: {
|
|
370
|
-
"Content-Type":
|
|
412
|
+
"Content-Type": "image/png"
|
|
371
413
|
}
|
|
372
414
|
});
|
|
373
415
|
};
|
|
@@ -375,13 +417,14 @@ const upload$1 = async (input)=>{
|
|
|
375
417
|
const debug = createDebug("@argos-ci/core");
|
|
376
418
|
|
|
377
419
|
const getConfigFromOptions = (options)=>{
|
|
378
|
-
const { apiBaseUrl , commit , branch , token , buildName , parallel } = options;
|
|
420
|
+
const { apiBaseUrl , commit , branch , token , buildName , parallel , prNumber } = options;
|
|
379
421
|
const config = createConfig();
|
|
380
422
|
config.load(omitUndefined({
|
|
381
423
|
apiBaseUrl,
|
|
382
424
|
commit,
|
|
383
425
|
branch,
|
|
384
426
|
token,
|
|
427
|
+
prNumber,
|
|
385
428
|
buildName,
|
|
386
429
|
parallel: Boolean(parallel),
|
|
387
430
|
parallelNonce: parallel ? parallel.nonce : null,
|
|
@@ -397,7 +440,8 @@ const getConfigFromOptions = (options)=>{
|
|
|
397
440
|
owner: ciEnv.owner,
|
|
398
441
|
repository: ciEnv.repository,
|
|
399
442
|
jobId: ciEnv.jobId,
|
|
400
|
-
runId: ciEnv.runId
|
|
443
|
+
runId: ciEnv.runId,
|
|
444
|
+
prNumber: ciEnv.prNumber
|
|
401
445
|
}));
|
|
402
446
|
}
|
|
403
447
|
}
|
|
@@ -423,13 +467,11 @@ const getConfigFromOptions = (options)=>{
|
|
|
423
467
|
});
|
|
424
468
|
// Optimize & compute hashes
|
|
425
469
|
const screenshots = await Promise.all(foundScreenshots.map(async (screenshot)=>{
|
|
426
|
-
const
|
|
427
|
-
const optimizedPath = await optimizeScreenshot(screenshot.path, format);
|
|
470
|
+
const optimizedPath = await optimizeScreenshot(screenshot.path);
|
|
428
471
|
const hash = await hashFile(optimizedPath);
|
|
429
472
|
return {
|
|
430
473
|
...screenshot,
|
|
431
474
|
optimizedPath,
|
|
432
|
-
format,
|
|
433
475
|
hash
|
|
434
476
|
};
|
|
435
477
|
}));
|
|
@@ -453,8 +495,7 @@ const getConfigFromOptions = (options)=>{
|
|
|
453
495
|
}
|
|
454
496
|
await upload$1({
|
|
455
497
|
url: putUrl,
|
|
456
|
-
path: screenshot.optimizedPath
|
|
457
|
-
format: screenshot.format
|
|
498
|
+
path: screenshot.optimizedPath
|
|
458
499
|
});
|
|
459
500
|
}));
|
|
460
501
|
// Update build
|
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.6.1",
|
|
4
|
+
"version": "0.6.3-alpha.1+46d7443",
|
|
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": "46d7443fe360fe5d42482e404bd3ab5c05116567"
|
|
64
64
|
}
|