Skip to content
Open
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
39 changes: 24 additions & 15 deletions .github/workflows/main.yml → .github/workflows/buildMain.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: CI
name: Publish Tutorials and Courses

on:
repository_dispatch:
types: [dispatch-katacoda-scenarios]

workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: choose random polling time
id: randompoll
Expand All @@ -28,33 +25,45 @@ jobs:
poll-interval-seconds: ${{ steps.randompoll.outputs.selected }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout tutorial-compiler
uses: actions/checkout@v2
with:
repository: devonfw-tutorials/tutorial-compiler
path: compiler

- name: Checkout playbooks
uses: actions/checkout@v2
with:
repository: devonfw-tutorials/tutorials
path: playbooks
path: compiler/playbooks


- uses: actions/setup-node@v2-beta

- name: install TS
run: npm install typescript

- name: npm install
run: npm install
run: |
cd compiler
npm install typescript

- name: run buildRun.sh
run: sh buildRun.sh -e katacoda -p ${{ github.event.client_payload.tutorial }}
- name: npm install
run: |
cd compiler
npm install

- name: Checkout
uses: actions/checkout@v2
with:
path: repo

- uses: actions/setup-node@v2-beta
- name: npm install
run: |
cd repo
npm install


- name: publish tutorials
run: bash repo/publishTutorials.sh
- name: create tutorials and courses
run: node repo/publish.js $GITHUB_WORKSPACE

- name: publish tutorials and courses
run: bash repo/publishScenariosAndCourses.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/*
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "katacoda-scenarios",
"version": "1.0.0",
"description": "",
"dependencies": {
"fs-extra": "^10.0.0"
},
"author": "",
"license": "ISC"
}
191 changes: 191 additions & 0 deletions publish.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
const path = require('path');
const fs = require('fs-extra');
const child_process = require("child_process");

const SCENARIOS = path.join(process.argv[2], 'repo');
const COMPILER = path.join(process.argv[2], 'compiler');
const PLAYBOOKS = path.join(COMPILER, 'playbooks');

const TEMP = path.join(process.argv[2], 'temp');
const TEMP_COURSES = path.join(process.argv[2], 'temp', 'courses');
const TEMP_FILES = path.join(process.argv[2], 'temp', 'scenarios');

let usedScenarios = new Array();
let folderNames = new Array();

function publish(){
try{


const SPECIFIED_COURSES = getCourses(PLAYBOOKS);
const SPECIFIED_SCENARIOS = getScenarios(PLAYBOOKS);

//create directories to save temp courses and scenarios
createFolder(TEMP);
createFolder(TEMP_COURSES);
createFolder(TEMP_FILES);

//TODO UPDATE changed course files only
//ISSUE #24
updateCourseFiles();

//TODO GENERATE changed tutorials only
//ISSUE #25
generateNewScenarios();

//TODO UPDATE changed courses only
//ISSUE #26
SPECIFIED_COURSES.forEach(course =>{
createCourse(course);
});

//TODO UPDATE changed scenarios only
//ISSUE #27
SPECIFIED_SCENARIOS.forEach( scenario => {
if(! usedScenarios.includes(scenario)){
createScenario(scenario);
}
});

//Delete unused and newly generated tutorials
cleanUp();
fs.copySync(TEMP_COURSES, SCENARIOS + "/.");
fs.copySync(TEMP_FILES, SCENARIOS + "/.");

let NEW_ONLINE_COURSES = getCourses(SCENARIOS);
let NEW_ONLINE_SCENARIOS = getScenarios(SCENARIOS);
console.log("ALL COURSES", NEW_ONLINE_COURSES)
console.log("ALL SCENARIO- AND COURSE-FOLDERS", NEW_ONLINE_SCENARIOS);
}

catch(e) {
console.error(e);
return -1;
}

}

function updateCourseFiles(){
const ONLINE_COURSES = fs.readdirSync(SCENARIOS, { withFileTypes: true }).filter(dirent => dirent.isFile());
const SPECIFIED_COURSES = fs.readdirSync(PLAYBOOKS, { withFileTypes: true }).filter(dirent => dirent.isFile());

ONLINE_COURSES.forEach(course => {
if(course.name.includes('-pathway')){
fs.removeSync(path.join(SCENARIOS, course.name));
}
});

SPECIFIED_COURSES.forEach(course => {
if(course.name.includes('-pathway')){
fs.copyFile(path.join(PLAYBOOKS, course.name), path.join(SCENARIOS, course.name));
console.log(course.name, 'updated.' );
}
});
}

function generateNewScenarios(){
let cp = child_process.spawnSync(`bash buildRun.sh -e katacoda`, { shell: true, cwd: COMPILER, encoding: 'utf-8' });
if(!fs.existsSync(path.join(COMPILER, 'build', 'output', 'katacoda'))) {
console.log("ERROR[generateNewScenarios]: ", cp);
return "";
}
}

function createCourse(coursefile){
//create course folder
let courseDirName = coursefile.replace("-pathway.json", '');
createFolder(path.join(TEMP_COURSES, courseDirName));
folderNames.push(courseDirName);

//parse scenario names
const genScenariosDir = path.join(COMPILER, 'build', 'output', 'katacoda');
let rawData = fs.readFileSync(path.join(SCENARIOS, coursefile));
let courseJson = JSON.parse(rawData);

courseJson.courses.forEach(scenario => {
fs.copySync(path.join(genScenariosDir, scenario.course_id), path.join(TEMP_COURSES, courseDirName, scenario.course_id));
if(!fs.existsSync(path.join(TEMP_COURSES, courseDirName, scenario.course_id))) {
console.log('Copying', scenario.course_id, 'to', courseDirName, 'failed');
return "";
}
if(!usedScenarios.includes(scenario.course_id)){
usedScenarios.push(scenario.course_id);
}
});

console.log(courseDirName, 'created in temporory directory.' );

}

function createScenario(scenario){
const genScenariosDir = path.join(COMPILER, 'build', 'output', 'katacoda');
folderNames.push(scenario);
fs.copySync(path.join(genScenariosDir, scenario), path.join(TEMP_FILES, scenario));

console.log(scenario, 'created in temporory directory.' );
}

function cleanUp(){
const ONLINE_COURSES = getCourses(SCENARIOS);
const ONLINE_FOLDERS = getScenarios(SCENARIOS);

ONLINE_COURSES.forEach(coursefile => {
course = coursefile.replace('-pathway.json');
if(! folderNames.includes(course)){
fs.removeSync(path.join(SCENARIOS, course), { recursive: true });
console.log(course, "doesn't exist anymore in the tutorials repository." );
}
});

ONLINE_FOLDERS.forEach(scenario => {
if(! folderNames.includes(scenario)){
fs.removeSync(path.join(SCENARIOS, scenario), { recursive: true });
console.log(scenario, "doesn't exist anymore in the tutorials repository." );
}
});

//TODO Filter only newly generated folders
//ISSUE #25 #26
ONLINE_FOLDERS.forEach(scenario => {
if(fs.existsSync(path.join(SCENARIOS, scenario))){
fs.removeSync(path.join(SCENARIOS, scenario), { recursive: true });
console.log(scenario, "removed to replace it with build." );
}
});


}


function getScenarios(dirname){
let folders = fs.readdirSync(dirname, { withFileTypes: true }).filter(dirent => dirent.isDirectory());
let scenarios = new Array();
folders.forEach(folder => {
if(!folder.name.includes('git')){
scenarios.push(folder.name);
}
});
return scenarios;
}


function getCourses(dirname){
let files = fs.readdirSync(dirname, { withFileTypes: true }).filter(dirent => dirent.isFile());
let coursefiles = new Array();
files.forEach(file => {
if(file.name.includes("pathway")){
coursefiles.push(file.name);
}
});
return coursefiles;
}

function createFolder(dirname){
if (fs.existsSync(dirname)){
fs.removeSync(dirname);
}
fs.mkdir(dirname);
console.log(dirname, "was created.");
}

publish();
9 changes: 9 additions & 0 deletions publishScenariosAndCourses.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

cd repo/
git add -A
git config user.email "devonfw"
git config user.name "devonfw"
git commit -m "Updated tutorials"
git pull --rebase origin/master
git push
47 changes: 0 additions & 47 deletions publishTutorials.sh

This file was deleted.