|
| 1 | +const executeStages = require("./executeStages"); |
| 2 | +const { EXECUTION_RESULTS } = require('../config'); |
| 3 | + |
| 4 | +function sendProcessMessage(msg) { |
| 5 | + // process.send not defined outside of child processes |
| 6 | + // this is used for the Builder CLI |
| 7 | + if(process.send) { |
| 8 | + process.send(msg); |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +function executeGroups(groups) { |
| 13 | + const stageContainers = groups.reduce((arr, group) => { |
| 14 | + const containers = group.stageContainers.map((x) => ({ ...x, stageContainerGroup: group })) |
| 15 | + return arr.concat(containers); |
| 16 | + }, []); |
| 17 | + |
| 18 | + const promises = new Array(stageContainers.length).fill(0).map(async (_, j) => { |
| 19 | + const stageContainer = stageContainers[j]; |
| 20 | + |
| 21 | + const { version, stages, stageContainerGroup } = stageContainer; |
| 22 | + const { title } = stageContainerGroup; |
| 23 | + |
| 24 | + console.log(`Running ${title} ${version}...`); |
| 25 | + const results = await executeStages(stages); |
| 26 | + const executedResults = results.filter(x => x !== EXECUTION_RESULTS.NONE); |
| 27 | + if(executedResults.length === 0) { |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + console.log(`${title} ${version} results:`); |
| 32 | + executedResults.forEach((result, i) => { |
| 33 | + const stage = stageContainer.stages[i]; |
| 34 | + if(result === EXECUTION_RESULTS.SUCCESS) { |
| 35 | + console.log(`✔️ ${stage.title} passed!`); |
| 36 | + sendProcessMessage({ type: "RESULT", data: { |
| 37 | + success: true, |
| 38 | + version: `${title} ${version}`, |
| 39 | + stage: stage.title |
| 40 | + }}); |
| 41 | + } |
| 42 | + else { |
| 43 | + console.log(`✘ ${stage.title} failed!`); |
| 44 | + sendProcessMessage({ type: "RESULT", data: { |
| 45 | + success: false, |
| 46 | + version: `${title} ${version}`, |
| 47 | + stage: stage.title |
| 48 | + }}); |
| 49 | + } |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + return Promise.all(promises); |
| 54 | +} |
| 55 | + |
| 56 | +module.exports = executeGroups; |
0 commit comments