Adding a task to clean files and/or directoies

This commit is contained in:
oanhnn 2015-09-08 11:48:07 +07:00
parent 0d12b3b219
commit b36b1ede9c
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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
*/