@code-pushup/cli 0.25.6 → 0.26.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/index.js +83 -81
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -320,23 +320,42 @@ function getDuplicateSlugCategories(categories) {
|
|
|
320
320
|
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
321
321
|
}
|
|
322
322
|
|
|
323
|
+
// packages/models/src/lib/commit.ts
|
|
324
|
+
import { z as z6 } from "zod";
|
|
325
|
+
var commitSchema = z6.object(
|
|
326
|
+
{
|
|
327
|
+
hash: z6.string({ description: "Commit SHA (full)" }).regex(
|
|
328
|
+
/^[\da-f]{40}$/,
|
|
329
|
+
"Commit SHA should be a 40-character hexadecimal string"
|
|
330
|
+
),
|
|
331
|
+
message: z6.string({ description: "Commit message" }),
|
|
332
|
+
date: z6.coerce.date({
|
|
333
|
+
description: "Date and time when commit was authored"
|
|
334
|
+
}),
|
|
335
|
+
author: z6.string({
|
|
336
|
+
description: "Commit author name"
|
|
337
|
+
}).trim()
|
|
338
|
+
},
|
|
339
|
+
{ description: "Git commit" }
|
|
340
|
+
);
|
|
341
|
+
|
|
323
342
|
// packages/models/src/lib/core-config.ts
|
|
324
|
-
import { z as
|
|
343
|
+
import { z as z12 } from "zod";
|
|
325
344
|
|
|
326
345
|
// packages/models/src/lib/persist-config.ts
|
|
327
|
-
import { z as
|
|
328
|
-
var formatSchema =
|
|
329
|
-
var persistConfigSchema =
|
|
346
|
+
import { z as z7 } from "zod";
|
|
347
|
+
var formatSchema = z7.enum(["json", "md"]);
|
|
348
|
+
var persistConfigSchema = z7.object({
|
|
330
349
|
outputDir: filePathSchema.describe("Artifacts folder").optional(),
|
|
331
350
|
filename: fileNameSchema.describe("Artifacts file name (without extension)").optional(),
|
|
332
|
-
format:
|
|
351
|
+
format: z7.array(formatSchema).optional()
|
|
333
352
|
});
|
|
334
353
|
|
|
335
354
|
// packages/models/src/lib/plugin-config.ts
|
|
336
|
-
import { z as
|
|
355
|
+
import { z as z10 } from "zod";
|
|
337
356
|
|
|
338
357
|
// packages/models/src/lib/group.ts
|
|
339
|
-
import { z as
|
|
358
|
+
import { z as z8 } from "zod";
|
|
340
359
|
var groupRefSchema = weightedRefSchema(
|
|
341
360
|
"Weighted reference to a group",
|
|
342
361
|
"Reference slug to a group within this plugin (e.g. 'max-lines')"
|
|
@@ -353,7 +372,7 @@ var groupSchema = scorableSchema(
|
|
|
353
372
|
getDuplicateRefsInGroups,
|
|
354
373
|
duplicateRefsInGroupsErrorMsg
|
|
355
374
|
).merge(groupMetaSchema);
|
|
356
|
-
var groupsSchema =
|
|
375
|
+
var groupsSchema = z8.array(groupSchema, {
|
|
357
376
|
description: "List of groups"
|
|
358
377
|
}).optional().refine(
|
|
359
378
|
(groups) => !getDuplicateSlugsInGroups(groups),
|
|
@@ -381,14 +400,14 @@ function getDuplicateSlugsInGroups(groups) {
|
|
|
381
400
|
}
|
|
382
401
|
|
|
383
402
|
// packages/models/src/lib/runner-config.ts
|
|
384
|
-
import { z as
|
|
385
|
-
var outputTransformSchema =
|
|
386
|
-
var runnerConfigSchema =
|
|
403
|
+
import { z as z9 } from "zod";
|
|
404
|
+
var outputTransformSchema = z9.function().args(z9.unknown()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
|
|
405
|
+
var runnerConfigSchema = z9.object(
|
|
387
406
|
{
|
|
388
|
-
command:
|
|
407
|
+
command: z9.string({
|
|
389
408
|
description: "Shell command to execute"
|
|
390
409
|
}),
|
|
391
|
-
args:
|
|
410
|
+
args: z9.array(z9.string({ description: "Command arguments" })).optional(),
|
|
392
411
|
outputFile: filePathSchema.describe("Output path"),
|
|
393
412
|
outputTransform: outputTransformSchema.optional()
|
|
394
413
|
},
|
|
@@ -396,8 +415,8 @@ var runnerConfigSchema = z8.object(
|
|
|
396
415
|
description: "How to execute runner"
|
|
397
416
|
}
|
|
398
417
|
);
|
|
399
|
-
var onProgressSchema =
|
|
400
|
-
var runnerFunctionSchema =
|
|
418
|
+
var onProgressSchema = z9.function().args(z9.unknown()).returns(z9.void());
|
|
419
|
+
var runnerFunctionSchema = z9.function().args(onProgressSchema.optional()).returns(z9.union([auditOutputsSchema, z9.promise(auditOutputsSchema)]));
|
|
401
420
|
|
|
402
421
|
// packages/models/src/lib/plugin-config.ts
|
|
403
422
|
var pluginMetaSchema = packageVersionSchema().merge(
|
|
@@ -408,13 +427,13 @@ var pluginMetaSchema = packageVersionSchema().merge(
|
|
|
408
427
|
description: "Plugin metadata"
|
|
409
428
|
})
|
|
410
429
|
).merge(
|
|
411
|
-
|
|
430
|
+
z10.object({
|
|
412
431
|
slug: slugSchema.describe("Unique plugin slug within core config"),
|
|
413
432
|
icon: materialIconSchema
|
|
414
433
|
})
|
|
415
434
|
);
|
|
416
|
-
var pluginDataSchema =
|
|
417
|
-
runner:
|
|
435
|
+
var pluginDataSchema = z10.object({
|
|
436
|
+
runner: z10.union([runnerConfigSchema, runnerFunctionSchema]),
|
|
418
437
|
audits: pluginAuditsSchema,
|
|
419
438
|
groups: groupsSchema
|
|
420
439
|
});
|
|
@@ -440,22 +459,22 @@ function getMissingRefsFromGroups(pluginCfg) {
|
|
|
440
459
|
}
|
|
441
460
|
|
|
442
461
|
// packages/models/src/lib/upload-config.ts
|
|
443
|
-
import { z as
|
|
444
|
-
var uploadConfigSchema =
|
|
462
|
+
import { z as z11 } from "zod";
|
|
463
|
+
var uploadConfigSchema = z11.object({
|
|
445
464
|
server: urlSchema.describe("URL of deployed portal API"),
|
|
446
|
-
apiKey:
|
|
465
|
+
apiKey: z11.string({
|
|
447
466
|
description: "API key with write access to portal (use `process.env` for security)"
|
|
448
467
|
}),
|
|
449
468
|
organization: slugSchema.describe(
|
|
450
469
|
"Organization slug from Code PushUp portal"
|
|
451
470
|
),
|
|
452
471
|
project: slugSchema.describe("Project slug from Code PushUp portal"),
|
|
453
|
-
timeout:
|
|
472
|
+
timeout: z11.number({ description: "Request timeout in minutes (default is 5)" }).positive().int().optional()
|
|
454
473
|
});
|
|
455
474
|
|
|
456
475
|
// packages/models/src/lib/core-config.ts
|
|
457
|
-
var unrefinedCoreConfigSchema =
|
|
458
|
-
plugins:
|
|
476
|
+
var unrefinedCoreConfigSchema = z12.object({
|
|
477
|
+
plugins: z12.array(pluginConfigSchema, {
|
|
459
478
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
460
479
|
}).min(1),
|
|
461
480
|
/** portal configuration for persisting results */
|
|
@@ -487,7 +506,7 @@ var PERSIST_FORMAT = ["json"];
|
|
|
487
506
|
var PERSIST_FILENAME = "report";
|
|
488
507
|
|
|
489
508
|
// packages/models/src/lib/report.ts
|
|
490
|
-
import { z as
|
|
509
|
+
import { z as z13 } from "zod";
|
|
491
510
|
var auditReportSchema = auditSchema.merge(auditOutputSchema);
|
|
492
511
|
var pluginReportSchema = pluginMetaSchema.merge(
|
|
493
512
|
executionMetaSchema({
|
|
@@ -495,9 +514,9 @@ var pluginReportSchema = pluginMetaSchema.merge(
|
|
|
495
514
|
descriptionDuration: "Duration of the plugin run in ms"
|
|
496
515
|
})
|
|
497
516
|
).merge(
|
|
498
|
-
|
|
499
|
-
audits:
|
|
500
|
-
groups:
|
|
517
|
+
z13.object({
|
|
518
|
+
audits: z13.array(auditReportSchema).min(1),
|
|
519
|
+
groups: z13.array(groupSchema).optional()
|
|
501
520
|
})
|
|
502
521
|
).refine(
|
|
503
522
|
(pluginReport) => !getMissingRefsFromGroups2(pluginReport.audits, pluginReport.groups ?? []),
|
|
@@ -531,10 +550,11 @@ var reportSchema = packageVersionSchema({
|
|
|
531
550
|
descriptionDuration: "Duration of the collect run in ms"
|
|
532
551
|
})
|
|
533
552
|
).merge(
|
|
534
|
-
|
|
553
|
+
z13.object(
|
|
535
554
|
{
|
|
536
|
-
categories:
|
|
537
|
-
plugins:
|
|
555
|
+
categories: z13.array(categoryConfigSchema),
|
|
556
|
+
plugins: z13.array(pluginReportSchema).min(1),
|
|
557
|
+
commit: commitSchema.describe("Git commit for which report was collected").nullable()
|
|
538
558
|
},
|
|
539
559
|
{ description: "Collect output data" }
|
|
540
560
|
)
|
|
@@ -983,9 +1003,12 @@ function toUnixPath(path) {
|
|
|
983
1003
|
async function getLatestCommit(git = simpleGit()) {
|
|
984
1004
|
const log = await git.log({
|
|
985
1005
|
maxCount: 1,
|
|
986
|
-
format: { hash: "%H", message: "%s", author: "%an", date: "%
|
|
1006
|
+
format: { hash: "%H", message: "%s", author: "%an", date: "%aI" }
|
|
987
1007
|
});
|
|
988
|
-
|
|
1008
|
+
if (!log.latest) {
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
return commitSchema.parse(log.latest);
|
|
989
1012
|
}
|
|
990
1013
|
function getGitRoot(git = simpleGit()) {
|
|
991
1014
|
return git.revparse("--show-toplevel");
|
|
@@ -995,18 +1018,6 @@ function formatGitPath(path, gitRoot) {
|
|
|
995
1018
|
const relativePath = relative(gitRoot, absolutePath);
|
|
996
1019
|
return toUnixPath(relativePath);
|
|
997
1020
|
}
|
|
998
|
-
function validateCommitData(commitData, options2 = {}) {
|
|
999
|
-
if (!commitData) {
|
|
1000
|
-
const msg = "no commit data available";
|
|
1001
|
-
if (options2.throwError) {
|
|
1002
|
-
throw new Error(msg);
|
|
1003
|
-
} else {
|
|
1004
|
-
console.warn(msg);
|
|
1005
|
-
return false;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
return true;
|
|
1009
|
-
}
|
|
1010
1021
|
|
|
1011
1022
|
// packages/utils/src/lib/group-by-status.ts
|
|
1012
1023
|
function groupByStatus(results) {
|
|
@@ -1154,7 +1165,7 @@ function tableHtml(data) {
|
|
|
1154
1165
|
}
|
|
1155
1166
|
|
|
1156
1167
|
// packages/utils/src/lib/reports/generate-md-report.ts
|
|
1157
|
-
function generateMdReport(report
|
|
1168
|
+
function generateMdReport(report) {
|
|
1158
1169
|
const printCategories = report.categories.length > 0;
|
|
1159
1170
|
return (
|
|
1160
1171
|
// header section
|
|
@@ -1163,7 +1174,7 @@ function generateMdReport(report, commitData) {
|
|
|
1163
1174
|
(printCategories ? reportToOverviewSection(report) + NEW_LINE + NEW_LINE : "") + // categories section
|
|
1164
1175
|
(printCategories ? reportToCategoriesSection(report) + NEW_LINE + NEW_LINE : "") + // audits section
|
|
1165
1176
|
reportToAuditsSection(report) + NEW_LINE + NEW_LINE + // about section
|
|
1166
|
-
reportToAboutSection(report
|
|
1177
|
+
reportToAboutSection(report) + NEW_LINE + NEW_LINE + // footer section
|
|
1167
1178
|
`${FOOTER_PREFIX} ${link2(README_LINK, "Code PushUp")}`
|
|
1168
1179
|
);
|
|
1169
1180
|
}
|
|
@@ -1287,10 +1298,10 @@ function reportToDetailsSection(audit) {
|
|
|
1287
1298
|
const detailsTable = `<h4>Issues</h4>${tableHtml(detailsTableData)}`;
|
|
1288
1299
|
return details(detailsTitle, detailsTable);
|
|
1289
1300
|
}
|
|
1290
|
-
function reportToAboutSection(report
|
|
1301
|
+
function reportToAboutSection(report) {
|
|
1291
1302
|
const date = formatDate(/* @__PURE__ */ new Date());
|
|
1292
|
-
const { duration, version: version2, plugins, categories } = report;
|
|
1293
|
-
const commitInfo =
|
|
1303
|
+
const { duration, version: version2, commit, plugins, categories } = report;
|
|
1304
|
+
const commitInfo = commit ? `${commit.message} (${commit.hash.slice(0, 7)})` : "N/A";
|
|
1294
1305
|
const reportMetaTable = [
|
|
1295
1306
|
reportMetaTableHeaders,
|
|
1296
1307
|
[
|
|
@@ -1575,7 +1586,7 @@ var verboseUtils = (verbose = false) => ({
|
|
|
1575
1586
|
|
|
1576
1587
|
// packages/core/package.json
|
|
1577
1588
|
var name = "@code-pushup/core";
|
|
1578
|
-
var version = "0.
|
|
1589
|
+
var version = "0.26.0";
|
|
1579
1590
|
|
|
1580
1591
|
// packages/core/src/lib/implementation/execute-plugin.ts
|
|
1581
1592
|
import chalk5 from "chalk";
|
|
@@ -1718,8 +1729,10 @@ async function collect(options2) {
|
|
|
1718
1729
|
const { plugins, categories } = options2;
|
|
1719
1730
|
const date = (/* @__PURE__ */ new Date()).toISOString();
|
|
1720
1731
|
const start = performance.now();
|
|
1732
|
+
const commit = await getLatestCommit();
|
|
1721
1733
|
const pluginOutputs = await executePlugins(plugins, options2);
|
|
1722
1734
|
return {
|
|
1735
|
+
commit,
|
|
1723
1736
|
packageName: name,
|
|
1724
1737
|
version,
|
|
1725
1738
|
date,
|
|
@@ -1746,24 +1759,20 @@ async function persistReport(report, options2) {
|
|
|
1746
1759
|
const { outputDir, filename, format } = options2;
|
|
1747
1760
|
const sortedScoredReport = sortReport(scoreReport(report));
|
|
1748
1761
|
console.info(generateStdoutSummary(sortedScoredReport));
|
|
1749
|
-
const results =
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
};
|
|
1764
|
-
}
|
|
1765
|
-
})
|
|
1766
|
-
);
|
|
1762
|
+
const results = format.map((reportType) => {
|
|
1763
|
+
switch (reportType) {
|
|
1764
|
+
case "json":
|
|
1765
|
+
return {
|
|
1766
|
+
format: "json",
|
|
1767
|
+
content: JSON.stringify(report, null, 2)
|
|
1768
|
+
};
|
|
1769
|
+
case "md":
|
|
1770
|
+
return {
|
|
1771
|
+
format: "md",
|
|
1772
|
+
content: generateMdReport(sortedScoredReport)
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
});
|
|
1767
1776
|
if (!await directoryExists(outputDir)) {
|
|
1768
1777
|
try {
|
|
1769
1778
|
await mkdir2(outputDir, { recursive: true });
|
|
@@ -1960,14 +1969,13 @@ async function upload(options2, uploadFn = uploadToPortal) {
|
|
|
1960
1969
|
...options2.persist,
|
|
1961
1970
|
format: "json"
|
|
1962
1971
|
});
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
throw new Error("no commit data available");
|
|
1972
|
+
if (!report.commit) {
|
|
1973
|
+
throw new Error("Commit must be linked in order to upload report");
|
|
1966
1974
|
}
|
|
1967
1975
|
const data = {
|
|
1968
1976
|
organization,
|
|
1969
1977
|
project,
|
|
1970
|
-
commit:
|
|
1978
|
+
commit: report.commit.hash,
|
|
1971
1979
|
...reportToGQL(report)
|
|
1972
1980
|
};
|
|
1973
1981
|
return uploadFn({ apiKey, server, data, timeout });
|
|
@@ -2088,10 +2096,7 @@ function yargsAutorunCommandObject() {
|
|
|
2088
2096
|
}
|
|
2089
2097
|
if (options2.upload) {
|
|
2090
2098
|
const { url } = await upload(options2);
|
|
2091
|
-
|
|
2092
|
-
if (validateCommitData(commitData, { throwError: true })) {
|
|
2093
|
-
uploadSuccessfulLog(url);
|
|
2094
|
-
}
|
|
2099
|
+
uploadSuccessfulLog(url);
|
|
2095
2100
|
} else {
|
|
2096
2101
|
ui().logger.warning("Upload skipped because configuration is not set.");
|
|
2097
2102
|
renderIntegratePortalHint();
|
|
@@ -2177,10 +2182,7 @@ function yargsUploadCommandObject() {
|
|
|
2177
2182
|
throw new Error("Upload configuration not set");
|
|
2178
2183
|
}
|
|
2179
2184
|
const { url } = await upload(options2);
|
|
2180
|
-
|
|
2181
|
-
if (validateCommitData(commitData, { throwError: true })) {
|
|
2182
|
-
uploadSuccessfulLog(url);
|
|
2183
|
-
}
|
|
2185
|
+
uploadSuccessfulLog(url);
|
|
2184
2186
|
}
|
|
2185
2187
|
};
|
|
2186
2188
|
}
|