Skip to content
Snippets Groups Projects
Commit e2fac0e0 authored by michael.minelli's avatar michael.minelli
Browse files

Merge branch 'success_optional_and_compose_verbose' into v2.2.0

parents 52a6dd06 0dd0a7eb
No related branches found
No related tags found
No related merge requests found
Pipeline #26560 passed
......@@ -10,10 +10,10 @@ import path from 'path';
import ClientsSharedConfig from '../../sharedByClients/config/ClientsSharedConfig';
import AssignmentFile from '../../shared/types/Dojo/AssignmentFile';
import ExerciseDockerCompose from '../../sharedByClients/helpers/Dojo/ExerciseDockerCompose';
import ExerciseResultsValidation from '../../sharedByClients/helpers/Dojo/ExerciseResultsValidation';
import SharedAssignmentHelper from '../../shared/helpers/Dojo/SharedAssignmentHelper';
import ExerciseCheckerError from '../../shared/types/Dojo/ExerciseCheckerError';
import ClientsSharedExerciseHelper from '../../sharedByClients/helpers/Dojo/ClientsSharedExerciseHelper';
import ExerciseResultsSanitizerAndValidator from '../../sharedByClients/helpers/Dojo/ExerciseResultsSanitizerAndValidator';
const execAsync = util.promisify(exec);
......@@ -36,6 +36,7 @@ class ExerciseRunCommand extends CommanderCommand {
this.command
.description('locally run an exercise')
.option('-p, --path <value>', 'exercise path', Config.folders.defaultLocalExercise)
.option('-v, --verbose', 'verbose mode (display docker compose logs in live)')
.action(this.commandAction.bind(this));
}
......@@ -46,12 +47,14 @@ class ExerciseRunCommand extends CommanderCommand {
}).start().info();
}
protected async commandAction(options: any): Promise<void> {
const localExercisePath = options.path ?? Config.folders.defaultLocalExercise;
protected async commandAction(options: { path: string, verbose: boolean }): Promise<void> {
const localExercisePath: string = options.path ?? Config.folders.defaultLocalExercise;
let assignmentFile: AssignmentFile;
let exerciseDockerCompose: ExerciseDockerCompose;
let exerciseResultsValidation: ExerciseResultsValidation;
let exerciseResultsValidation: ExerciseResultsSanitizerAndValidator;
let haveResultsVolume: boolean;
// Step 1: Check requirements (if it's an exercise folder and if Docker deamon is running)
{
......@@ -101,6 +104,8 @@ class ExerciseRunCommand extends CommanderCommand {
assignmentFile = validationResults.results!;
}
haveResultsVolume = assignmentFile.result.volume !== undefined;
spinner.succeed(`The ${ Config.assignment.filename } file is valid`);
}
......@@ -127,30 +132,60 @@ class ExerciseRunCommand extends CommanderCommand {
{
console.log(chalk.cyan('Please wait while we are running the exercise...'));
let composeFileOverride: string[] = [];
const composeOverridePath: string = path.join(localExercisePath, 'docker-compose-override.yml');
const composeOverride = fs.readFileSync(path.join(__dirname, '../../../assets/docker-compose-override.yml'), 'utf8').replace('{{VOLUME_NAME}}', assignmentFile.result.volume).replace('{{MOUNT_PATH}}', this.folderResultsExercise);
if ( haveResultsVolume ) {
const composeOverride = fs.readFileSync(path.join(__dirname, '../../../assets/docker-compose-override.yml'), 'utf8').replace('{{VOLUME_NAME}}', assignmentFile.result.volume!).replace('{{MOUNT_PATH}}', this.folderResultsExercise);
fs.writeFileSync(composeOverridePath, composeOverride);
exerciseDockerCompose = new ExerciseDockerCompose(this.projectName, assignmentFile, localExercisePath, [ composeOverridePath ]);
composeFileOverride = [ composeOverridePath ];
}
exerciseDockerCompose = new ExerciseDockerCompose(this.projectName, assignmentFile, localExercisePath, composeFileOverride);
try {
await new Promise<void>((resolve, reject) => {
let spinner: ora.Ora;
if ( options.verbose ) {
exerciseDockerCompose.events.on('logs', (log: string, _error: boolean, displayable: boolean) => {
if ( displayable ) {
console.log(log);
}
});
}
exerciseDockerCompose.events.on('step', (name: string, message: string) => {
spinner = ora({
text : message,
indent: 4
}).start();
if ( options.verbose && name == 'COMPOSE_RUN' ) {
spinner.info();
}
});
exerciseDockerCompose.events.on('endStep', (stepName: string, message: string, error: boolean) => {
if ( error ) {
if ( options.verbose && stepName == 'COMPOSE_RUN' ) {
ora({
text : message,
indent: 4
}).start().fail();
} else {
spinner.fail(message);
}
} else {
if ( options.verbose && stepName == 'COMPOSE_RUN' ) {
ora({
text : message,
indent: 4
}).start().succeed();
} else {
spinner.succeed(message);
}
}
});
exerciseDockerCompose.events.on('finished', (success: boolean, exitCode: number) => {
......@@ -161,7 +196,7 @@ class ExerciseRunCommand extends CommanderCommand {
});
} catch ( error ) { }
fs.rmSync(composeOverridePath);
fs.rmSync(composeOverridePath, { force: true });
fs.writeFileSync(this.fileComposeLogs, exerciseDockerCompose.allLogs);
if ( !exerciseDockerCompose.success ) {
......@@ -175,7 +210,7 @@ class ExerciseRunCommand extends CommanderCommand {
{
console.log(chalk.cyan('Please wait while we are checking the results...'));
exerciseResultsValidation = new ExerciseResultsValidation(this.folderResultsDojo, this.folderResultsExercise);
exerciseResultsValidation = new ExerciseResultsSanitizerAndValidator(this.folderResultsDojo, this.folderResultsExercise, exerciseDockerCompose.exitCode);
try {
await new Promise<void>((resolve, reject) => {
......
......@@ -15,7 +15,7 @@ class SessionAppLoginCommand extends CommanderCommand {
.action(this.commandAction.bind(this));
}
protected async commandAction(options: any): Promise<void> {
protected async commandAction(options: { user: string, password: string }): Promise<void> {
if ( !options.password ) {
options.password = (await inquirer.prompt({
type : 'password',
......
......@@ -14,7 +14,7 @@ class SessionGitlabLoginCommand extends CommanderCommand {
.action(this.commandAction.bind(this));
}
protected async commandAction(options: any): Promise<void> {
protected async commandAction(options: { token: string }): Promise<void> {
if ( !options.token ) {
options.token = (await inquirer.prompt({
type : 'password',
......
Subproject commit 8d7e3ca0cca10e874ac48e19e47da8a1491ccba7
Subproject commit 8bdbef31376a8284bd8a5139588b43a57cf74a4b
Subproject commit 4ff3846e9415a6122b0b966be089eec3f0117f4f
Subproject commit 97ba763f9517880ecfa6245c172a0e330ebdd11a
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment