diff --git a/recipe/common.php b/recipe/common.php index 81ccc5a5..3c57166b 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -15,6 +15,8 @@ set('copy_dirs', []); set('writable_dirs', []); set('writable_use_sudo', true); // Using sudo in writable commands? set('http_user', null); +set('clear_paths', []); // Relative path from deploy_path +set('clear_use_sudo', true); // Using sudo in clean commands? /** * Environment vars @@ -372,6 +374,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 e6f25229..e943c485 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 */