@argos-ci/cli 0.4.2 → 0.4.4
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 +65 -65
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -4,14 +4,13 @@ import { resolve } from 'node:path';
|
|
|
4
4
|
import { program } from 'commander';
|
|
5
5
|
import convict from 'convict';
|
|
6
6
|
import { execSync } from 'node:child_process';
|
|
7
|
-
import {
|
|
7
|
+
import { existsSync, readFileSync, createReadStream } from 'node:fs';
|
|
8
8
|
import createDebug from 'debug';
|
|
9
9
|
import envCi from 'env-ci';
|
|
10
10
|
import glob from 'fast-glob';
|
|
11
11
|
import { promisify } from 'node:util';
|
|
12
12
|
import sharp from 'sharp';
|
|
13
13
|
import tmp from 'tmp';
|
|
14
|
-
import { createReadStream } from 'node:fs';
|
|
15
14
|
import { createHash } from 'node:crypto';
|
|
16
15
|
import axios from 'axios';
|
|
17
16
|
import ora from 'ora';
|
|
@@ -173,39 +172,6 @@ const service$3 = {
|
|
|
173
172
|
})
|
|
174
173
|
};
|
|
175
174
|
|
|
176
|
-
const getSha = ({ env })=>{
|
|
177
|
-
const isPr = env.GITHUB_EVENT_NAME === "pull_request" || env.GITHUB_EVENT_NAME === "pull_request_target";
|
|
178
|
-
if (isPr) {
|
|
179
|
-
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/;
|
|
180
|
-
const mergeCommitMessage = execSync$1("git show --no-patch --format=%P").toString().trim();
|
|
181
|
-
// console.log(
|
|
182
|
-
// `Handling PR with parent hash(es) '${mergeCommitMessage}' of current commit.`
|
|
183
|
-
// );
|
|
184
|
-
if (mergeCommitRegex.exec(mergeCommitMessage)) {
|
|
185
|
-
const mergeCommit = mergeCommitMessage.split(" ")[1];
|
|
186
|
-
// console.log(
|
|
187
|
-
// `Fixing merge commit SHA ${process.env.GITHUB_SHA} -> ${mergeCommit}`
|
|
188
|
-
// );
|
|
189
|
-
return mergeCommit;
|
|
190
|
-
} else if (mergeCommitMessage === "") {
|
|
191
|
-
console.error(`Error: automatic detection of commit SHA failed.
|
|
192
|
-
|
|
193
|
-
Please run "actions/checkout" with "fetch-depth: 2". Example:
|
|
194
|
-
|
|
195
|
-
steps:
|
|
196
|
-
- uses: actions/checkout@v3
|
|
197
|
-
with:
|
|
198
|
-
fetch-depth: 2
|
|
199
|
-
|
|
200
|
-
`);
|
|
201
|
-
process.exit(1);
|
|
202
|
-
} else {
|
|
203
|
-
console.error(`Commit with SHA ${process.env.GITHUB_SHA} is not a valid commit`);
|
|
204
|
-
process.exit(1);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
return process.env.GITHUB_SHA ?? null;
|
|
208
|
-
};
|
|
209
175
|
const getBranch = ({ env })=>{
|
|
210
176
|
if (env.GITHUB_HEAD_REF) {
|
|
211
177
|
return env.GITHUB_HEAD_REF;
|
|
@@ -221,34 +187,32 @@ const getRepository$1 = ({ env })=>{
|
|
|
221
187
|
if (!env.GITHUB_REPOSITORY) return null;
|
|
222
188
|
return env.GITHUB_REPOSITORY.split("/")[1];
|
|
223
189
|
};
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return Number(branchMatches[1]);
|
|
229
|
-
}
|
|
230
|
-
return null;
|
|
190
|
+
const readEventPayload = ({ env })=>{
|
|
191
|
+
if (!env.GITHUB_EVENT_PATH) return null;
|
|
192
|
+
if (!existsSync(env.GITHUB_EVENT_PATH)) return null;
|
|
193
|
+
return JSON.parse(readFileSync(env.GITHUB_EVENT_PATH, "utf-8"));
|
|
231
194
|
};
|
|
232
195
|
const service$2 = {
|
|
233
196
|
name: "GitHub Actions",
|
|
234
197
|
detect: ({ env })=>Boolean(env.GITHUB_ACTIONS),
|
|
235
|
-
config: ({ env })=>
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
198
|
+
config: ({ env })=>{
|
|
199
|
+
const payload = readEventPayload({
|
|
200
|
+
env
|
|
201
|
+
});
|
|
202
|
+
return {
|
|
203
|
+
commit: payload?.pull_request?.head.sha || process.env.GITHUB_SHA || null,
|
|
204
|
+
branch: payload?.pull_request?.head.ref || getBranch({
|
|
240
205
|
env
|
|
241
|
-
}),
|
|
206
|
+
}) || null,
|
|
242
207
|
owner: env.GITHUB_REPOSITORY_OWNER || null,
|
|
243
208
|
repository: getRepository$1({
|
|
244
209
|
env
|
|
245
210
|
}),
|
|
246
211
|
jobId: env.GITHUB_JOB || null,
|
|
247
212
|
runId: env.GITHUB_RUN_ID || null,
|
|
248
|
-
prNumber:
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
})
|
|
213
|
+
prNumber: payload?.pull_request?.number || null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
252
216
|
};
|
|
253
217
|
|
|
254
218
|
const getPrNumber$1 = ({ env })=>{
|
|
@@ -306,7 +270,20 @@ const service = {
|
|
|
306
270
|
}
|
|
307
271
|
};
|
|
308
272
|
|
|
309
|
-
const
|
|
273
|
+
const KEY = "@argos-ci/core";
|
|
274
|
+
const debug = createDebug(KEY);
|
|
275
|
+
const debugTime = (arg)=>{
|
|
276
|
+
const enabled = createDebug.enabled(KEY);
|
|
277
|
+
if (enabled) {
|
|
278
|
+
console.time(arg);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
const debugTimeEnd = (arg)=>{
|
|
282
|
+
const enabled = createDebug.enabled(KEY);
|
|
283
|
+
if (enabled) {
|
|
284
|
+
console.timeEnd(arg);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
310
287
|
|
|
311
288
|
const getCiEnvironmentFromEnvCi = (ctx)=>{
|
|
312
289
|
const ciContext = envCi(ctx);
|
|
@@ -480,6 +457,22 @@ const upload$1 = async (input)=>{
|
|
|
480
457
|
});
|
|
481
458
|
};
|
|
482
459
|
|
|
460
|
+
/**
|
|
461
|
+
* Split an array into chunks of a given size.
|
|
462
|
+
*/ const chunk = (collection, size)=>{
|
|
463
|
+
const result = [];
|
|
464
|
+
// add each chunk to the result
|
|
465
|
+
for(let x = 0; x < Math.ceil(collection.length / size); x++){
|
|
466
|
+
let start = x * size;
|
|
467
|
+
let end = start + size;
|
|
468
|
+
result.push(collection.slice(start, end));
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Size of the chunks used to upload screenshots to Argos.
|
|
475
|
+
*/ const CHUNK_SIZE = 10;
|
|
483
476
|
const getConfigFromOptions = (options)=>{
|
|
484
477
|
const config = createConfig();
|
|
485
478
|
const ciEnv = getCiEnvironment();
|
|
@@ -548,18 +541,25 @@ const getConfigFromOptions = (options)=>{
|
|
|
548
541
|
prNumber: config.prNumber
|
|
549
542
|
});
|
|
550
543
|
debug("Got screenshots", result);
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
await
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
544
|
+
debug(`Split screenshots in chunks of ${CHUNK_SIZE}`);
|
|
545
|
+
const chunks = chunk(result.screenshots, CHUNK_SIZE);
|
|
546
|
+
debug(`Starting upload of ${chunks.length} chunks`);
|
|
547
|
+
for(let i = 0; i < chunks.length; i++){
|
|
548
|
+
debug(`Uploading chunk ${i + 1}/${chunks.length}`);
|
|
549
|
+
const timeLabel = `Chunk ${i + 1}/${chunks.length}`;
|
|
550
|
+
debugTime(timeLabel);
|
|
551
|
+
await Promise.all(chunks[i].map(async ({ key , putUrl })=>{
|
|
552
|
+
const screenshot = screenshots.find((s)=>s.hash === key);
|
|
553
|
+
if (!screenshot) {
|
|
554
|
+
throw new Error(`Invariant: screenshot with hash ${key} not found`);
|
|
555
|
+
}
|
|
556
|
+
await upload$1({
|
|
557
|
+
url: putUrl,
|
|
558
|
+
path: screenshot.optimizedPath
|
|
559
|
+
});
|
|
560
|
+
}));
|
|
561
|
+
debugTimeEnd(timeLabel);
|
|
562
|
+
}
|
|
563
563
|
// Update build
|
|
564
564
|
debug("Updating build");
|
|
565
565
|
await apiClient.updateBuild({
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/cli",
|
|
3
3
|
"description": "Visual testing solution to avoid visual regression. Argos CLI is used to interact with and upload screenshots to argos-ci.com via command line.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.4",
|
|
5
5
|
"bin": {
|
|
6
6
|
"argos": "./bin/argos-cli.js"
|
|
7
7
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@argos-ci/core": "^0.
|
|
43
|
+
"@argos-ci/core": "^0.8.0",
|
|
44
44
|
"commander": "^9.4.1",
|
|
45
45
|
"ora": "^6.1.2",
|
|
46
46
|
"update-notifier": "^6.0.2"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"rollup": "^2.79.1",
|
|
50
50
|
"rollup-plugin-swc3": "^0.6.0"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "bad0f5b5bf1dc1672b05cf08a4fec5d011ac4b0a"
|
|
53
53
|
}
|