From bc6ac89e312b01779fe28ea6619365c2c8a5298e Mon Sep 17 00:00:00 2001 From: olivernybroe Date: Mon, 24 Jun 2024 11:27:32 +0200 Subject: [PATCH] fix: deployment command showing wrong output Deployment command was looking for an event id by the description, however deployment commands always have the same description. This resulted in it getting the previous deployment output. Changed to use deployment id for finding deployment output instead of event id. --- app/Commands/Concerns/InteractsWithEvents.php | 25 ++++++++---- app/Commands/DeployCommand.php | 40 ++++++++++++------- 2 files changed, 44 insertions(+), 21 deletions(-) diff --git a/app/Commands/Concerns/InteractsWithEvents.php b/app/Commands/Concerns/InteractsWithEvents.php index f02998d..09227a6 100644 --- a/app/Commands/Concerns/InteractsWithEvents.php +++ b/app/Commands/Concerns/InteractsWithEvents.php @@ -45,13 +45,8 @@ protected function displayEventOutput($username, $eventId, $while = null) } if ($exitCode == 0) { - collect($output)->slice(count($this->outputBuffer[$eventId])) - ->map('trim') - ->filter(function ($line) { - return ! empty($line); - })->each(function ($line) { - $this->line(" ▕ $line"); - }); + $this->displayOutput(collect($output)->slice(count($this->outputBuffer[$eventId])) + ->map('trim')); $this->outputBuffer[$eventId] = $output; } @@ -60,6 +55,22 @@ protected function displayEventOutput($username, $eventId, $while = null) $while ? $this->displayEventOutput($username, $eventId) : $this->line(''); } + /** + * Display the output of the given collection indenting each line. + * + * @param \Illuminate\Support\Collection $collection + * @return void + */ + protected function displayOutput($collection) + { + $collection->map('trim') + ->filter(function ($line) { + return ! empty($line); + })->each(function ($line) { + return $this->line(" ▕ $line"); + }); + } + /** * Find the first event by the given "description". * diff --git a/app/Commands/DeployCommand.php b/app/Commands/DeployCommand.php index fce0f56..10bb761 100644 --- a/app/Commands/DeployCommand.php +++ b/app/Commands/DeployCommand.php @@ -52,15 +52,13 @@ public function deploy($site) $this->forge->deploySite($server->id, $site->id, false); - [$deploymentId, $eventId] = $this->ensureDeploymentHaveStarted($site); + $deploymentId = $this->ensureDeploymentHaveStarted($site); - $deployment = null; + $deployment = $this->ensureDeploymentHaveFinished($server, $site, $deploymentId); - $this->displayEventOutput($site->username, $eventId, function () use ($server, $site, $deploymentId, &$deployment) { - $deployment = $this->forge->siteDeployment($server->id, $site->id, $deploymentId); - - return $deployment->status == 'deploying'; - }); + $output = $this->forge->siteDeploymentOutput($server->id, $site->id, $deploymentId); + $output = explode(PHP_EOL, $output); + $this->displayOutput(collect($output)); abort_if($deployment->status == 'failed', 1, 'The deployment failed.'); @@ -71,7 +69,7 @@ public function deploy($site) * Ensure the deployment have started on the server. * * @param \Laravel\Forge\Resources\Site $site - * @return array + * @return int */ protected function ensureDeploymentHaveStarted($site) { @@ -88,17 +86,31 @@ protected function ensureDeploymentHaveStarted($site) $this->step('Deploying'); - $eventId = $this->findEventId(sprintf( - 'Deploying Pushed Code (%s).', - $site->name - )); - $deploymentId = collect($this->forge->siteDeployments( $this->currentServer()->id, $site->id, ))->first()['id']; - return [$deploymentId, $eventId]; + return $deploymentId; + } + + /** + * Ensure the deployment have finished on the server. + * + * @param \Laravel\Forge\Resources\Server $server + * @param \Laravel\Forge\Resources\Site $site + * @param \Laravel\Forge\Resources\Site $site + * @return object + */ + protected function ensureDeploymentHaveFinished($server, $site, $deploymentId) + { + do { + $this->time->sleep(1); + + $deployment = $this->forge->siteDeployment($server->id, $site->id, $deploymentId); + } while ($deployment->status == 'deploying'); + + return $deployment; } /**