From 51818b3cf776f2959f8d5c4f1cb8310af3148711 Mon Sep 17 00:00:00 2001 From: Julien Jacottet Date: Thu, 25 Apr 2024 21:39:27 +0200 Subject: [PATCH] rename copy action to upload --- doc/pages/deployment-strategies.md | 4 ++-- doc/pages/reference.md | 4 ++-- src/Automate/CommandDenormalizer.php | 10 +++++----- src/Automate/Configuration.php | 2 +- src/Automate/Model/{Copy.php => Upload.php} | 2 +- src/Automate/Ssh/Ssh.php | 2 +- src/Automate/Workflow/Context.php | 8 ++++---- src/Automate/Workflow/Deployer.php | 6 +++--- src/Automate/Workflow/Session.php | 4 ++-- tests/Automate/LoaderTest.php | 4 ++-- tests/fixtures/config.yml | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) rename src/Automate/Model/{Copy.php => Upload.php} (97%) diff --git a/doc/pages/deployment-strategies.md b/doc/pages/deployment-strategies.md index 9913db7..5754710 100644 --- a/doc/pages/deployment-strategies.md +++ b/doc/pages/deployment-strategies.md @@ -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" @@ -53,7 +53,7 @@ For example, you might only send the build of your assets. This approach combine ~~~~yaml repository: git@github.com: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] diff --git a/doc/pages/reference.md b/doc/pages/reference.md index 629e827..3075cc1 100644 --- a/doc/pages/reference.md +++ b/doc/pages/reference.md @@ -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: @@ -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/' diff --git a/src/Automate/CommandDenormalizer.php b/src/Automate/CommandDenormalizer.php index 0c66bfb..fc52988 100644 --- a/src/Automate/CommandDenormalizer.php +++ b/src/Automate/CommandDenormalizer.php @@ -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 @@ -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); diff --git a/src/Automate/Configuration.php b/src/Automate/Configuration.php index fe6383d..8966da7 100644 --- a/src/Automate/Configuration.php +++ b/src/Automate/Configuration.php @@ -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([]) diff --git a/src/Automate/Model/Copy.php b/src/Automate/Model/Upload.php similarity index 97% rename from src/Automate/Model/Copy.php rename to src/Automate/Model/Upload.php index abe6586..0b2c3c7 100644 --- a/src/Automate/Model/Copy.php +++ b/src/Automate/Model/Upload.php @@ -11,7 +11,7 @@ namespace Automate\Model; -class Copy extends Action +class Upload extends Action { /** * @param null|string[] $only diff --git a/src/Automate/Ssh/Ssh.php b/src/Automate/Ssh/Ssh.php index 445c325..c30fcf4 100644 --- a/src/Automate/Ssh/Ssh.php +++ b/src/Automate/Ssh/Ssh.php @@ -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'); diff --git a/src/Automate/Workflow/Context.php b/src/Automate/Workflow/Context.php index 54c4157..5d17abb 100644 --- a/src/Automate/Workflow/Context.php +++ b/src/Automate/Workflow/Context.php @@ -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...'); diff --git a/src/Automate/Workflow/Deployer.php b/src/Automate/Workflow/Deployer.php index 0b08d17..b64901c 100644 --- a/src/Automate/Workflow/Deployer.php +++ b/src/Automate/Workflow/Deployer.php @@ -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; /** @@ -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()); } } } diff --git a/src/Automate/Workflow/Session.php b/src/Automate/Workflow/Session.php index d0943ce..57f9c7b 100644 --- a/src/Automate/Workflow/Session.php +++ b/src/Automate/Workflow/Session.php @@ -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 diff --git a/tests/Automate/LoaderTest.php b/tests/Automate/LoaderTest.php index d3b3744..d1b813e 100644 --- a/tests/Automate/LoaderTest.php +++ b/tests/Automate/LoaderTest.php @@ -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 @@ -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()); diff --git a/tests/fixtures/config.yml b/tests/fixtures/config.yml index 4e8210c..c0a3d29 100644 --- a/tests/fixtures/config.yml +++ b/tests/fixtures/config.yml @@ -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