Skip to content

Commit

Permalink
fix: deployment command showing wrong output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
olivernybroe committed Jun 24, 2024
1 parent b05be4f commit bc6ac89
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->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.');

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 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;
}

/**
Expand Down

0 comments on commit bc6ac89

Please sign in to comment.