deployer/recipe/deploy/cleanup.php
Anton Medvedev 29a643b623 v7
2020-05-16 18:02:17 +03:00

32 lines
725 B
PHP

<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
desc('Cleaning up old releases');
task('deploy:cleanup', function () {
$releases = get('releases_list');
$keep = get('keep_releases');
$runOpts = [];
if ($keep === -1) {
// Keep unlimited releases.
return;
}
while ($keep > 0) {
array_shift($releases);
--$keep;
}
foreach ($releases as $release) {
run("rm -rf {{deploy_path}}/releases/$release", $runOpts);
}
run("cd {{deploy_path}} && if [ -e release ]; then rm release; fi", $runOpts);
});