diff --git a/documentation/Functions.md b/documentation/Functions.md index 201641b1..b2ae06d5 100644 --- a/documentation/Functions.md +++ b/documentation/Functions.md @@ -44,9 +44,7 @@ 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,14 +80,30 @@ 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 +**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) @@ -97,7 +111,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/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 bd7c1e73..95fd787d 100644 --- a/runners/console/index.ts +++ b/runners/console/index.ts @@ -102,19 +102,17 @@ 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 - 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')){ @@ -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 dd66b6ee..78438c8f 100644 --- a/runners/katacoda/index.ts +++ b/runners/katacoda/index.ts @@ -136,6 +136,31 @@ 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, "/"); + + 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", + "script": "restoreWorkspace.sh" + }) + + if(!this.getVariable(this.useDevonCommand)) + this.setVariable(this.workspaceDirectory, path.join('/root', "workspaces")) + + 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..62ed92a5 --- /dev/null +++ b/runners/katacoda/templates/scripts/restoreWorkspace.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +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; %> || true +cd ~/.