Skip to content

Commit

Permalink
rename copy action to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
julienj committed Apr 25, 2024
1 parent 214a7a6 commit 51818b3
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions doc/pages/deployment-strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ example :
~~~~yaml
# do not specify a repository
pre_deploy:
- copy: .
- upload: .
exclude: [node_modules]
post_deploy:
- cmd: "php bin/console doctrine:migrations:migrate"
Expand All @@ -53,7 +53,7 @@ For example, you might only send the build of your assets. This approach combine
~~~~yaml
repository: [email protected]:symfony/symfony-demo.git
pre_deploy:
- copy: public/build
- upload: public/build
post_deploy:
- cmd: "php bin/console doctrine:migrations:migrate"
only: [ dev-example-front-01]
Expand Down
4 changes: 2 additions & 2 deletions doc/pages/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ There are two types of actions that can be specified within the hooks:

1. **command:** Allows executing a command on the remote server. For example, `composer install`.

2. **copy:** Allows sending local files or directories to remote servers. You can specify files or directories to exclude from the copy.
2. **upload:** Allows sending local files or directories to remote servers. You can specify files or directories to exclude.

In both cases, it is possible to restrict the servers on which the action should be executed using the `only` option. For example:

Expand All @@ -101,7 +101,7 @@ on_deploy:
- cmd: "composer install"
only: ['dddv-exemple-front-01']

- copy: "build/assets"
- upload: "build/assets"
exclude:
- '/^myfile.ext/'
- '/^folder/subfolder/'
Expand Down
10 changes: 5 additions & 5 deletions src/Automate/CommandDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Automate\Model\Action;
use Automate\Model\Command;
use Automate\Model\Copy;
use Automate\Model\Upload;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

class CommandDenormalizer implements DenormalizerInterface
Expand All @@ -25,13 +25,13 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
{
if (isset($data['cmd'])) {
$action = new Command($data['cmd']);
} elseif (isset($data['copy'])) {
$action = new Copy(
path: $data['copy'],
} elseif (isset($data['upload'])) {
$action = new Upload(
path: $data['upload'],
exclude: $data['exclude'] ?? null
);
} else {
throw new \InvalidArgumentException('Actions must have a "cmd" or "copy" parameter.');
throw new \InvalidArgumentException('Actions must have a "cmd" or "upload" parameter.');
}

$action->setOnly($data['only'] ?? null);
Expand Down
2 changes: 1 addition & 1 deletion src/Automate/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function addCommandsNode(string $name): NodeDefinition
->end()
->children()
->scalarNode('cmd')->end()
->scalarNode('copy')->end()
->scalarNode('upload')->end()
->arrayNode('exclude')->scalarPrototype()->end()->end()
->arrayNode('only')
->defaultValue([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Automate\Model;

class Copy extends Action
class Upload extends Action
{
/**
* @param null|string[] $only
Expand Down
2 changes: 1 addition & 1 deletion src/Automate/Ssh/Ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function exec(string $command): string
return $rs;
}

public function put(string $path, string $target): void
public function upload(string $path, string $target): void
{
if (!$this->sftp instanceof SFTP) {
throw new \RuntimeException('The connection is not active');
Expand Down
8 changes: 4 additions & 4 deletions src/Automate/Workflow/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,22 @@ public function execAsync(string $command, ?array $serversList = null, bool $add
* @param ?string[] $exclude
* @param ?string[] $serversList
*/
public function copy(string $path, ?array $exclude, ?array $serversList = null): void
public function upload(string $path, ?array $exclude, ?array $serversList = null): void
{
$this->logger->command(sprintf('COPY [local] %s to [remote] %s', $path, $path));
$this->logger->command(sprintf('Upload [local] %s to [remote] %s', $path, $path));

if (!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('"%s" does not exist', $path));
}

$this->logger->info(' Copy preparation ...');
$this->logger->info(' Upload preparation ...');
$archive = $this->archiver->archive($path, $exclude);
$archiveFileName = $this->archiver->getArchiveFileName($path);

$this->logger->info(' Send data ...');
$this->exec(static function (Session $session) use ($archive, $archiveFileName): void {
$targetPath = Path::join($session->getReleasePath(), $archiveFileName);
$session->copy($archive->getPath(), $targetPath);
$session->upload($archive->getPath(), $targetPath);
}, $serversList);

$this->logger->info(' Untar data...');
Expand Down
6 changes: 3 additions & 3 deletions src/Automate/Workflow/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Automate\Event\FailedDeployEvent;
use Automate\Model\Action;
use Automate\Model\Command;
use Automate\Model\Copy;
use Automate\Model\Upload;
use Symfony\Component\Filesystem\Path;

/**
Expand Down Expand Up @@ -128,8 +128,8 @@ private function runHooks(array $actions, string $name): void
$this->context->execAsync($action->getCmd(), $action->getOnly());
}

if ($action instanceof Copy) {
$this->context->copy($action->getPath(), $action->getExclude(), $action->getOnly());
if ($action instanceof Upload) {
$this->context->upload($action->getPath(), $action->getExclude(), $action->getOnly());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Automate/Workflow/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function execAsync(string $command, bool $addWorkingDir = true): Process
return $this->ssh->execAsync($command);
}

public function copy(string $path, string $target): void
public function upload(string $path, string $target): void
{
$this->ssh->put($path, $target);
$this->ssh->upload($path, $target);
}

public function mkdir(string $path, bool $recursive = false): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Automate/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use Automate\Loader;
use Automate\Model\Action;
use Automate\Model\Command;
use Automate\Model\Copy;
use Automate\Model\Project;
use Automate\Model\Server;
use Automate\Model\Upload;
use PHPUnit\Framework\TestCase;

class LoaderTest extends TestCase
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testLoader(): void
$this->assertEquals('php bin/console messenger:consume', $project->getPostDeploy()[3]->getCmd());
$this->assertEquals(['eddv-exemple-front-01', 'dddv-exemple-front-01'], $project->getPostDeploy()[3]->getOnly());

$this->assertInstanceOf(Copy::class, $project->getPostDeploy()[4]);
$this->assertInstanceOf(Upload::class, $project->getPostDeploy()[4]);
$this->assertEquals('public/build', $project->getPostDeploy()[4]->getPath());
$this->assertEquals(['vendor'], $project->getPostDeploy()[4]->getExclude());

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ post_deploy:
- "php bin/console doctrine:cache:clear-result"
- cmd: "php bin/console messenger:consume"
only: ["eddv-exemple-front-01", "dddv-exemple-front-01"]
- copy: "public/build"
- upload: "public/build"
exclude:
- vendor

0 comments on commit 51818b3

Please sign in to comment.