Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions documentation/Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -82,22 +80,38 @@ 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)
#### example
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)



Expand Down
20 changes: 20 additions & 0 deletions documentation/Structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 11 additions & 9 deletions runners/console/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')){

Expand All @@ -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;
}

Expand Down
25 changes: 25 additions & 0 deletions runners/katacoda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
13 changes: 13 additions & 0 deletions runners/katacoda/templates/scripts/restoreWorkspace.sh
Original file line number Diff line number Diff line change
@@ -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 ~/.