diff --git a/src/Automate/Configuration.php b/src/Automate/Configuration.php index 0528667..8eea689 100644 --- a/src/Automate/Configuration.php +++ b/src/Automate/Configuration.php @@ -53,7 +53,14 @@ private function addCommandsNode($name) ->end() ->children() ->scalarNode('cmd')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('only')->defaultNull()->end() + ->arrayNode('only') + ->defaultValue([]) + ->beforeNormalization() + ->ifString() + ->then(function ($v) { return [$v]; }) + ->end() + ->scalarPrototype()->end() + ->end() ->end() ->end() ; diff --git a/src/Automate/Context/AbstractContext.php b/src/Automate/Context/AbstractContext.php index 9e31b0a..5b72ca0 100644 --- a/src/Automate/Context/AbstractContext.php +++ b/src/Automate/Context/AbstractContext.php @@ -171,12 +171,12 @@ public function getReleaseId() /** * {@inheritdoc} */ - public function run($command, $verbose = false, $specificServer = null, $addWorkingDir = true) + public function run($command, $verbose = false, $specificServers = null, $addWorkingDir = true) { $servers = $this->platform->getServers(); foreach ($servers as $server) { - if($specificServer && $server->getName() != $specificServer) { + if($specificServers && !in_array($server->getName(), $specificServers)) { continue; } $this->logger->command($command, $verbose); diff --git a/src/Automate/Context/ContextInterface.php b/src/Automate/Context/ContextInterface.php index fbde67d..54963bf 100644 --- a/src/Automate/Context/ContextInterface.php +++ b/src/Automate/Context/ContextInterface.php @@ -96,10 +96,11 @@ public function getReleaseId(); * @param string $command * * @param bool $verbose - * @param null $specificServer + * @param array|null $specificServers + * @param bool $addWorkingDir * @return mixed */ - public function run($command, $verbose = false, $specificServer = null); + public function run($command, $verbose = false, $specificServers = null, $addWorkingDir = true); /** * Run on server. diff --git a/src/Automate/Model/Command.php b/src/Automate/Model/Command.php index e580c00..fa78ca0 100644 --- a/src/Automate/Model/Command.php +++ b/src/Automate/Model/Command.php @@ -22,7 +22,7 @@ class Command private $cmd; /** - * @var string + * @var array */ private $only; @@ -47,7 +47,7 @@ public function setCmd($cmd) } /** - * @return string + * @return array */ public function getOnly() { @@ -55,11 +55,11 @@ public function getOnly() } /** - * @param string $only + * @param array $only * * @return Command */ - public function setOnly($only) + public function setOnly(array $only) { $this->only = $only; diff --git a/tests/Automate/LoaderTest.php b/tests/Automate/LoaderTest.php index 229ea00..cb9d452 100644 --- a/tests/Automate/LoaderTest.php +++ b/tests/Automate/LoaderTest.php @@ -48,13 +48,16 @@ public function testLoader() } $this->assertEquals('php bin/console doctrine:cache:clear-metadata', $project->getPostDeploy()[0]->getCmd()); - $this->assertEquals(null , $project->getPostDeploy()[0]->getOnly()); + $this->assertEquals([] , $project->getPostDeploy()[0]->getOnly()); $this->assertEquals('php bin/console doctrine:schema:update --force', $project->getPostDeploy()[1]->getCmd()); - $this->assertEquals('eddv-exemple-front-01' , $project->getPostDeploy()[1]->getOnly()); + $this->assertEquals(['eddv-exemple-front-01'] , $project->getPostDeploy()[1]->getOnly()); $this->assertEquals('php bin/console doctrine:cache:clear-result', $project->getPostDeploy()[2]->getCmd()); - $this->assertEquals(null , $project->getPostDeploy()[2]->getOnly()); + $this->assertEquals([] , $project->getPostDeploy()[2]->getOnly()); + + $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->assertCount(2, $project->getPlatforms()); diff --git a/tests/fixtures/config.yml b/tests/fixtures/config.yml index 4b227f6..fce319b 100644 --- a/tests/fixtures/config.yml +++ b/tests/fixtures/config.yml @@ -42,4 +42,6 @@ post_deploy: - "php bin/console doctrine:cache:clear-metadata" - cmd: "php bin/console doctrine:schema:update --force" only: eddv-exemple-front-01 - - "php bin/console doctrine:cache:clear-result" \ No newline at end of file + - "php bin/console doctrine:cache:clear-result" + - cmd: "php bin/console messenger:consume" + only: ["eddv-exemple-front-01", "dddv-exemple-front-01"] \ No newline at end of file