mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	Change Deploy Stages with Constants.
This commit is contained in:
		
							parent
							
								
									d55e18b34b
								
							
						
					
					
						commit
						eecf9bf4ea
					
				@ -13,6 +13,7 @@ namespace Mage\Command\BuiltIn;
 | 
				
			|||||||
use Mage\Command\AbstractCommand;
 | 
					use Mage\Command\AbstractCommand;
 | 
				
			||||||
use Mage\Command\RequiresEnvironment;
 | 
					use Mage\Command\RequiresEnvironment;
 | 
				
			||||||
use Mage\Task\Factory;
 | 
					use Mage\Task\Factory;
 | 
				
			||||||
 | 
					use Mage\Task\AbstractTask;
 | 
				
			||||||
use Mage\Task\Releases\SkipOnOverride;
 | 
					use Mage\Task\Releases\SkipOnOverride;
 | 
				
			||||||
use Mage\Task\ErrorWithMessageException;
 | 
					use Mage\Task\ErrorWithMessageException;
 | 
				
			||||||
use Mage\Task\SkipException;
 | 
					use Mage\Task\SkipException;
 | 
				
			||||||
@ -141,7 +142,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
        $this->startTime = time();
 | 
					        $this->startTime = time();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Run Pre-Deployment Tasks
 | 
					        // Run Pre-Deployment Tasks
 | 
				
			||||||
        $this->runNonDeploymentTasks('pre-deploy', $this->getConfig(), 'Pre-Deployment');
 | 
					        $this->runNonDeploymentTasks(AbstractTask::STAGE_PRE_DEPLOY, $this->getConfig(), 'Pre-Deployment');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Check Status
 | 
					        // Check Status
 | 
				
			||||||
        if (self::$failedTasks > 0) {
 | 
					        if (self::$failedTasks > 0) {
 | 
				
			||||||
@ -159,7 +160,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
        	}
 | 
					        	}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Run Post-Deployment Tasks
 | 
					        	// 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
 | 
					        // Time Information Hosts
 | 
				
			||||||
@ -197,7 +198,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
        self::$failedTasks = 0;
 | 
					        self::$failedTasks = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // PreDeployment Hook
 | 
					        // PreDeployment Hook
 | 
				
			||||||
        if ($stage == 'pre-deploy') {
 | 
					        if ($stage == AbstractTask::STAGE_PRE_DEPLOY) {
 | 
				
			||||||
        	// Look for Remote Source
 | 
					        	// Look for Remote Source
 | 
				
			||||||
        	if (is_array($config->deployment('source', null))) {
 | 
					        	if (is_array($config->deployment('source', null))) {
 | 
				
			||||||
        		array_unshift($tasksToRun, 'scm/clone');
 | 
					        		array_unshift($tasksToRun, 'scm/clone');
 | 
				
			||||||
@ -210,7 +211,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // PostDeployment Hook
 | 
					        // PostDeployment Hook
 | 
				
			||||||
        if ($stage == 'post-deploy') {
 | 
					        if ($stage == AbstractTask::STAGE_POST_DEPLOY) {
 | 
				
			||||||
        	// If Deploy failed, clear post deploy tasks
 | 
					        	// If Deploy failed, clear post deploy tasks
 | 
				
			||||||
        	if (self::$deployStatus == self::FAILED) {
 | 
					        	if (self::$deployStatus == self::FAILED) {
 | 
				
			||||||
        		$tasksToRun = array();
 | 
					        		$tasksToRun = array();
 | 
				
			||||||
@ -328,7 +329,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    			} else {
 | 
					    			} else {
 | 
				
			||||||
    				foreach ($tasksToRun as $taskData) {
 | 
					    				foreach ($tasksToRun as $taskData) {
 | 
				
			||||||
    					$tasks++;
 | 
					    					$tasks++;
 | 
				
			||||||
    					$task = Factory::get($taskData, $this->getConfig(), false, 'deploy');
 | 
					    					$task = Factory::get($taskData, $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    					if ($this->runTask($task)) {
 | 
					    					if ($this->runTask($task)) {
 | 
				
			||||||
    						$completedTasks++;
 | 
					    						$completedTasks++;
 | 
				
			||||||
@ -374,7 +375,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    				$this->getConfig()->setHost($host);
 | 
					    				$this->getConfig()->setHost($host);
 | 
				
			||||||
    				$this->getConfig()->setHostConfig($hostConfig);
 | 
					    				$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> ... ')) {
 | 
					    				if ($this->runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
 | 
				
			||||||
    					$completedTasks++;
 | 
					    					$completedTasks++;
 | 
				
			||||||
@ -399,7 +400,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    				$this->getConfig()->setHost($host);
 | 
					    				$this->getConfig()->setHost($host);
 | 
				
			||||||
    				$this->getConfig()->setHostConfig($hostConfig);
 | 
					    				$this->getConfig()->setHostConfig($hostConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				$tasksToRun = $this->getConfig()->getTasks('post-release');
 | 
					    				$tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_RELEASE);
 | 
				
			||||||
    				$tasks = count($tasksToRun);
 | 
					    				$tasks = count($tasksToRun);
 | 
				
			||||||
    				$completedTasks = 0;
 | 
					    				$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>:');
 | 
					    					Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    					foreach ($tasksToRun as $task) {
 | 
					    					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)) {
 | 
					    						if ($this->runTask($task)) {
 | 
				
			||||||
    							$completedTasks++;
 | 
					    							$completedTasks++;
 | 
				
			||||||
 | 
				
			|||||||
@ -235,20 +235,26 @@ class Config
 | 
				
			|||||||
     * @param string $stage
 | 
					     * @param string $stage
 | 
				
			||||||
     * @return array
 | 
					     * @return array
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getTasks($stage = 'on-deploy')
 | 
					    public function getTasks($stage = 'deploy')
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					    	if ($stage == 'deploy') {
 | 
				
			||||||
 | 
					    		$configStage = 'on-deploy';
 | 
				
			||||||
 | 
					    	} else {
 | 
				
			||||||
 | 
					    		$configStage = $stage;
 | 
				
			||||||
 | 
					    	}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $tasks = array();
 | 
					        $tasks = array();
 | 
				
			||||||
        $config = $this->getEnvironmentOption('tasks', array());
 | 
					        $config = $this->getEnvironmentOption('tasks', array());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Host Config
 | 
					        // Host Config
 | 
				
			||||||
        if (is_array($this->hostConfig) && isset($this->hostConfig['tasks'])) {
 | 
					        if (is_array($this->hostConfig) && isset($this->hostConfig['tasks'])) {
 | 
				
			||||||
        	if (isset($this->hostConfig['tasks'][$stage])) {
 | 
					        	if (isset($this->hostConfig['tasks'][$configStage])) {
 | 
				
			||||||
        		$config[$stage] = $this->hostConfig['tasks'][$stage];
 | 
					        		$config[$configStage] = $this->hostConfig['tasks'][$configStage];
 | 
				
			||||||
        	}
 | 
					        	}
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($config[$stage])) {
 | 
					        if (isset($config[$configStage])) {
 | 
				
			||||||
            $tasksData = ($config[$stage] ? (array) $config[$stage] : array());
 | 
					            $tasksData = ($config[$configStage] ? (array) $config[$configStage] : array());
 | 
				
			||||||
            foreach ($tasksData as $taskName => $taskData) {
 | 
					            foreach ($tasksData as $taskName => $taskData) {
 | 
				
			||||||
                if (is_array($taskData)) {
 | 
					                if (is_array($taskData)) {
 | 
				
			||||||
                    ;
 | 
					                    ;
 | 
				
			||||||
 | 
				
			|||||||
@ -207,7 +207,7 @@ abstract class AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected final function runCommand($command, &$output = null)
 | 
					    protected final function runCommand($command, &$output = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->getStage() == 'deploy') {
 | 
					        if ($this->getStage() == self::STAGE_DEPLOY) {
 | 
				
			||||||
        	return $this->runCommandRemote($command, $output);
 | 
					        	return $this->runCommandRemote($command, $output);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        	return $this->runCommandLocal($command, $output);
 | 
					        	return $this->runCommandLocal($command, $output);
 | 
				
			||||||
 | 
				
			|||||||
@ -112,7 +112,7 @@ class RollbackTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
                    $this->getConfig()->setReleaseId($releaseId);
 | 
					                    $this->getConfig()->setReleaseId($releaseId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    foreach ($tasksToRun as $taskData) {
 | 
					                    foreach ($tasksToRun as $taskData) {
 | 
				
			||||||
                        $task = Factory::get($taskData, $this->getConfig(), true, 'deploy');
 | 
					                        $task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_DEPLOY);
 | 
				
			||||||
                        $task->init();
 | 
					                        $task->init();
 | 
				
			||||||
                        Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
					                        Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user