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