forked from rudderlabs/rudder-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrationBuildScript.js
70 lines (59 loc) · 1.98 KB
/
integrationBuildScript.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
/* eslint-disable no-console */
import { exec } from 'child_process';
import { configToIntNames } from './utils/config_to_integration_names';
const intgNamesArr = Object.values(configToIntNames);
const totalIntgCount = intgNamesArr.length;
let passCount = 0;
let curInt = 0;
const numCPUs = require('os').cpus().length;
let numRunning = 0;
let index = 0;
// At any given time, create only processes for
// max CPUs available
// Intentionally using 1 less CPU
const maxAtOnce = numCPUs > 1 ? numCPUs - 1 : 1;
console.log(`Total integrations to build: ${totalIntgCount}`);
console.log(`Maximum number of concurrent processes: ${maxAtOnce}`);
function buildIntegrations() {
// if there are more waiting, run them
while (numRunning < maxAtOnce && index < totalIntgCount) {
numRunning += 1;
const intgName = intgNamesArr[index];
index += 1;
let cmd = `npm run buildProdIntegrationCLI --intg=${intgName}`;
if (process.env.BUNDLE_SIZE_VISUALIZER === 'true') {
cmd = `npm run bundle-size-visual-integration-cli --intg=${intgName}`;
}
// eslint-disable-next-line no-loop-func
exec(cmd, (error, stdout, stderr) => {
curInt += 1;
console.log(
`\nCompleted building integration: ${intgName} (${curInt} out of ${totalIntgCount})`,
);
console.log(stdout);
console.log(stderr);
if (error) {
console.log(`${intgName} build failed!!!`);
console.log('ERROR: ', error);
} else {
passCount += 1;
}
numRunning -= 1;
// Trigger more builds
buildIntegrations();
});
}
if (numRunning === 0) {
// All the integrations are built
console.log(`Final Status: ${passCount !== totalIntgCount ? 'FAILURE' : 'SUCCESS'}`);
console.log(
`Summary: ${passCount} out of ${totalIntgCount} integration builds were successful`,
);
if (passCount !== totalIntgCount) {
// Force exit to indicate failure
process.exit(1);
}
}
}
// Kickoff the builds
buildIntegrations();