Change Deploy Stages with Constants.

This commit is contained in:
Andrés Montañez 2013-12-15 17:11:53 -02:00
parent d55e18b34b
commit eecf9bf4ea
4 changed files with 22 additions and 15 deletions

View file

@ -13,6 +13,7 @@ namespace Mage\Command\BuiltIn;
use Mage\Command\AbstractCommand;
use Mage\Command\RequiresEnvironment;
use Mage\Task\Factory;
use Mage\Task\AbstractTask;
use Mage\Task\Releases\SkipOnOverride;
use Mage\Task\ErrorWithMessageException;
use Mage\Task\SkipException;
@ -141,7 +142,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$this->startTime = time();
// Run Pre-Deployment Tasks
$this->runNonDeploymentTasks('pre-deploy', $this->getConfig(), 'Pre-Deployment');
$this->runNonDeploymentTasks(AbstractTask::STAGE_PRE_DEPLOY, $this->getConfig(), 'Pre-Deployment');
// Check Status
if (self::$failedTasks > 0) {
@ -159,7 +160,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
}
// Run Post-Deployment Tasks
$this->runNonDeploymentTasks('post-deploy', $this->getConfig(), 'Post-Deployment');
$this->runNonDeploymentTasks(AbstractTask::STAGE_POST_DEPLOY, $this->getConfig(), 'Post-Deployment');
}
// Time Information Hosts
@ -197,7 +198,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
self::$failedTasks = 0;
// PreDeployment Hook
if ($stage == 'pre-deploy') {
if ($stage == AbstractTask::STAGE_PRE_DEPLOY) {
// Look for Remote Source
if (is_array($config->deployment('source', null))) {
array_unshift($tasksToRun, 'scm/clone');
@ -210,7 +211,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
}
// PostDeployment Hook
if ($stage == 'post-deploy') {
if ($stage == AbstractTask::STAGE_POST_DEPLOY) {
// If Deploy failed, clear post deploy tasks
if (self::$deployStatus == self::FAILED) {
$tasksToRun = array();
@ -328,7 +329,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
} else {
foreach ($tasksToRun as $taskData) {
$tasks++;
$task = Factory::get($taskData, $this->getConfig(), false, 'deploy');
$task = Factory::get($taskData, $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
if ($this->runTask($task)) {
$completedTasks++;
@ -374,7 +375,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$this->getConfig()->setHost($host);
$this->getConfig()->setHostConfig($hostConfig);
$task = Factory::get('deployment/release', $this->getConfig(), false, 'deploy');
$task = Factory::get('deployment/release', $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
if ($this->runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
$completedTasks++;
@ -399,7 +400,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
$this->getConfig()->setHost($host);
$this->getConfig()->setHostConfig($hostConfig);
$tasksToRun = $this->getConfig()->getTasks('post-release');
$tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_RELEASE);
$tasks = count($tasksToRun);
$completedTasks = 0;
@ -407,7 +408,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
foreach ($tasksToRun as $task) {
$task = Factory::get($task, $this->getConfig(), false, 'post-release');
$task = Factory::get($task, $this->getConfig(), false, AbstractTask::STAGE_POST_RELEASE);
if ($this->runTask($task)) {
$completedTasks++;

View file

@ -235,20 +235,26 @@ class Config
* @param string $stage
* @return array
*/
public function getTasks($stage = 'on-deploy')
public function getTasks($stage = 'deploy')
{
if ($stage == 'deploy') {
$configStage = 'on-deploy';
} else {
$configStage = $stage;
}
$tasks = array();
$config = $this->getEnvironmentOption('tasks', array());
// Host Config
if (is_array($this->hostConfig) && isset($this->hostConfig['tasks'])) {
if (isset($this->hostConfig['tasks'][$stage])) {
$config[$stage] = $this->hostConfig['tasks'][$stage];
if (isset($this->hostConfig['tasks'][$configStage])) {
$config[$configStage] = $this->hostConfig['tasks'][$configStage];
}
}
if (isset($config[$stage])) {
$tasksData = ($config[$stage] ? (array) $config[$stage] : array());
if (isset($config[$configStage])) {
$tasksData = ($config[$configStage] ? (array) $config[$configStage] : array());
foreach ($tasksData as $taskName => $taskData) {
if (is_array($taskData)) {
;

View file

@ -207,7 +207,7 @@ abstract class AbstractTask
*/
protected final function runCommand($command, &$output = null)
{
if ($this->getStage() == 'deploy') {
if ($this->getStage() == self::STAGE_DEPLOY) {
return $this->runCommandRemote($command, $output);
} else {
return $this->runCommandLocal($command, $output);

View file

@ -112,7 +112,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
$this->getConfig()->setReleaseId($releaseId);
foreach ($tasksToRun as $taskData) {
$task = Factory::get($taskData, $this->getConfig(), true, 'deploy');
$task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_DEPLOY);
$task->init();
Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);