|
|
|
@ -90,6 +90,10 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
|
|
|
|
|
|
|
|
|
|
$result = $this->runCommandRemote($command); |
|
|
|
|
|
|
|
|
|
if ($result) { |
|
|
|
|
$this->cleanUpReleases(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $result; |
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
@ -97,4 +101,44 @@ class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Removes old releases |
|
|
|
|
*/ |
|
|
|
|
protected function cleanUpReleases() |
|
|
|
|
{ |
|
|
|
|
// Count Releases |
|
|
|
|
if ($this->getConfig()->release('enabled', false) == true) { |
|
|
|
|
$releasesDirectory = $this->getConfig()->release('directory', 'releases'); |
|
|
|
|
$symlink = $this->getConfig()->release('symlink', 'current'); |
|
|
|
|
|
|
|
|
|
if (substr($symlink, 0, 1) == '/') { |
|
|
|
|
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$maxReleases = $this->getConfig()->release('max', false); |
|
|
|
|
if (($maxReleases !== false) && ($maxReleases > 0)) { |
|
|
|
|
$releasesList = ''; |
|
|
|
|
$countReleasesFetch = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $releasesList); |
|
|
|
|
$releasesList = trim($releasesList); |
|
|
|
|
|
|
|
|
|
if ($countReleasesFetch && $releasesList != '') { |
|
|
|
|
$releasesList = explode(PHP_EOL, $releasesList); |
|
|
|
|
if (count($releasesList) > $maxReleases) { |
|
|
|
|
$releasesToDelete = array_diff($releasesList, array($this->getConfig()->getReleaseId())); |
|
|
|
|
sort($releasesToDelete); |
|
|
|
|
$releasesToDeleteCount = count($releasesToDelete) - $maxReleases; |
|
|
|
|
$releasesToDelete = array_slice($releasesToDelete, 0, $releasesToDeleteCount + 1); |
|
|
|
|
|
|
|
|
|
foreach ($releasesToDelete as $releaseIdToDelete) { |
|
|
|
|
$directoryToDelete = $releasesDirectory . '/' . $releaseIdToDelete; |
|
|
|
|
if ($directoryToDelete != '/') { |
|
|
|
|
$command = 'rm -rf ' . $directoryToDelete; |
|
|
|
|
$this->runCommandRemote($command); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|