dryrun-ci
Version:
DryRun CI - Local GitLab CI/CD pipeline testing tool with Docker execution, performance monitoring, and security sandboxing
111 lines (110 loc) ⢠4.87 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RealTimeUiManager = void 0;
const ora_1 = __importDefault(require("ora"));
const cli_progress_1 = __importDefault(require("cli-progress"));
const chalk_1 = __importDefault(require("chalk"));
class RealTimeUiManager {
constructor() {
this.currentStage = '';
this.startTime = 0;
this.stageStartTimes = new Map();
this.jobStartTimes = new Map();
this.stageSpinner = (0, ora_1.default)();
this.jobProgress = new cli_progress_1.default.SingleBar({
format: '{bar} | {percentage}% | {stage}: {value}/{total} jobs',
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
});
}
startPipeline() {
this.startTime = Date.now();
console.log(chalk_1.default.cyan('\nš Starting pipeline execution\n'));
}
startStage(stageName, totalJobs) {
this.currentStage = stageName;
this.stageStartTimes.set(stageName, Date.now());
console.log(chalk_1.default.yellow(`\nš¦ Stage: ${stageName}`));
this.jobProgress.start(totalJobs, 0, { stage: stageName });
}
startJob(job) {
this.jobStartTimes.set(job.name, Date.now());
this.stageSpinner.start(chalk_1.default.blue(`āļø Running job: ${job.name}`));
}
updateJobProgress(completed) {
this.jobProgress.update(completed);
}
completeJob(job) {
const duration = this.formatDuration(Date.now() - (this.jobStartTimes.get(job.name) || 0));
this.stageSpinner.stop();
const status = job.status === 'success'
? chalk_1.default.green('ā
Success')
: chalk_1.default.red('ā Failed');
console.log(`${status} | ${chalk_1.default.blue(job.name)} (${duration})`);
if (job.output && job.output.length > 0) {
console.log(chalk_1.default.gray('Output:'));
console.log(chalk_1.default.gray('----------------------------------------'));
console.log(job.output.join('\n'));
console.log(chalk_1.default.gray('----------------------------------------\n'));
}
}
completeStage(stageName) {
const duration = this.formatDuration(Date.now() - (this.stageStartTimes.get(stageName) || 0));
this.jobProgress.stop();
console.log(chalk_1.default.green(`\n⨠Stage ${stageName} completed (${duration})`));
}
completePipeline(execution) {
const durationMs = Date.now() - this.startTime;
const duration = this.formatDuration(durationMs);
const status = execution.status === 'success'
? chalk_1.default.green('ā
Pipeline succeeded')
: chalk_1.default.red('ā Pipeline failed');
console.log('\n----------------------------------------');
console.log(`${status} (${duration})`);
console.log('----------------------------------------\n');
console.log(chalk_1.default.cyan('š Pipeline Summary:'));
const summary = this.generatePipelineSummary(execution);
console.log(summary);
console.log(chalk_1.default.magenta(`\nš Total elapsed time: ${duration}`));
}
generatePipelineSummary(execution) {
const stageStats = new Map();
for (const job of execution.jobs) {
if (!stageStats.has(job.stage)) {
stageStats.set(job.stage, { total: 0, success: 0, failed: 0 });
}
const stats = stageStats.get(job.stage);
stats.total++;
if (job.status === 'success')
stats.success++;
if (job.status === 'failed')
stats.failed++;
}
let summary = '';
for (const [stage, stats] of stageStats) {
const duration = this.formatDuration((this.stageStartTimes.get(stage) || 0) -
(this.stageStartTimes.get(stage) || 0));
summary += `\n${chalk_1.default.yellow(stage)} (${duration}):\n`;
summary += ` Total Jobs: ${stats.total}\n`;
summary += ` ${chalk_1.default.green('Successful')}: ${stats.success}\n`;
if (stats.failed > 0) {
summary += ` ${chalk_1.default.red('Failed')}: ${stats.failed}\n`;
}
}
return summary;
}
formatDuration(ms) {
if (ms < 1000)
return `${ms}ms`;
const seconds = Math.floor(ms / 1000);
if (seconds < 60)
return `${seconds}s`;
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}m ${remainingSeconds}s`;
}
}
exports.RealTimeUiManager = RealTimeUiManager;