Skip to content

Commit 17ac944

Browse files
Merge pull request #145 from denise-khuu/feature/envSelector
feature/selectEnvironmentAndPlaybook
2 parents 2b498ee + 116e463 commit 17ac944

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
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 --skipCommands.console dockerCompose
7+
node $PSScriptRoot\build\engine\run.js --skipCommands.console dockerCompose $args

buildRun.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ cp -r playbooks build
44
cp -r environments build
55
cp -r runners build
66
npm test
7-
node build/engine/run.js
7+
node build/engine/run.js $*

documentation/Development.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To create a new command you can use in your playbooks, you have to implement a n
1111

1212
The new method must match the following syntax: 'run' + name of the command. The first letter after 'run' has to be in upper case letters.
1313
```
14-
runYourCommand(step: Step, command: Command): RunResult {
14+
runYourCommand(runCommand: RunCommand): RunResult
1515
...your code...
1616
let result = new RunResult();
1717
result.returnCode = 1;
@@ -22,7 +22,7 @@ With the RunResult object you can return a value after the function has executed
2222

2323
The assert method has to match the same naming conventions as the run method (except the 'assert' at the beginning) and is located in the same runner class. The RunResult object of the run method is passed to this method as a parameter.
2424
```
25-
async assertYourCommand(step: Step, command: Command, result: RunResult) {
25+
async assertYourCommand(runCommand: RunCommand, result: RunResult) {
2626
new Assertions()
2727
.yourFirstAssertion(result)
2828
.yourSecondAssertion(result);
@@ -55,3 +55,24 @@ public yourAssertionCode(): Assertions {
5555
```
5656
If you want to pass arguments to this method, you have to do this in the header of the 'run' method and in the call of the method.
5757

58+
## Choose the tutorial and the environment
59+
60+
### Environment
61+
flag: '-e'
62+
value: 'katacoda', 'console'
63+
64+
If you don't pass environment arguments to the file, it will run the playbooks on all environments.
65+
66+
#### example
67+
'bash localBuildRun.sh -e katacoda -e console'
68+
69+
### Playbook
70+
flag: '-p'
71+
value: foldername of the tutorial
72+
73+
If you don't pass playbook arguments to the file, it will run all playbooks, that are in the folder 'tutorials'.
74+
75+
#### example
76+
'bash localBuildRun.sh -p cobigen-cli'
77+
78+

engine/run.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ class Run {
1717
this.parseArgs();
1818
this.parsePlaybooks();
1919
this.parseEnvironments();
20-
for (let entry of Array.from(this.environments.entries())) {
20+
let entries = this.filterEnv(Array.from(this.environments.entries()))
21+
for (let entry of entries) {
2122
let key = entry[0];
2223
let value = entry[1];
23-
for (let playbookIndex in this.playbooks) {
24+
let playbookIndecies = this.filterPlaybooks(this.playbooks)
25+
for (let playbookIndex of playbookIndecies) {
2426
let engine = new Engine(key, value, this.playbooks[playbookIndex]);
2527

2628
for (let varEntry of Array.from(this.args.entries())) {
@@ -97,6 +99,30 @@ class Run {
9799
}
98100
}
99101
}
102+
103+
filterEnv(entries){
104+
if(!this.args.get('e'))
105+
return entries;
106+
107+
let filteredEntries = new Array();
108+
for(let entry of entries){
109+
if(this.args.get('e').includes(entry[0]))
110+
filteredEntries.push(entry)
111+
}
112+
return filteredEntries
113+
}
114+
115+
filterPlaybooks(playbooks){
116+
if(!this.args.get('p'))
117+
return Array.from(playbooks.keys());
118+
119+
let filteredIndecies = [];
120+
for(let playbook of playbooks){
121+
if(this.args.get('p').includes(playbook['name'].replace("/", "")))
122+
filteredIndecies.push(playbooks.indexOf(playbook))
123+
}
124+
return filteredIndecies
125+
}
100126
}
101127

102128

engine/runner.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { Command } from "./command";
21
import { RunResult } from "./run_result";
32
import { Playbook } from "./playbook";
4-
import { Step } from "./step";
53
import * as fs from 'fs';
64
import * as rimraf from 'rimraf';
75
import { RunCommand } from "./run_command";

localBuildRun.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Copy-Item -Force -Recurse -Path $PSScriptRoot\environments\ -Destination $PSScri
55
Copy-Item -Force -Recurse -Path $PSScriptRoot\runners\ -Destination $PSScriptRoot\build
66
npm test
77
if(-not $?) { throw 'tests failed' }
8-
node $PSScriptRoot\build\engine\run.js
8+
node $PSScriptRoot\build\engine\run.js $args

localBuildRun.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ if [ $? -eq 1 ]; then
88
echo 'tests failed'
99
exit 1
1010
fi
11-
node build/engine/run.js
11+
12+
node build/engine/run.js $*

0 commit comments

Comments
 (0)