Skip to content

Commit 63f2030

Browse files
Merge branch 'main' into feature/wikiRunnerCreateFile
2 parents aacd59f + be5c211 commit 63f2030

62 files changed

Lines changed: 851 additions & 250 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linuxPullRequest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: run checkout.sh
2121
run: bash checkout.sh
2222

23-
- name: run buildRun.sh --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }} ${{ github.event.inputs.logLevel }}
23+
- name: run buildRun.sh --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }}
2424
uses: GabrielBB/xvfb-action@v1.0
2525
with:
26-
run: sh buildRun.sh --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }} ${{ github.event.inputs.logLevel }}
26+
run: sh buildRun.sh --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }}

.github/workflows/syncDocs.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
env:
2+
BUILD_USER: ${{ secrets.BUILD_USER }}
3+
BUILD_USER_PASSWD: ${{ secrets.BUILD_USER_PASSWD }}
4+
BUILD_USER_EMAIL: ${{ secrets.BUILD_USER_EMAIL }}
5+
on:
6+
push:
7+
branches:
8+
- main
9+
name: Sync Docs
10+
jobs:
11+
update-wiki:
12+
if: ${{github.repository == 'devonfw-tutorials/tutorial-compiler'}}
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: setup variables
16+
run: |
17+
echo "ORG=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV
18+
echo "REPO_COMPILER_SOURCE=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
19+
echo "REPO_COMPILER_DEST=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}').wiki" >> $GITHUB_ENV
20+
echo "REPO_TUTORIAL_DEST=$(echo 'tutorials.wiki')" >> $GITHUB_ENV
21+
shell: bash
22+
- name: Checkout ${REPO_COMPILER_SOURCE} Repository
23+
run: git clone https://github.com/${ORG}/${REPO_COMPILER_SOURCE}.git ${REPO_COMPILER_SOURCE}
24+
- name: Checkout ${REPO_COMPILER_DEST} Repository
25+
run: git clone https://github.com/${ORG}/${REPO_COMPILER_DEST}.git ${REPO_COMPILER_DEST}
26+
- name: Checkout ${REPO_TUTORIAL_DEST} Repository
27+
run: git clone https://github.com/${ORG}/${REPO_TUTORIAL_DEST}.git ${REPO_TUTORIAL_DEST}
28+
- name: Copy docs and consolidate links
29+
run: |
30+
cp -rf ${REPO_COMPILER_SOURCE}/documentation/* ${REPO_COMPILER_DEST}/
31+
cd ${REPO_COMPILER_DEST}
32+
grep -lr "link:[a-zA-Z0-9_.-]*.md.*" .| xargs -r sed -i "s/.md//g"
33+
echo ">"
34+
git diff-index --quiet HEAD & git status -s
35+
echo "<"
36+
git status
37+
echo ">"
38+
git diff-index --quiet HEAD & git status -s
39+
echo "<"
40+
echo "TO_BE_CANCELLED=$(if [[ $(git diff-index --quiet HEAD & git status -s) ]]; then echo "false"; else echo "true"; fi)" >> $GITHUB_ENV
41+
echo "$TO_BE_CANCELLED"
42+
- name: Copy docs and consolidate links to ${REPO_TUTORIAL_DEST} Repository
43+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
44+
run: |
45+
cp -rf ${REPO_COMPILER_SOURCE}/documentation/* ${REPO_TUTORIAL_DEST}/
46+
cd ${REPO_TUTORIAL_DEST}
47+
grep -lr "link:[a-zA-Z0-9_.-]*.md.*" .| xargs -r sed -i "s/.md//g"
48+
echo ">"
49+
git diff-index --quiet HEAD & git status -s
50+
echo "<"
51+
git status
52+
echo ">"
53+
git diff-index --quiet HEAD & git status -s
54+
echo "<"
55+
echo "TO_BE_CANCELLED=$(if [[ $(git diff-index --quiet HEAD & git status -s) ]]; then echo "false"; else echo "true"; fi)" >> $GITHUB_ENV
56+
echo "$TO_BE_CANCELLED"
57+
- name: setup git user
58+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
59+
run: |
60+
git config --global user.email ${BUILD_USER_EMAIL}
61+
git config --global user.name ${BUILD_USER}
62+
- name: Sync Wiki
63+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
64+
run: |
65+
cd ${REPO_COMPILER_DEST}
66+
git status
67+
git add .
68+
git commit -m "${REPO_COMPILER_SOURCE} documentation | GitHub Actions $GITHUB_WORKFLOW $GITHUB_RUN_NUMBER"
69+
git remote add origin-wiki "https://${BUILD_USER}:${BUILD_USER_PASSWD}@github.com/${ORG}/${REPO_COMPILER_DEST}.git"
70+
git push origin-wiki main
71+
- name: Sync Wiki ${REPO_TUTORIAL_DEST} Repository
72+
if: ${{ env.TO_BE_CANCELLED == 'false' }}
73+
run: |
74+
cd ${REPO_TUTORIAL_DEST}
75+
git status
76+
git add .
77+
git commit -m "${REPO_COMPILER_SOURCE} documentation | GitHub Actions $GITHUB_WORKFLOW $GITHUB_RUN_NUMBER"
78+
git remote add origin-wiki "https://${BUILD_USER}:${BUILD_USER_PASSWD}@github.com/${ORG}/${REPO_TUTORIAL_DEST}.git"
79+
git push origin-wiki main
80+

.github/workflows/windowsPullRequest.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ jobs:
2020
- name: run checkout.ps1
2121
run: .\checkout.ps1
2222

23-
- name: run buildRun.ps1 --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }} ${{ github.event.inputs.logLevel }}
24-
run: .\buildRun.ps1 --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }} ${{ github.event.inputs.logLevel }}
23+
- name: run buildRun.ps1 --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }}
24+
run: .\buildRun.ps1 --user ${{ github.actor }} --branch ${{ github.event.pull_request.head.ref }}
25+

assertions/serverIsReachable.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ export class ServerIsReachable {
88
let interval = this.getValue(parameters, 'intervall', 5);
99
let startupTime = this.getValue(parameters, 'startupTime', 600);
1010
let command = this.getValue(parameters, 'command', "");
11-
1211
if(!port) {
1312
throw new Error("Missing arguments for the command " + command + ". You have to specify a port for the server. For further information read the function documentation.");
14-
1513
} else {
1614
let timeoutFlag = false;
1715
let reached = false;
@@ -45,4 +43,4 @@ export class ServerIsReachable {
4543
private static sleep(seconds: number) {
4644
return new Promise(resolve => setTimeout(resolve, seconds * 1000));
4745
}
48-
}
46+
}

documentation/Functions.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The following functions are already implemented:
44
* restoreDevonfwIde
55
* restoreWorkspace
66
* changeWorkspace
7+
* executeCommand
78
* installCobiGen
89
* cobiGenJava
910
* createDevon4jProject
@@ -114,6 +115,39 @@ will set the workspace directory to "[working directory]/devonfw/workspaces/proj
114115

115116
Learn more about the workspace directory and working directory on [Structure](https://github.com/devonfw-tutorials/tutorial-compiler/wiki/Structure)
116117

118+
### executeCommand
119+
#### parameter
120+
1. The command that will be executed on Windows
121+
2. The command that will be executed on Linux
122+
3. Json-object with optional fields
123+
* (Optional) Directory where the command will be executed, if not in current directory (relative to workspace){"dir": string}
124+
* (Optional) Synchronous or asynchronous process. Use asynchronous when starting a server. Default is synchronous. {"asynchronous": boolean}
125+
* (Optional) Array of arguments {"args": string[]}
126+
4. Assert information needed if you start a server to check server availability. Only required when you start a asynchronous server.
127+
128+
#### Commands
129+
It is needed to pass a command for Windows and also for Linux-based systems because both systems will always be tested.
130+
131+
##### Assertion information
132+
startupTime = Time in seconds to wait before checking if the server is running
133+
port: Port on which the server is running
134+
path: The URL path on which is checked if the server is running
135+
interval: The availability of the server is checked in the given interval
136+
* (Required) port: will throw error if no port is given.
137+
* (Optional) path: subpath which should be pinged, i.e: if localhost:8081/jumpthequeue should be checked path should be "jumpthequeue". DEFAULT: ""
138+
* (Optional) interval: interval in seconds in which the server should be pinged until it is available or timeouted. DEFAULT: 5 seconds
139+
* (Optional) startupTime: seconds until a timeout will occur and an error will be thrown. DEFAULT: 10 minutes
140+
141+
#### example
142+
143+
executeCommand("node", "node" ,{"args": ["-v"]})
144+
Will create a command for executing node -v .
145+
146+
executeCommand("somePollingScript.ps1","bash somePollingScript.sh", {"dir": "data/setup","asynchronous": true, "args": ["--params 5"]})
147+
Will create a command to execute the script in the directory with the parameter --params 5 and in a new terminal.
148+
149+
executeCommand("someServerScript.ps1","bash someServerScript.sh", {"asynchronous": true, "args":["-port 8080"] },{"port":8080 , "startupTime": 20, "path": "some/path/", "interval": 2})
150+
Starting a server in a new terminal. You have to specify the port for testing, the other parameters are optional. The startupTime can specify how long the runner will wait for a response from the server process and with interval you can set the frequenzy for the server testing. The path is the subpath from your server that should be reached.
117151

118152

119153
### installCobiGen
@@ -193,12 +227,14 @@ example:{...,"placeholder": "private int age;"}
193227
| --- | --- | --- |
194228
|<p>private int age;<br><br>public String getFirstname() {<br>return firstname;<br>}<br></p>|<p>private int age;<br><br>private String company;<br>public String getCompany() {<br>return firstname;<br>}<br>public void setCompany(String company) {<br>this.company = company;<br>}</p>|<p>private int age;<br><br>private String company;<br>public String getCompany() {<br>return firstname;<br>}<br>public void setCompany(String company) {<br>this.company = company;<br><br>public String getFirstname() {<br>return firstname;<br>}<br></p>|
195229

230+
196231
##### Prerequisite
197232
The usage of the line number function requires having VSCode installed on your System. Not having VSCode installed will not create any output for Katacoda.
198233

199234
##### Name of the placeholder
200235
If you want to insert content into your code between two existing lines, take the previous line as your placeholder or use the option to insert at a line number. Add your placeholder into the new file or string, otherwise it will be replaced entirely.
201236

237+
202238
A placeholder is optional. If you do not define a placeholder, the content in the existing file will be simply replaced by the new content.
203239

204240
Please try not to use custom placeholders. Keep in mind that you might want to build the project before changing them. Custom placeholders with a comment-syntax (e.g. "//PLACEHOLDER") will be removed by the console-environment and others might cause errors.
@@ -361,4 +397,13 @@ This command also works if the devonfw IDE is not installed, but then you have t
361397
2. Path of the script (Windows). Relative to the playbook directory
362398

363399
#### example
364-
addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1")
400+
addSetupScript("assets/createProjectScript.sh", "assets/createProjectScript.ps1")
401+
402+
***
403+
404+
### openFile
405+
#### parameter
406+
1. Path of the file to be opened (relative path to the workspace directory)
407+
408+
#### example
409+
openFile("cobigenexample/core/src/main/java/com/example/application/cobigenexample/customermanagement/dataaccess/api/CustomerEntity.java")

engine/engine.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { Playbook } from "./playbook";
33
import { Runner } from "./runner";
44
import { RunCommand } from "./run_command";
55
import { RunResult } from "./run_result";
6+
import { SyntaxErrorLogger } from "./syntax_error_logger";
67

78
export class Engine {
89

910
private runners: Map<string, Runner> = new Map<string, Runner>();
1011
private variables: Map<string, any> = new Map<string, any>();
1112

12-
constructor(private environmentName: string, private environment: Environment, private playbook: Playbook) { }
13+
constructor(private environmentName: string, private environment: Environment, private playbook: Playbook, private syntaxErrorLogger: SyntaxErrorLogger) { }
1314

1415
async run() {
1516
for (let runnerIndex in this.environment.runners) {
@@ -69,6 +70,7 @@ export class Engine {
6970
}
7071

7172
private async isEnvironmentComplete(): Promise<boolean> {
73+
let missingFunctions = [];
7274
for (let stepIndex in this.playbook.steps) {
7375
for (let lineIndex in this.playbook.steps[stepIndex].lines) {
7476
let isSupported = false;
@@ -79,12 +81,16 @@ export class Engine {
7981
}
8082
}
8183
if (!isSupported) {
82-
return false;
84+
missingFunctions.push(this.playbook.steps[stepIndex].lines[lineIndex].name);
8385
}
8486
}
8587
}
86-
87-
return true;
88+
if(missingFunctions.length > 0) {
89+
this.syntaxErrorLogger.handle("Environment incomplete: " + this.environmentName + " | Missing functions: \n - " + missingFunctions.join("\n - "));
90+
return false;
91+
} else {
92+
return true;
93+
}
8894
}
8995

9096
private async getRunner(name: string): Promise<Runner> {

engine/parser.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ blockmarker "===="
4646
= "===="
4747

4848
stepstitle
49-
= "==" _ string __
49+
= "==" _ steptitle __
50+
51+
steptitle
52+
= [^\r\n] + { return { "steptitle": text()};}
5053

5154
steptextlines
5255
= steptextline* { return { "steptextlines": text()}; }

engine/parser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export class Parser {
5252

5353
getTitle(parseResult, index) {
5454
try {
55-
return (parseResult[3][index][3][2]|| parseResult[3][index][2][3][2]);
55+
// parseResult[3][index][4][2] step without block
56+
// parseResult[3][index][2][4][2] step inside a block
57+
return (parseResult[3][index][4][2].steptitle || parseResult[3][index][2][4][2].steptitle);
5658
} catch(error) {
5759
return null;
5860
}

engine/run.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Parser } from "./parser";
22
import { Playbook } from "./playbook";
33
import { Environment } from "./environment";
44
import { Engine } from "./engine";
5-
import { isObject } from "util";
5+
import { SyntaxErrorLogger } from "./syntax_error_logger";
66
const fs = require('fs');
77
const yargs = require('yargs/yargs');
88

@@ -11,22 +11,27 @@ class Run {
1111
private environments: Map<string, Environment> = new Map<string, Environment>();
1212
private args: Map<string, string> = new Map<string, string>();
1313
private errors = [];
14+
private syntaxErrorLogger = new SyntaxErrorLogger();
1415

1516
async run(): Promise<boolean> {
1617
try {
1718
this.parseArgs();
1819
if(!this.args.has("debug")) {
1920
console.debug = function(){}
2021
}
22+
if(this.args.has("checkSyntax")) {
23+
this.syntaxErrorLogger.activate();
24+
}
2125
this.parsePlaybooks();
2226
this.parseEnvironments();
2327
let entries = this.filterEnv(Array.from(this.environments.entries()));
28+
2429
for (let entry of entries) {
2530
let key = entry[0];
2631
let value = entry[1];
2732
let playbookIndecies = this.filterPlaybooks(this.playbooks)
2833
for (let playbookIndex of playbookIndecies) {
29-
let engine = new Engine(key, value, this.playbooks[playbookIndex]);
34+
let engine = new Engine(key, value, this.playbooks[playbookIndex], this.syntaxErrorLogger);
3035

3136
for (let varEntry of Array.from(this.args.entries())) {
3237
engine.setVariable(varEntry[0], varEntry[1]);
@@ -46,7 +51,7 @@ class Run {
4651
}
4752

4853
if (this.errors.length != 0) {
49-
console.log("Errors", this.errors);
54+
console.log("Errors", JSON.stringify(this.errors, null, "\t"));
5055
}
5156
return this.errors.length == 0;
5257
}
@@ -67,6 +72,7 @@ class Run {
6772
}
6873
} catch(e) {
6974
console.error("Error while parsing playbook: " + playbookDirs[index], e);
75+
this.syntaxErrorLogger.handle("Error while parsing playbook: " + playbookDirs[index] + "\n"+ "- " + e);
7076
this.errors.push(e);
7177
}
7278
}

engine/runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export abstract class Runner {
1111
public playbookPath: string;
1212
public playbookTitle: string;
1313
public environmentName: string;
14-
protected readonly useDevonCommand: string = "useDevonCommand";
15-
protected readonly workspaceDirectory: string = "workspaceDirectory";
14+
protected readonly USE_DEVON_COMMAND: string = "useDevonCommand";
15+
protected readonly WORKSPACE_DIRECTORY: string = "workspaceDirectory";
1616

1717
private setVariableCallback: (name: string, value: any) => any;
1818
registerSetVariableCallback(callback: (name: string, value: any) => any) {
@@ -83,7 +83,7 @@ export abstract class Runner {
8383
}
8484

8585
init(playbook: Playbook): void {
86-
this.setVariable(this.useDevonCommand, false);
86+
this.setVariable(this.USE_DEVON_COMMAND, false);
8787
}
8888

8989
run(runCommand: RunCommand): RunResult {

0 commit comments

Comments
 (0)