Skip to content

Commit 5b27486

Browse files
committed
Merge remote-tracking branch 'upstream/main' into feature/adaptCobiGenTemplates
2 parents 0465af0 + f76f7e9 commit 5b27486

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

buildRun.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Copy-Item -Force -Recurse -Path $PSScriptRoot\playbooks\ -Destination $PSScriptR
44
Copy-Item -Force -Recurse -Path $PSScriptRoot\environments\ -Destination $PSScriptRoot\build
55
Copy-Item -Force -Recurse -Path $PSScriptRoot\runners\ -Destination $PSScriptRoot\build
66
npm test
7-
node $PSScriptRoot\build\engine\run.js
7+
node $PSScriptRoot\build\engine\run.js --skipCommands.console dockerCompose

documentation/Functions.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The following functions are already implemented:
1313
* runServerJava
1414
* buildNg
1515
* npmInstall
16+
* dockerCompose
1617
* downloadFile
1718
* nextKatacodaStep
1819
* adaptCobiGenTemplates
@@ -163,6 +164,20 @@ npmInstall("my-thai-star/angular")
163164

164165
***
165166

167+
### dockerCompose
168+
#### parameter
169+
1. Path to the directory where the docker-compose.yml file is located, relative to workspace.
170+
2. Assertion information. Only needed for the console runner to check if the server was started properly.
171+
#### example
172+
dockerCompose("my-thai-star", { "startupTime": 600, "port": 8081, "path": "" })
173+
174+
##### Assertion information
175+
startupTime = Time in seconds to wait before checking if the server is running
176+
port: Port on which the server is running
177+
path: The URL path on which is checked if the server is running
178+
179+
***
180+
166181
### downloadFile
167182
#### parameter
168183
1. URL of the file to be downloaded.

engine/engine.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,33 @@ export class Engine {
2424
(await this.getRunner(this.environment.runners[runnerIndex])).init(this.playbook);
2525
}
2626

27-
for (let stepIndex in this.playbook.steps) {
27+
mainloop: for (let stepIndex in this.playbook.steps) {
2828
for (let lineIndex in this.playbook.steps[stepIndex].lines) {
29+
let foundRunnerToExecuteCommand = false;
2930
for (let runnerIndex in this.environment.runners) {
3031
let runner = await this.getRunner(this.environment.runners[runnerIndex]);
3132
if (runner.supports(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
3233
var result = new RunResult();
34+
if(runner.commandIsSkippable(this.playbook.steps[stepIndex].lines[lineIndex].name)) {
35+
console.log("Command " + this.playbook.steps[stepIndex].lines[lineIndex].name + " will be skipped.");
36+
continue;
37+
}
3338
try {
3439
result = runner.run(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex]);
3540
}
3641
catch (e) {
3742
result.exceptions.push(e);
3843
}
44+
3945
await runner.assert(this.playbook.steps[stepIndex], this.playbook.steps[stepIndex].lines[lineIndex], result);
46+
47+
foundRunnerToExecuteCommand = true;
4048
break;
4149
}
4250
}
51+
if(!foundRunnerToExecuteCommand) {
52+
break mainloop;
53+
}
4354
}
4455
}
4556

engine/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class Run {
7777
traverseArgs(parentName, obj) {
7878

7979
for (let index in obj) {
80-
if (isObject(obj[index])) {
80+
if (obj[index] instanceof Object) {
81+
this.args.set(parentName + index, obj[index]);
8182
this.traverseArgs(parentName + index + ".", obj[index]);
8283
}
8384
else {

engine/runner.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ export abstract class Runner {
110110
fs.mkdirSync(path, { recursive: true });
111111
return path;
112112
}
113+
114+
commandIsSkippable(command: String): Boolean {
115+
let returnVal = false;
116+
let runner = this.getVariable("skipCommands." + this.getRunnerName());
117+
if(runner) {
118+
if((runner instanceof Array && runner.indexOf(command) != -1) || runner == command) {
119+
returnVal = true;
120+
}
121+
}
122+
return returnVal;
123+
}
113124
}

runners/console/index.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class Console extends Runner {
3636
}
3737
this.setVariable(this.workspaceDirectory, path.join(this.getWorkingDirectory()));
3838
this.env = process.env;
39+
3940
}
4041

4142
destroy(playbook: Playbook): void {
@@ -204,6 +205,27 @@ export class Console extends Runner {
204205
return result;
205206
}
206207

208+
209+
runDockerCompose(step: Step, command: Command): RunResult {
210+
let result = new RunResult();
211+
result.returnCode = 0;
212+
213+
let filepath = path.join(this.getVariable(this.workspaceDirectory), command.parameters[0]);
214+
215+
let process = this.executeCommandAsync("docker-compose up", filepath, result);
216+
process.on('close', (code) => {
217+
if (code !== 0) {
218+
result.returnCode = code;
219+
}
220+
});
221+
if(process.pid && command.parameters.length == 2) {
222+
this.asyncProcesses.push({ pid: process.pid, name: "dockerCompose", port: command.parameters[1].port });
223+
}
224+
225+
return result;
226+
227+
}
228+
207229
runRunServerJava(step: Step, command: Command): RunResult {
208230
let result = new RunResult();
209231
result.returnCode = 0;
@@ -231,6 +253,7 @@ export class Console extends Runner {
231253
this.executeCommandSync("git clone " + command.parameters[1], directorypath, result);
232254

233255
return result;
256+
234257
}
235258

236259
runNpmInstall(step: Step, command: Command): RunResult {
@@ -434,7 +457,37 @@ export class Console extends Runner {
434457
throw error;
435458
}
436459
}
437-
460+
461+
async assertDockerCompose(step: Step, command: Command, result: RunResult) {
462+
try {
463+
let assert = new Assertions()
464+
.noErrorCode(result)
465+
.noException(result);
466+
467+
if(command.parameters.length > 1) {
468+
if(!command.parameters[1].startupTime) {
469+
console.warn("No startup time for command dockerCompose has been set")
470+
}
471+
let startupTimeInSeconds = command.parameters[1].startupTime ? command.parameters[1].startupTime : 0;
472+
await this.sleep(command.parameters[1].startupTime);
473+
474+
if(!command.parameters[1].port) {
475+
this.killAsyncProcesses();
476+
throw new Error("Missing arguments for command dockerCompose. You have to specify a port and a path for the server. For further information read the function documentation.");
477+
} else {
478+
let isReachable = await assert.serverIsReachable(command.parameters[1].port, command.parameters[1].path);
479+
if(!isReachable) {
480+
this.killAsyncProcesses();
481+
throw new Error("The server has not become reachable in " + startupTimeInSeconds + " seconds: " + "http://localhost:" + command.parameters[1].port + "/" + command.parameters[1].path);
482+
}
483+
}
484+
}
485+
} catch(error) {
486+
this.cleanUp();
487+
throw error;
488+
}
489+
}
490+
438491
async assertRunServerJava(step: Step, command: Command, result: RunResult) {
439492
try {
440493
let assert = new Assertions()
@@ -683,5 +736,6 @@ export class Console extends Runner {
683736
}
684737
}
685738

739+
686740

687-
}
741+
}

0 commit comments

Comments
 (0)