Skip to content

Commit

Permalink
Merge pull request #88 from laravel/fix_deployment_output
Browse files Browse the repository at this point in the history
fix: deployment command showing wrong output
  • Loading branch information
olivernybroe authored Jun 24, 2024
2 parents 98b9750 + 8715fff commit 237a34a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
25 changes: 18 additions & 7 deletions app/Commands/Concerns/InteractsWithEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(" <fg=#6C7280>▕</> $line");
});
$this->displayOutput(collect($output)->slice(count($this->outputBuffer[$eventId]))
->map('trim'));

$this->outputBuffer[$eventId] = $output;
}
Expand All @@ -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(" <fg=#6C7280>▕</> $line");
});
}

/**
* Find the first event by the given "description".
*
Expand Down
40 changes: 26 additions & 14 deletions app/Commands/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->ensureDeploymentHasFinished($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.');

Expand All @@ -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)
{
Expand All @@ -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 has finished on the server.
*
* @param \Laravel\Forge\Resources\Server $server
* @param \Laravel\Forge\Resources\Site $site
* @param int $deploymentId
* @return object
*/
protected function ensureDeploymentHasFinished($server, $site, $deploymentId)
{
do {
$this->time->sleep(1);

$deployment = $this->forge->siteDeployment($server->id, $site->id, $deploymentId);
} while ($deployment->status == 'deploying');

return $deployment;
}

/**
Expand Down

0 comments on commit 237a34a

Please sign in to comment.