From 0fe106610a411b9a031c6fcaf8182368430f4e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Fri, 14 Apr 2017 16:29:22 -0300 Subject: [PATCH] Allow Exclude to be defined globally. --- CHANGELOG.md | 1 + src/Task/BuiltIn/Deploy/RsyncTask.php | 2 +- src/Task/BuiltIn/Deploy/Tar/PrepareTask.php | 2 +- .../BuiltIn/DeployCommandMiscTasksTest.php | 30 +++++++++++++++++++ tests/Resources/global-exclude.yml | 17 +++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/Resources/global-exclude.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a7930a..4084637 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ CHANGELOG for 3.X ================= * 3.2.0 (2017-04-xx) + * Allow to define excludes in the global scope. * Improve code quality, remove duplications on Symfony Tasks. * Improve code quality, remove duplications on Composer Tasks. * [PR#364] Allow to define custom timeout to Composer:Install diff --git a/src/Task/BuiltIn/Deploy/RsyncTask.php b/src/Task/BuiltIn/Deploy/RsyncTask.php index 1dce74e..57e1d0d 100644 --- a/src/Task/BuiltIn/Deploy/RsyncTask.php +++ b/src/Task/BuiltIn/Deploy/RsyncTask.php @@ -54,7 +54,7 @@ class RsyncTask extends AbstractTask protected function getExcludes() { - $excludes = $this->runtime->getEnvOption('exclude', []); + $excludes = $this->runtime->getMergedOption('exclude', []); $excludes = array_merge(['.git'], array_filter($excludes)); foreach ($excludes as &$exclude) { diff --git a/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php b/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php index e694f8f..d982000 100644 --- a/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php +++ b/src/Task/BuiltIn/Deploy/Tar/PrepareTask.php @@ -51,7 +51,7 @@ class PrepareTask extends AbstractTask protected function getExcludes() { - $excludes = $this->runtime->getEnvOption('exclude', []); + $excludes = $this->runtime->getMergedOption('exclude', []); $excludes = array_merge(['.git'], array_filter($excludes)); foreach ($excludes as &$exclude) { diff --git a/tests/Command/BuiltIn/DeployCommandMiscTasksTest.php b/tests/Command/BuiltIn/DeployCommandMiscTasksTest.php index ae13f8b..c8be597 100644 --- a/tests/Command/BuiltIn/DeployCommandMiscTasksTest.php +++ b/tests/Command/BuiltIn/DeployCommandMiscTasksTest.php @@ -80,6 +80,36 @@ class DeployCommandMiscTasksTest extends TestCase $this->assertEquals(0, $tester->getStatusCode()); } + public function testGlobalExcludeFlags() + { + $application = new MageApplicationMockup(__DIR__ . '/../../Resources/global-exclude.yml'); + + /** @var AbstractCommand $command */ + $command = $application->find('deploy'); + $this->assertTrue($command instanceof DeployCommand); + + $tester = new CommandTester($command); + $tester->execute(['command' => $command->getName(), 'environment' => 'test']); + + $ranCommands = $application->getRuntime()->getRanCommands(); + + $testCase = array( + 0 => '/usr/bin/composer.phar install --prefer-source', + 1 => '/usr/bin/composer.phar dump-autoload --no-scripts', + 2 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test', + ); + + // Check total of Executed Commands + $this->assertEquals(count($testCase), count($ranCommands)); + + // Check Generated Commands + foreach ($testCase as $index => $command) { + $this->assertEquals($command, $ranCommands[$index]); + } + + $this->assertEquals(0, $tester->getStatusCode()); + } + public function testComposerEnvFlags() { $application = new MageApplicationMockup(__DIR__ . '/../../Resources/composer-env.yml'); diff --git a/tests/Resources/global-exclude.yml b/tests/Resources/global-exclude.yml new file mode 100644 index 0000000..cfa5ddf --- /dev/null +++ b/tests/Resources/global-exclude.yml @@ -0,0 +1,17 @@ +magephp: + log_dir: /tmp + composer: + path: /usr/bin/composer.phar + exclude: + - ./var/cache/* + - ./var/log/* + - ./web/app_dev.php + environments: + test: + user: tester + host_path: /var/www/test + hosts: + - testhost + pre-deploy: + - composer/install: { flags: '--prefer-source' } + - composer/dump-autoload: { flags: '--no-scripts' }