Allow to fail a task with a message via Mage_Task_ErrorWithMessageException

This commit is contained in:
Andrés Montañez 2013-11-02 19:14:52 -02:00
parent d5ebf6e6e3
commit fe60dfbdd4
4 changed files with 28 additions and 11 deletions

View file

@ -305,6 +305,10 @@ class Mage_Command_BuiltIn_Deploy
Mage_Console::output('<red>FAIL</red>', 0); Mage_Console::output('<red>FAIL</red>', 0);
$result = false; $result = false;
} }
} catch (Mage_Task_ErrorWithMessageException $e) {
Mage_Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
$result = false;
} catch (Mage_Task_SkipException $e) { } catch (Mage_Task_SkipException $e) {
Mage_Console::output('<yellow>SKIPPED</yellow>', 0); Mage_Console::output('<yellow>SKIPPED</yellow>', 0);
$result = true; $result = true;

View file

@ -2,7 +2,7 @@
class Mage_Task_BuiltIn_Scm_ChangeBranch class Mage_Task_BuiltIn_Scm_ChangeBranch
extends Mage_Task_TaskAbstract extends Mage_Task_TaskAbstract
{ {
protected static $_startingBranch = 'master'; protected static $startingBranch = 'master';
private $_name = 'SCM Changing branch [built-in]'; private $_name = 'SCM Changing branch [built-in]';
public function getName() public function getName()
@ -25,10 +25,11 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
public function run() public function run()
{ {
switch ($this->getConfig()->general('scm')) { $scmConfig = $this->getConfig()->general('scm', array());
switch ((isset($scmConfig['type']) ? $scmConfig['type'] : false)) {
case 'git': case 'git':
if ($this->getParameter('_changeBranchRevert', false)) { if ($this->getParameter('_changeBranchRevert', false)) {
$command = 'git checkout ' . self::$_startingBranch; $command = 'git checkout ' . self::$startingBranch;
$result = $this->_runLocalCommand($command); $result = $this->_runLocalCommand($command);
} else { } else {
@ -37,19 +38,25 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
$result = $this->_runLocalCommand($command, $currentBranch); $result = $this->_runLocalCommand($command, $currentBranch);
$scmData = $this->getConfig()->deployment('scm', false); $scmData = $this->getConfig()->deployment('scm', false);
if ($result && is_array($scmData) && isset($scmData['branch'])) {
$branch = $this->getParameter('branch', $scmData['branch']);
$command = 'git checkout ' . $branch;
$result = $this->_runLocalCommand($command);
self::$_startingBranch = $currentBranch; if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
$command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
$isBranchTracked = '';
$result = $this->_runLocalCommand($command, $isBranchTracked);
if ($isBranchTracked == '') {
throw new Mage_Task_ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
}
$branch = $this->getParameter('branch', $scmData['branch']);
$command = 'git checkout ' . $branch;
$result = $this->_runLocalCommand($command);
self::$startingBranch = $currentBranch;
} else { } else {
throw new Mage_Task_SkipException; throw new Mage_Task_SkipException;
} }
} }
break; break;
default: default:

View file

@ -0,0 +1,6 @@
<?php
class Mage_Task_ErrorWithMessageException
extends Exception
{
}

View file

@ -4,7 +4,7 @@ deployment:
from: ./ from: ./
to: /var/www/ to: /var/www/
scm: scm:
branch: master branch: master2
releases: releases:
enabled: true enabled: true
max: 5 max: 5