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

ExerciseRun => Adapt for optional results file

parent ff18f6ff
No related branches found
No related tags found
No related merge requests found
Pipeline #26558 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,7 +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', 'exercise path', Config.folders.defaultLocalExercise)
.option('-v, --verbose', 'verbose mode (display docker compose logs in live)')
.action(this.commandAction.bind(this));
}
......@@ -48,11 +48,13 @@ class ExerciseRunCommand extends CommanderCommand {
}
protected async commandAction(options: { path: string, verbose: boolean }): Promise<void> {
const localExercisePath = options.path ?? Config.folders.defaultLocalExercise;
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)
{
......@@ -102,6 +104,8 @@ class ExerciseRunCommand extends CommanderCommand {
assignmentFile = validationResults.results!;
}
haveResultsVolume = assignmentFile.result.volume !== undefined;
spinner.succeed(`The ${ Config.assignment.filename } file is valid`);
}
......@@ -128,12 +132,16 @@ 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) => {
......@@ -152,14 +160,32 @@ class ExerciseRunCommand extends CommanderCommand {
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) => {
......@@ -170,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 ) {
......@@ -184,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) => {
......
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