-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
detect-jobs-to-run.js
executable file
·73 lines (61 loc) · 1.51 KB
/
detect-jobs-to-run.js
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
#!/usr/bin/env node
// @ts-check
const { stdin } = process;
// From https://github.com/sindresorhus/get-stdin/blob/main/index.js
async function getStdin() {
let result = "";
if (stdin.isTTY) {
return result;
}
stdin.setEncoding("utf8");
for await (const chunk of stdin) {
result += chunk;
}
return result;
}
async function main() {
const stdinData = await getStdin();
console.log("stdin:", stdinData);
/**
* @type string[]
**/
const filesChanged = JSON.parse(stdinData);
console.log("filesChanged:", filesChanged);
const jobsToRun = [];
// If changes are located only in one of the paths below
if (
filesChanged.every((fileChanged) =>
fileChanged.startsWith("packages/cli/")
)
) {
jobsToRun.push("-cli-");
} else if (
filesChanged.every((fileChanged) =>
fileChanged.startsWith("packages/client/")
)
) {
jobsToRun.push("-client-");
jobsToRun.push("-integration-tests-");
jobsToRun.push("-cli-");
} else if (
filesChanged.every((fileChanged) =>
fileChanged.startsWith("packages/integration-tests/")
)
) {
jobsToRun.push("-integration-tests-");
} else if (
filesChanged.every((fileChanged) =>
fileChanged.startsWith("packages/migrate/")
)
) {
jobsToRun.push("-migrate-");
jobsToRun.push("-cli-");
} else {
jobsToRun.push("-all-");
}
console.log("jobsToRun:", jobsToRun);
console.log("::set-output name=jobs::" + jobsToRun.join());
}
main().then(function () {
console.log("Done");
});