diff --git a/recipe/common.php b/recipe/common.php index 3a793520..233b72db 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -16,6 +16,8 @@ set('writable_dirs', []); set('writable_use_sudo', true); // Using sudo in writable commands? set('http_user', null); set('composer_command', 'composer'); // Path to composer +set('clear_paths', []); // Relative path from deploy_path +set('clear_use_sudo', true); // Using sudo in clean commands? /** * Environment vars @@ -395,6 +397,18 @@ task('cleanup', function () { })->desc('Cleaning up old releases'); +/** + * Cleanup files and directories + */ +task('deploy:clean', function () { + $paths = get('clear_paths'); + $sudo = get('clear_use_sudo') ? 'sudo' : ''; + + foreach ($paths as $path) { + run("$sudo rm -rf {{deploy_path}}/$path"); + } + +})->desc('Cleaning up files and/or directories'); /** * Success message diff --git a/test/recipe/CommonTest.php b/test/recipe/CommonTest.php index 44a0d39b..1f57bdb3 100644 --- a/test/recipe/CommonTest.php +++ b/test/recipe/CommonTest.php @@ -134,6 +134,20 @@ class CommonTest extends RecipeTester $this->assertEquals(3, iterator_count($fi)); } + /** + * Test clean + */ + public function testClean() + { + set('clear_paths', ['current/app/README.md', 'current/app/tests']); + set('clear_use_sudo', false); + + $this->exec('deploy:clean'); + + $this->assertFileNotExists($this->getEnv('deploy_path') . '/current/app/README.md'); + $this->assertFileNotExists($this->getEnv('deploy_path') . '/current/app/tests'); + } + /** * @depends testCleanup */