From a04414f19daadae82bdbfb9d96450c48ac5f33ec Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:47:50 +0200 Subject: [PATCH 1/9] katacoda/restoreWorkspace --- runners/katacoda/index.ts | 24 +++++++++++++++++++ .../templates/scripts/restoreWorkspace.sh | 22 +++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 runners/katacoda/templates/scripts/restoreWorkspace.sh diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index f5f823a4..aa2bdc66 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -130,6 +130,30 @@ export class Katacoda extends Runner { return null; } + runRestoreWorkspace(runCommand: RunCommand): RunResult { + + let workspacesName = "workspace-" + ((runCommand.command.parameters.length > 0 && runCommand.command.parameters[0].workspace) + ? runCommand.command.parameters[0].workspace + : this.playbookName.replace("/", "").replace(" ","-")); + + let workspacesDir = this.getVariable(this.useDevonCommand) + ? (path.join('/root', "devonfw", "workspaces")).replace(/\\/g, "/") + : (path.join('/root', "workspaces")).replace(/\\/g, "/"); + + console.log(workspacesDir) + + this.renderTemplate(path.join("scripts", "restoreWorkspace.sh"), path.join(this.setupDir, "restoreWorkspace.sh"), {user: this.getVariable("user"), branch: this.getVariable("branch"), workspace: workspacesName, workspaceDir: workspacesDir, useDevonCommand: !!this.getVariable(this.useDevonCommand)}) + + this.setupScripts.push({ + "name": "Restore Workspace", + "script": "restoreWorkspace.sh" + }) + + this.getStepsCount(runCommand); + + return null; + } + runInstallCobiGen(runCommand: RunCommand): RunResult { this.pushStep(runCommand, "Install CobiGen", "step" + this.getStepsCount(runCommand) + ".md"); diff --git a/runners/katacoda/templates/scripts/restoreWorkspace.sh b/runners/katacoda/templates/scripts/restoreWorkspace.sh new file mode 100644 index 00000000..da4853ac --- /dev/null +++ b/runners/katacoda/templates/scripts/restoreWorkspace.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +echo "<%= user; %> <%= branch; %>" +echo "<%= workspaceDir; %> <%= workspace; %>" +branch = "<%= branch; %>" + +if <%= useDevonCommand; %>; then + rm -r <%= workspaceDir; %> +fi + +if ! git clone https://github.com/<%= user; %>/<%= workspace; %>.git <%= workspaceDir; %>; then + git clone https://github.com/devonfw-tutorials/<%= workspace; %>.git <%= workspaceDir; %> +fi + +cd <%= workspaceDir; %> +git checkout <%= branch; %> +cd ~/. + + +if ! <%= useDevonCommand; %>; then + cp -r ./workspaces/* /root && rm -R workspaces +fi From dc8141da09e1a5dcf14adb8b2e5fb174eaf61656 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:48:32 +0200 Subject: [PATCH 2/9] removed console.log --- runners/katacoda/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index aa2bdc66..c2d98986 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -140,8 +140,6 @@ export class Katacoda extends Runner { ? (path.join('/root', "devonfw", "workspaces")).replace(/\\/g, "/") : (path.join('/root', "workspaces")).replace(/\\/g, "/"); - console.log(workspacesDir) - this.renderTemplate(path.join("scripts", "restoreWorkspace.sh"), path.join(this.setupDir, "restoreWorkspace.sh"), {user: this.getVariable("user"), branch: this.getVariable("branch"), workspace: workspacesName, workspaceDir: workspacesDir, useDevonCommand: !!this.getVariable(this.useDevonCommand)}) this.setupScripts.push({ From 86cfe9b02ee438681bc82c942b4389680b8404df Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:50:03 +0200 Subject: [PATCH 3/9] removed echo --- runners/katacoda/templates/scripts/restoreWorkspace.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/runners/katacoda/templates/scripts/restoreWorkspace.sh b/runners/katacoda/templates/scripts/restoreWorkspace.sh index da4853ac..79848438 100644 --- a/runners/katacoda/templates/scripts/restoreWorkspace.sh +++ b/runners/katacoda/templates/scripts/restoreWorkspace.sh @@ -1,9 +1,5 @@ #!/bin/bash -echo "<%= user; %> <%= branch; %>" -echo "<%= workspaceDir; %> <%= workspace; %>" -branch = "<%= branch; %>" - if <%= useDevonCommand; %>; then rm -r <%= workspaceDir; %> fi From 83afd2b123ed43468ff9220754000e2595fd5541 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:50:53 +0200 Subject: [PATCH 4/9] removed whitespace --- runners/katacoda/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index c2d98986..a8d3ed37 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -131,7 +131,6 @@ export class Katacoda extends Runner { } runRestoreWorkspace(runCommand: RunCommand): RunResult { - let workspacesName = "workspace-" + ((runCommand.command.parameters.length > 0 && runCommand.command.parameters[0].workspace) ? runCommand.command.parameters[0].workspace : this.playbookName.replace("/", "").replace(" ","-")); From c0058ed12079da3b947273e2a661dbefc8591b32 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Fri, 9 Apr 2021 14:50:53 +0200 Subject: [PATCH 5/9] fixed bug restoreWorkspace --- runners/katacoda/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index c2d98986..a8d3ed37 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -131,7 +131,6 @@ export class Katacoda extends Runner { } runRestoreWorkspace(runCommand: RunCommand): RunResult { - let workspacesName = "workspace-" + ((runCommand.command.parameters.length > 0 && runCommand.command.parameters[0].workspace) ? runCommand.command.parameters[0].workspace : this.playbookName.replace("/", "").replace(" ","-")); From be1fc793c9316c925594e3453063fec0393308da Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 12 Apr 2021 14:43:00 +0200 Subject: [PATCH 6/9] bug fix --- documentation/Functions.md | 17 +++++++++-------- runners/console/index.ts | 12 ++++++------ runners/katacoda/index.ts | 3 ++- .../templates/scripts/restoreWorkspace.sh | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index c88f2f63..64d549bc 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -44,9 +44,8 @@ In the Katacoda environment the installation of the devonfw IDE is executed in a ### restoreWorkspace #### parameter -1. (Optional): - * Name of the workspace repository {"workspace": string} (Default is the playbook-name) - * local workspace {"local": boolean} (Default is false) +1. (Optional) Name of the workspace repository {"workspace": string} (Default is the playbook-name) + #### arguments **User**(Optional) @@ -82,10 +81,12 @@ will run "git clone https://github.com/[GitHub-name]/[playbook-name]" and checko **example** "workspace-devon4ng" -> {"workspace" : "devon4ng"} -**local** - You can use a local repository as workspace in your tutorial. - Clone the forked repository next to the tutorial-compiler folder and set the "local"-parameter to true {"local": true} - +**local repository** + You can use a local repository as workspace in the console environment for your tutorial. + Clone the forked repository next to the tutorial-compiler folder. Before cloning the GitHub repository, the console runner will always check, if there is a 'workspace-[name]'-folder next to the tutorial compiler first, and will use it instead. + + Keep in mind, that it is a feature only implemented in the console environment. Other runners will clone the environment from GitHub. + |--tutorial-compiler |--tutorials |--workspace-devon4ng @@ -97,7 +98,7 @@ will run "git clone https://github.com/[GitHub-name]/[playbook-name]" and checko changeWorkspace("devonfw/workspaces/project") will set the workspace directory to "[working directory]/devonfw/workspaces/project" -Learn more about the workspace directory and working direktory on [Structure](https://github.com/devonfw-forge/tutorial-compiler/wiki/Structure) +Learn more about the workspace directory and working directory on [Structure](https://github.com/devonfw-forge/tutorial-compiler/wiki/Structure) diff --git a/runners/console/index.ts b/runners/console/index.ts index 94e207ae..af93f751 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -104,17 +104,17 @@ export class Console extends Runner { ? path.join(this.getWorkingDirectory(), "devonfw", "workspaces") : this.getVariable(this.workspaceDirectory); + //removes all the directories and files inside workspace if(this.getVariable(this.useDevonCommand)) - this.createFolder(workspacesDir, true) + this.createFolder(workspacesDir, true); //copies a local repository into the workspace - if(runCommand.command.parameters.length > 0 && runCommand.command.parameters[0].local){ - let forkedWorkspacesDir = path.join(this.getWorkingDirectory(),'..','..','..', workspacesName); - if(fs.existsSync(forkedWorkspacesDir)) - fs.copySync(path.join(forkedWorkspacesDir, '/.'), workspacesDir); + let forkedWorkspacesDir = path.join(this.getWorkingDirectory(),'..','..','..', workspacesName); + if(fs.existsSync(forkedWorkspacesDir)){ + fs.copySync(path.join(forkedWorkspacesDir, '/.'), workspacesDir); } - + //uses GitHub-username and branch if user and branch are specified else if(this.getVariable('user') || this.getVariable('branch')){ diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index a8d3ed37..587a09b1 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -139,7 +139,8 @@ export class Katacoda extends Runner { ? (path.join('/root', "devonfw", "workspaces")).replace(/\\/g, "/") : (path.join('/root', "workspaces")).replace(/\\/g, "/"); - this.renderTemplate(path.join("scripts", "restoreWorkspace.sh"), path.join(this.setupDir, "restoreWorkspace.sh"), {user: this.getVariable("user"), branch: this.getVariable("branch"), workspace: workspacesName, workspaceDir: workspacesDir, useDevonCommand: !!this.getVariable(this.useDevonCommand)}) + let user = this.getVariable('user') ? this.getVariable('user') : 'devonfw-tutorials'; + 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.useDevonCommand)}) this.setupScripts.push({ "name": "Restore Workspace", diff --git a/runners/katacoda/templates/scripts/restoreWorkspace.sh b/runners/katacoda/templates/scripts/restoreWorkspace.sh index 79848438..2f2e2daf 100644 --- a/runners/katacoda/templates/scripts/restoreWorkspace.sh +++ b/runners/katacoda/templates/scripts/restoreWorkspace.sh @@ -9,7 +9,7 @@ if ! git clone https://github.com/<%= user; %>/<%= workspace; %>.git <%= workspa fi cd <%= workspaceDir; %> -git checkout <%= branch; %> +git checkout <%= branch; %> || true cd ~/. From a5c4e0a13df19ea2e3f3f16b8a23f7f961769760 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Mon, 12 Apr 2021 14:51:58 +0200 Subject: [PATCH 7/9] removed brackets --- runners/katacoda/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 587a09b1..47f01a07 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -136,8 +136,8 @@ export class Katacoda extends Runner { : this.playbookName.replace("/", "").replace(" ","-")); let workspacesDir = this.getVariable(this.useDevonCommand) - ? (path.join('/root', "devonfw", "workspaces")).replace(/\\/g, "/") - : (path.join('/root', "workspaces")).replace(/\\/g, "/"); + ? path.join('/root', "devonfw", "workspaces").replace(/\\/g, "/") + : path.join('/root', "workspaces").replace(/\\/g, "/"); let user = this.getVariable('user') ? this.getVariable('user') : 'devonfw-tutorials'; 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.useDevonCommand)}) From 6879ab817bba447e0f0f91920f138babac75377b Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Tue, 13 Apr 2021 12:54:50 +0200 Subject: [PATCH 8/9] added indentations --- runners/katacoda/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index 47f01a07..afee8a69 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -132,12 +132,12 @@ export class Katacoda extends Runner { runRestoreWorkspace(runCommand: RunCommand): RunResult { let workspacesName = "workspace-" + ((runCommand.command.parameters.length > 0 && runCommand.command.parameters[0].workspace) - ? runCommand.command.parameters[0].workspace - : this.playbookName.replace("/", "").replace(" ","-")); + ? runCommand.command.parameters[0].workspace + : this.playbookName.replace("/", "").replace(" ","-")); let workspacesDir = this.getVariable(this.useDevonCommand) - ? path.join('/root', "devonfw", "workspaces").replace(/\\/g, "/") - : path.join('/root', "workspaces").replace(/\\/g, "/"); + ? path.join('/root', "devonfw", "workspaces").replace(/\\/g, "/") + : path.join('/root', "workspaces").replace(/\\/g, "/"); let user = this.getVariable('user') ? this.getVariable('user') : 'devonfw-tutorials'; 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.useDevonCommand)}) From ba55aa8a08acd7d46d25d9d0830d9258bbd44dd3 Mon Sep 17 00:00:00 2001 From: denise-khuu <74537227+denise-khuu@users.noreply.github.com> Date: Tue, 13 Apr 2021 14:54:01 +0200 Subject: [PATCH 9/9] changed workspaceDirectory --- documentation/Functions.md | 15 +++++++++++++- documentation/Structure.md | 20 +++++++++++++++++++ runners/console/index.ts | 12 ++++++----- runners/katacoda/index.ts | 3 +++ .../templates/scripts/restoreWorkspace.sh | 5 ----- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/documentation/Functions.md b/documentation/Functions.md index 64d549bc..16ba39a2 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -46,7 +46,6 @@ In the Katacoda environment the installation of the devonfw IDE is executed in a #### parameter 1. (Optional) Name of the workspace repository {"workspace": string} (Default is the playbook-name) - #### arguments **User**(Optional) flag: --user @@ -91,6 +90,20 @@ will run "git clone https://github.com/[GitHub-name]/[playbook-name]" and checko |--tutorials |--workspace-devon4ng +**workspace directory** + + If you call 'restoreDevonfwIde' or 'installDevonfwIde' before the 'restoreWorkspace'-function the workspace directory remains: + + `'/root/workspaces/main'` + + If you don't call them, the workspace is changed to: + + `'/root/workspaces'` + + +Learn more about the workspace directory and working directory on [Structure](https://github.com/devonfw-forge/tutorial-compiler/wiki/Structure) + + ### changeWorkspace #### parameter 1. path to a new workspace (relative to working directory) diff --git a/documentation/Structure.md b/documentation/Structure.md index f8588d8e..a8f90f06 100644 --- a/documentation/Structure.md +++ b/documentation/Structure.md @@ -96,3 +96,23 @@ will change the workspace to the "[working-directory]/devonfw/workspaces/main". The phrase "relative to workspace" means in this case relative to "./main" You can set a new workspace with the function [changeWorkspace](https://github.com/devonfw-forge/tutorial-compiler/wiki/Functions). +### Workspace with restoreWorkspace + +The function [restoreWorkspace](https://github.com/devonfw-forge/tutorial-compiler/wiki/Functions) will change the workspace. + +#### WIthout devonfw IDE + + |--[working-directory] + |--workspaces + +The phrase "relative to workspace" means in this case relative to "./workspaces" + + +#### With devonfw IDE + + |--[working-directory] + |--devonfw + |--workspaces + |--main + +The phrase "relative to workspace" means in this case relative to "./main" \ No newline at end of file diff --git a/runners/console/index.ts b/runners/console/index.ts index af93f751..0020844f 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -102,12 +102,10 @@ export class Console extends Runner { let workspacesDir = this.getVariable(this.useDevonCommand) ? path.join(this.getWorkingDirectory(), "devonfw", "workspaces") - : this.getVariable(this.workspaceDirectory); - + : path.join(this.getWorkingDirectory(), 'workspaces'); //removes all the directories and files inside workspace - if(this.getVariable(this.useDevonCommand)) - this.createFolder(workspacesDir, true); + this.createFolder(workspacesDir, true); //copies a local repository into the workspace let forkedWorkspacesDir = path.join(this.getWorkingDirectory(),'..','..','..', workspacesName); @@ -137,7 +135,11 @@ export class Console extends Runner { else{ ConsoleUtils.executeCommandSync("git clone https://github.com/devonfw-tutorials/" + workspacesName + ".git .", workspacesDir, result, this.env); } - + + if(!this.getVariable(this.useDevonCommand)){ + this.setVariable(this.workspaceDirectory, path.join(this.getWorkingDirectory(), 'workspaces')); + } + return result; } diff --git a/runners/katacoda/index.ts b/runners/katacoda/index.ts index afee8a69..c53165b0 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -147,6 +147,9 @@ export class Katacoda extends Runner { "script": "restoreWorkspace.sh" }) + if(!this.getVariable(this.useDevonCommand)) + this.setVariable(this.workspaceDirectory, path.join('/root', "workspaces")) + this.getStepsCount(runCommand); return null; diff --git a/runners/katacoda/templates/scripts/restoreWorkspace.sh b/runners/katacoda/templates/scripts/restoreWorkspace.sh index 2f2e2daf..62ed92a5 100644 --- a/runners/katacoda/templates/scripts/restoreWorkspace.sh +++ b/runners/katacoda/templates/scripts/restoreWorkspace.sh @@ -11,8 +11,3 @@ fi cd <%= workspaceDir; %> git checkout <%= branch; %> || true cd ~/. - - -if ! <%= useDevonCommand; %>; then - cp -r ./workspaces/* /root && rm -R workspaces -fi