From eecf9bf4ea5ddd41a8300c6370bf1cd53acbbf1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sun, 15 Dec 2013 17:11:53 -0200 Subject: [PATCH] Change Deploy Stages with Constants. --- Mage/Command/BuiltIn/DeployCommand.php | 17 +++++++++-------- Mage/Config.php | 16 +++++++++++----- Mage/Task/AbstractTask.php | 2 +- Mage/Task/BuiltIn/Releases/RollbackTask.php | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 58bf7e3..9c94f36 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -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 ' . $host . ' ... ')) { $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 Post-Release tasks for ' . $host . ':'); 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++; diff --git a/Mage/Config.php b/Mage/Config.php index c5706db..7d9b06a 100644 --- a/Mage/Config.php +++ b/Mage/Config.php @@ -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)) { ; diff --git a/Mage/Task/AbstractTask.php b/Mage/Task/AbstractTask.php index f17fc16..3f34b94 100644 --- a/Mage/Task/AbstractTask.php +++ b/Mage/Task/AbstractTask.php @@ -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); diff --git a/Mage/Task/BuiltIn/Releases/RollbackTask.php b/Mage/Task/BuiltIn/Releases/RollbackTask.php index 7f54bc1..e130d2e 100644 --- a/Mage/Task/BuiltIn/Releases/RollbackTask.php +++ b/Mage/Task/BuiltIn/Releases/RollbackTask.php @@ -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 ' . $task->getName() . ' ... ', 2, false);