Skip to content
Merged
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
21 changes: 11 additions & 10 deletions src/Commands/ProtocolStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// Prepare sub-command inputs
$arrInput = new ArrayInput(['--dir' => $repo_dir]);
$arrInput1 = new ArrayInput(['--dir' => $repo_dir, 'environment' => $environment]);
$nullOutput = new NullOutput();
$verbose = $output->isVerbose();
$subOutput = $verbose ? $output : new NullOutput();
$app = $this->getApplication();

$output->writeln('');

$runner = new StageRunner($output);
$runner = new StageRunner($output, $verbose);

// ── Stage 1: Scanning codebase ──────────────────────────
$runner->run('Scanning codebase', function() use ($repo_dir, $environment, $strategy) {
Expand All @@ -159,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
});

// ── Stage 2: Infrastructure provisioning ────────────────
$runner->run('Infrastructure provisioning', function() use ($runner, $app, $arrInput, $arrInput1, $nullOutput, $repo_dir, $environment, $strategy, $isDev, $nodeConfig, $nodeData) {
$runner->run('Infrastructure provisioning', function() use ($runner, $app, $arrInput, $arrInput1, $subOutput, $repo_dir, $environment, $strategy, $isDev, $nodeConfig, $nodeData) {

// Refresh GitHub App credentials and fix remote URLs if needed
if (GitHubApp::isConfigured()) {
Expand Down Expand Up @@ -204,15 +205,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($hasConfigRepo) {
if ($configRemote) {
$runner->log("Running config:slave");
$app->find('config:slave')->run($arrInput, $nullOutput);
$app->find('config:slave')->run($arrInput, $subOutput);
}
$runner->log("Running config:link");
$app->find('config:link')->run($arrInput, $nullOutput);
$app->find('config:link')->run($arrInput, $subOutput);
}

// Start the release watcher daemon
$runner->log("Running deploy:slave");
$app->find('deploy:slave')->run($arrInput, $nullOutput);
$app->find('deploy:slave')->run($arrInput, $subOutput);

} else {
// Legacy branch-based deployment mode
Expand All @@ -227,20 +228,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$runner->log("remote.origin.url={$remoteUrl}");

$runner->log("Running git:pull");
$app->find('git:pull')->run($arrInput, $nullOutput);
$app->find('git:pull')->run($arrInput, $subOutput);
$runner->log("git:pull completed");
$runner->log("Running git:slave");
$app->find('git:slave')->run($arrInput, $nullOutput);
$app->find('git:slave')->run($arrInput, $subOutput);
}

if ($hasConfigRepo) {
if (!$isDev && $configRemote) {
$runner->log("Running config:slave");
$app->find('config:slave')->run($arrInput, $nullOutput);
$app->find('config:slave')->run($arrInput, $subOutput);
}

$runner->log("Running config:link");
$app->find('config:link')->run($arrInput, $nullOutput);
$app->find('config:link')->run($arrInput, $subOutput);
}
}

Expand Down
25 changes: 16 additions & 9 deletions src/Helpers/StageRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class StageRunner

private OutputInterface $output;
private bool $isTty;
private bool $verbose;
private array $completedStages = [];
private float $startTime;
private ?string $logFile = null;
private ?string $currentStage = null;

public function __construct(OutputInterface $output)
public function __construct(OutputInterface $output, bool $verbose = false)
{
$this->output = $output;
$this->isTty = self::isTty();
$this->verbose = $verbose;
$this->isTty = $verbose ? false : self::isTty();
$this->startTime = microtime(true);
$this->initLog();
}
Expand Down Expand Up @@ -67,15 +69,20 @@ private function initLog(): void
*/
public function log(string $message): void
{
if (!$this->logFile) return;

$timestamp = date('H:i:s');
$prefix = $this->currentStage ? "[{$this->currentStage}] " : '';
@file_put_contents(
$this->logFile,
"[{$timestamp}] {$prefix}{$message}\n",
FILE_APPEND | LOCK_EX
);

if ($this->logFile) {
@file_put_contents(
$this->logFile,
"[{$timestamp}] {$prefix}{$message}\n",
FILE_APPEND | LOCK_EX
);
}

if ($this->verbose) {
$this->output->writeln("[{$timestamp}] {$prefix}{$message}");
}
}

/**
Expand Down
Loading