Skip to content

Commit

Permalink
Allow forcing asset re-uploading (#122)
Browse files Browse the repository at this point in the history
* allow forcing asset reuploading

* fix style

* Update DeployCommand.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
themsaid and taylorotwell authored May 6, 2021
1 parent 34b8a43 commit 9bf5c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Commands/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protected function configure()
->addOption('commit', null, InputOption::VALUE_OPTIONAL, 'The commit hash that is being deployed')
->addOption('message', null, InputOption::VALUE_OPTIONAL, 'The message for the commit that is being deployed')
->addOption('without-waiting', null, InputOption::VALUE_NONE, 'Deploy without waiting for progress')
->addOption('fresh-assets', null, InputOption::VALUE_NONE, 'Upload a fresh copy of all assets')
->setDescription('Deploy an environment');
}

Expand Down Expand Up @@ -202,7 +203,7 @@ protected function serveAssets(array $artifact)
{
Helpers::line();

(new ServeAssets())->__invoke($this->vapor, $artifact);
(new ServeAssets())->__invoke($this->vapor, $artifact, $this->option('fresh-assets'));
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/ConsoleVaporClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,15 @@ public function createArtifact(
*
* @param int $artifactId
* @param array $files
* @param bool $fresh
*
* @return array
*/
public function authorizeArtifactAssets($artifactId, array $files)
public function authorizeArtifactAssets($artifactId, array $files, bool $fresh = false)
{
return $this->requestWithErrorHandling('post', '/api/artifacts/'.$artifactId.'/asset-authorizations', [
'files' => $files,
'fresh' => $fresh,
]);
}

Expand Down
16 changes: 11 additions & 5 deletions src/ServeAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ class ServeAssets
*
* @param \Laravel\VaporCli\ConsoleVaporClient $vapor
* @param array $artifact
* @param bool $fresh
*
* @return void
*/
public function __invoke(ConsoleVaporClient $vapor, array $artifact)
public function __invoke(ConsoleVaporClient $vapor, array $artifact, $fresh)
{
$assetPath = Path::build().'/assets';

$requests = $this->getAuthorizedAssetRequests(
$vapor,
$artifact,
$assetFiles = $this->getAssetFiles($assetPath)
$assetFiles = $this->getAssetFiles($assetPath),
$fresh
);

$this->executeStoreAssetRequests($requests['store'], $assetPath);
Expand Down Expand Up @@ -72,7 +74,9 @@ protected function executeCopyAssetRequests($requests, $assetPath)
Helpers::step('<fg=magenta>Copying Unchanged Asset:</> '.$request['path'].' ('.Helpers::kilobytes($assetPath.'/'.$request['path']).')');
}

$storage->executeCopyRequests($requests);
if (! empty($requests)) {
$storage->executeCopyRequests($requests);
}
}

/**
Expand All @@ -87,11 +91,13 @@ protected function executeCopyAssetRequests($requests, $assetPath)
protected function getAuthorizedAssetRequests(
ConsoleVaporClient $vapor,
array $artifact,
array $assetFiles
array $assetFiles,
bool $fresh
) {
return $vapor->authorizeArtifactAssets(
$artifact['id'],
$assetFiles
$assetFiles,
$fresh
);
}

Expand Down

0 comments on commit 9bf5c87

Please sign in to comment.