Repository navigation
Expand file tree
/
Copy pathvalidate-patch-report.js
More file actions
125 lines (114 loc) · 3.36 KB
/
Copy pathvalidate-patch-report.js
File metadata and controls
125 lines (114 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
"use strict";
const {
SUCCESS_STATUSES,
optionalDriftFromReport,
} = require("../lib/patch-report.js");
const {
readPatchReport,
uniqueStrings,
validatePatchReport,
} = require("../lib/patch-validation.js");
function usage() {
return [
"Usage: validate-patch-report.js <patch-report.json> [--profile upstream-build]",
" [--require-enabled-feature FEATURE_ID] [--require-success PATCH_NAME]",
" [--require-applied PATCH_NAME]",
].join("\n");
}
function parseArgs(argv) {
let profile = "upstream-build";
const requiredEnabledFeatures = [];
const requiredAppliedPatches = [];
const requiredSuccessfulPatches = [];
const positional = [];
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (arg === "--profile") {
profile = argv[index + 1];
if (!profile) {
throw new Error(usage());
}
index += 1;
} else if (arg === "--require-enabled-feature") {
const featureId = argv[index + 1];
if (!featureId) {
throw new Error(usage());
}
requiredEnabledFeatures.push(featureId);
index += 1;
} else if (arg === "--require-success") {
const patchName = argv[index + 1];
if (!patchName) {
throw new Error(usage());
}
requiredSuccessfulPatches.push(patchName);
index += 1;
} else if (arg === "--require-applied") {
const patchName = argv[index + 1];
if (!patchName) {
throw new Error(usage());
}
requiredAppliedPatches.push(patchName);
index += 1;
} else if (arg === "--help" || arg === "-h") {
console.log(usage());
process.exit(0);
} else if (arg.startsWith("--")) {
throw new Error(`Unknown option: ${arg}\n${usage()}`);
} else {
positional.push(arg);
}
}
if (positional.length !== 1) {
throw new Error(usage());
}
return {
profile,
reportPath: positional[0],
requirements: {
requiredAppliedPatches: uniqueStrings(requiredAppliedPatches),
requiredEnabledFeatures: uniqueStrings(requiredEnabledFeatures),
requiredSuccessfulPatches: uniqueStrings(requiredSuccessfulPatches),
},
};
}
const readReport = readPatchReport;
const validateReport = validatePatchReport;
function printOptionalDrift(report) {
const drift = optionalDriftFromReport(report);
if (drift.length === 0) {
return;
}
console.warn(`Optional patch drift (${drift.length}, non-failing):`);
for (const item of drift) {
console.warn(`- ${item.name}: ${item.status}${item.reason ? ` (${item.reason})` : ""}`);
}
}
function main() {
try {
const { profile, reportPath, requirements } = parseArgs(process.argv.slice(2));
const report = readReport(reportPath);
printOptionalDrift(report);
const failures = validateReport(report, profile, requirements);
if (failures.length > 0) {
console.error(`Required patch validation failed for profile ${profile}:`);
for (const failure of failures) {
console.error(`- ${failure}`);
}
process.exit(1);
}
console.log(`Required patch validation passed for profile ${profile}.`);
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
process.exit(1);
}
}
if (require.main === module) {
main();
}
module.exports = {
SUCCESS_STATUSES,
readReport,
validateReport,
};