-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpr-quality-command-plan.mjs
More file actions
131 lines (109 loc) · 2.86 KB
/
Copy pathpr-quality-command-plan.mjs
File metadata and controls
131 lines (109 loc) · 2.86 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
126
127
128
129
130
131
import { appendFileSync } from "node:fs";
export function createPrQualityCommandPlan({
job,
docsOnly,
runMode,
canUseRemoteCache,
}) {
if (!["format", "static", "test", "e2e"].includes(job)) {
throw new Error(`Unsupported job: ${job}`);
}
if (docsOnly || runMode === "noop") {
return {
should_run: false,
command: "",
uses_remote_cache: false,
reason: "docs-only-noop",
};
}
if (job === "format") {
return {
should_run: true,
command: "pnpm format:check",
uses_remote_cache: false,
reason: "full-format-gate",
};
}
if (job === "static") {
if (runMode === "affected") {
return {
should_run: true,
command:
"pnpm exec turbo run lint --affected && pnpm exec turbo run typecheck --affected",
uses_remote_cache: canUseRemoteCache,
reason: "affected-static-gate",
};
}
return {
should_run: true,
command: "pnpm lint && pnpm typecheck",
uses_remote_cache: canUseRemoteCache,
reason: "full-static-gate",
};
}
if (job === "test") {
if (runMode === "affected") {
return {
should_run: true,
command: "pnpm test:root && pnpm exec turbo run test --affected",
uses_remote_cache: canUseRemoteCache,
reason: "affected-test-gate",
};
}
return {
should_run: true,
command: "pnpm test",
uses_remote_cache: canUseRemoteCache,
reason: "full-test-gate",
};
}
return {
should_run: true,
command: "pnpm test:e2e",
uses_remote_cache: canUseRemoteCache,
reason: "full-e2e-terminal-gate",
};
}
function parseArgs(argv) {
const options = {};
for (let index = 0; index < argv.length; index += 1) {
const arg = argv[index];
if (!arg.startsWith("--")) {
continue;
}
const key = arg.slice(2);
const nextValue = argv[index + 1];
if (!nextValue || nextValue.startsWith("--")) {
options[key] = "true";
continue;
}
options[key] = nextValue;
index += 1;
}
return options;
}
function toBoolean(value) {
return value === "true";
}
function writeGitHubOutput(filePath, result) {
const lines = Object.entries(result).map(([key, value]) => `${key}=${value}`);
for (const line of lines) {
appendFileSync(filePath, `${line}\n`);
}
}
function main() {
const options = parseArgs(process.argv.slice(2));
const result = createPrQualityCommandPlan({
job: options.job,
docsOnly: toBoolean(options["docs-only"] ?? "false"),
runMode: options["run-mode"] ?? "full",
canUseRemoteCache: toBoolean(options["can-use-remote-cache"] ?? "false"),
});
if (options["github-output"]) {
writeGitHubOutput(options["github-output"], result);
}
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
}
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}