Skip to content

Commit 9bd072a

Browse files
bugfix for katacoda runner
1 parent 643c598 commit 9bd072a

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

assertions/noException.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RunResult } from "../engine/run_result";
33
export class NoException {
44
public static run(result: RunResult): void {
55
if(result.exceptions.length > 0) {
6-
throw new Error("Unexpected exception.");
6+
throw new Error("Unexpected exception: " + result.exceptions.join());
77
}
88
}
99
}

runners/katacoda/index.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DirUtils } from "./dirUtils";
99
import * as path from 'path';
1010
import * as ejs from 'ejs';
1111
import * as fs from 'fs';
12+
import { Assertions } from "../../assertions";
1213

1314
export class Katacoda extends Runner {
1415

@@ -24,6 +25,7 @@ export class Katacoda extends Runner {
2425
private terminalCounter: number = 1;
2526
private showVsCodeIde: boolean = false;
2627
private terminals: KatacodaTerminals[] = [{function: "default", terminalId: 1}];
28+
private runResult: RunResult = new RunResult();
2729

2830
init(playbook: Playbook): void {
2931
// create directory for katacoda tutorials if not exist
@@ -146,7 +148,7 @@ export class Katacoda extends Runner {
146148
: path.join('/root', "workspaces").replace(/\\/g, "/");
147149

148150
let user = this.getVariable('user') ? this.getVariable('user') : 'devonfw-tutorials';
149-
this.renderTemplate(path.join("scripts", "restoreWorkspace.sh"), path.join(this.setupDir, "restoreWorkspace.sh"), {user: user, branch: this.getVariable("branch"), workspace: workspacesName, workspaceDir: workspacesDir, USE_DEVON_COMMAND: !!this.getVariable(this.USE_DEVON_COMMAND)});
151+
this.renderTemplate(path.join("scripts", "restoreWorkspace.sh"), path.join(this.setupDir, "restoreWorkspace.sh"), {user: user, branch: this.getVariable("branch"), workspace: workspacesName, workspaceDir: workspacesDir, useDevonCommand: !!this.getVariable(this.USE_DEVON_COMMAND)});
150152

151153
this.setupScripts.push({
152154
"name": "Restore Workspace",
@@ -254,7 +256,7 @@ export class Katacoda extends Runner {
254256

255257
this.pushStep(runCommand, "Build the Java project", "step" + runCommand.stepIndex + ".md");
256258

257-
this.renderTemplate("buildJava.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, skipTest: skipTest, USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND)});
259+
this.renderTemplate("buildJava.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, skipTest: skipTest, useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND)});
258260
return null;
259261

260262
}
@@ -265,7 +267,7 @@ export class Katacoda extends Runner {
265267

266268
this.pushStep(runCommand, "Build the Angular project", "step" + runCommand.stepIndex + ".md");
267269

268-
this.renderTemplate("buildNg.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, outputDir: runCommand.command.parameters[1], USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND) });
270+
this.renderTemplate("buildNg.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, outputDir: runCommand.command.parameters[1], useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND) });
269271

270272
return null;
271273
}
@@ -291,7 +293,7 @@ export class Katacoda extends Runner {
291293
let cdCommand = this.changeCurrentDir(serverDir, terminal.terminalId, terminal.isRunning);
292294
this.pushStep(runCommand, "Start the Java server", "step" + runCommand.stepIndex + ".md");
293295

294-
this.renderTemplate("runServerJava.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND)});
296+
this.renderTemplate("runServerJava.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND)});
295297
return null;
296298
}
297299

@@ -306,7 +308,7 @@ export class Katacoda extends Runner {
306308

307309
this.pushStep(runCommand, "Install " + packageTitle, "step" + runCommand.stepIndex + ".md")
308310

309-
this.renderTemplate("npmInstall.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND), npmCommand: npmCommand});
311+
this.renderTemplate("npmInstall.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND), npmCommand: npmCommand});
310312
return null;
311313
}
312314

@@ -319,7 +321,7 @@ export class Katacoda extends Runner {
319321

320322
fs.appendFileSync(path.join(this.getRunnerDirectory(),"templates","scripts", "intro_background.sh"), "\necho \'export NODE_OPTIONS=\"--max-old-space-size=16384\"\' >> /root/.profile\n");
321323

322-
this.renderTemplate("runClientNg.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: runCommand.command.parameters[1].port, USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND)});
324+
this.renderTemplate("runClientNg.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, terminalId: terminal.terminalId, interrupt: terminal.isRunning, port: runCommand.command.parameters[1].port, useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND)});
323325
return null;
324326
}
325327

@@ -397,7 +399,7 @@ export class Katacoda extends Runner {
397399

398400
this.pushStep(runCommand, "Create Angular project", "step" + runCommand.stepIndex + ".md");
399401

400-
this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], params: params, USE_DEVON_COMMAND: this.getVariable(this.USE_DEVON_COMMAND) });
402+
this.renderTemplate("createDevon4ngProject.md", this.outputPathTutorial + "step" + runCommand.stepIndex + ".md", { text: runCommand.text, textAfter: runCommand.textAfter, cdCommand: cdCommand, projectName: runCommand.command.parameters[0], params: params, useDevonCommand: this.getVariable(this.USE_DEVON_COMMAND) });
401403
return null;
402404
}
403405

@@ -463,9 +465,13 @@ export class Katacoda extends Runner {
463465
}
464466

465467
private renderTemplate(name: string, targetPath: string, variables) {
466-
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8');
467-
let result = ejs.render(template, variables);
468-
fs.writeFileSync(targetPath, result, {flag: "a"});
468+
try {
469+
let template = fs.readFileSync(path.join(this.getRunnerDirectory(),"templates", name), 'utf8');
470+
let result = ejs.render(template, variables);
471+
fs.writeFileSync(targetPath, result, {flag: "a"});
472+
} catch(e) {
473+
this.runResult.exceptions.push(e);
474+
}
469475
}
470476

471477
private writeSetupFile(setupFile: string) {
@@ -535,5 +541,9 @@ export class Katacoda extends Runner {
535541
}
536542
}
537543

544+
async assert(runCommand: RunCommand, runResult: RunResult): Promise<void> {
545+
new Assertions().noException(this.runResult);
546+
}
547+
538548
}
539549

0 commit comments

Comments
 (0)