mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-06-20 22:45:05 +02:00
Allow to fail a task with a message via Mage_Task_ErrorWithMessageException
This commit is contained in:
parent
d5ebf6e6e3
commit
fe60dfbdd4
|
@ -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;
|
||||||
|
|
|
@ -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:
|
||||||
|
|
6
Mage/Task/ErrorWithMessageException.php
Normal file
6
Mage/Task/ErrorWithMessageException.php
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
class Mage_Task_ErrorWithMessageException
|
||||||
|
extends Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue