Change SCM configs.

This commit is contained in:
Andrés Montañez 2013-07-06 20:46:19 -03:00
parent 6015b6d7c1
commit 39b1bf7cd5
6 changed files with 38 additions and 99 deletions

View file

@ -167,7 +167,8 @@ class Mage_Command_BuiltIn_Deploy
if ($stage == 'post-deploy') { if ($stage == 'post-deploy') {
// Change Branch Back // Change Branch Back
if ($this->getConfig()->deployment('scm', false)) { if ($this->getConfig()->deployment('scm', false)) {
array_unshift($tasksToRun, 'scm/change-branch-back'); array_unshift($tasksToRun, 'scm/change-branch');
$config->addParameter('_changeBranchRevert');
} }
// Remove Remote Source // Remove Remote Source

View file

@ -8,7 +8,6 @@ class Mage_Config
private $_releaseId = null; private $_releaseId = null;
private $_config = array( private $_config = array(
'general' => array(), 'general' => array(),
'scm' => array(),
'environment' => array(), 'environment' => array(),
); );
@ -78,6 +77,16 @@ class Mage_Config
return $this->_parameters; return $this->_parameters;
} }
/**
* Adds (or replaces) a parameter
* @param string $name
* @param mixed $value
*/
public function addParameter($name, $value = true)
{
$this->_parameters[$name] = $value;
}
/** /**
* Returns the Current environment * Returns the Current environment
* *
@ -218,27 +227,6 @@ class Mage_Config
} }
} }
/**
* Gets SCM Configuration
*
* @param string $option
* @param string $default
* @return mixed
*/
public function scm($option, $default = false)
{
$config = $this->_config['scm'];
if (isset($config[$option])) {
if (is_array($default) && ($config[$option] == '')) {
return $default;
} else {
return $config[$option];
}
} else {
return $default;
}
}
/** /**
* Get deployment configuration * Get deployment configuration
* *
@ -354,16 +342,6 @@ class Mage_Config
} }
} }
/**
* Loads the SCM Configuration
*/
private function _loadSCM()
{
if (file_exists('.mage/config/scm.yml')) {
$this->_config['scm'] = spyc_load_file('.mage/config/scm.yml');
}
}
/** /**
* Loads the Environment configuration * Loads the Environment configuration
* *

View file

@ -2,6 +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';
private $_name = 'SCM Changing branch [built-in]'; private $_name = 'SCM Changing branch [built-in]';
public function getName() public function getName()
@ -11,7 +12,7 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
public function init() public function init()
{ {
switch ($this->getConfig()->scm('type')) { switch ($this->getConfig()->general('scm')) {
case 'git': case 'git':
$this->_name = 'SCM Changing branch (GIT) [built-in]'; $this->_name = 'SCM Changing branch (GIT) [built-in]';
break; break;
@ -24,29 +25,35 @@ class Mage_Task_BuiltIn_Scm_ChangeBranch
public function run() public function run()
{ {
switch ($this->getConfig()->scm('type')) { switch ($this->getConfig()->general('scm')) {
case 'git': case 'git':
$command = 'git branch | grep \'*\' | cut -d\' \' -f 2'; if ($this->getParameter('_changeBranchRevert', false)) {
$currentBranch = 'master'; $command = 'git checkout ' . self::$_startingBranch;
$result = $this->_runLocalCommand($command, $currentBranch); $result = $this->_runLocalCommand($command);
$scmData = $this->getConfig()->deployment('scm', false); } else {
if ($result && is_array($scmData) && isset($scmData['branch'])) { $command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
$branch = $this->getParameter('branch', $scmData['branch']); $currentBranch = 'master';
$command = 'git checkout ' . $branch; $result = $this->_runLocalCommand($command, $currentBranch);
$result = $this->_runLocalCommand($command);
$oldBranchFile = '.mage/' . $this->getConfig()->getEnvironment() . '.oldBranch'; $scmData = $this->getConfig()->deployment('scm', false);
file_put_contents($oldBranchFile, $currentBranch); 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;
} else {
throw new Mage_Task_SkipException;
}
}
} else {
throw new Mage_Task_SkipException;
}
break; break;
default: default:
return false; throw new Mage_Task_SkipException;
break; break;
} }

View file

@ -1,47 +0,0 @@
<?php
class Mage_Task_BuiltIn_Scm_ChangeBranchBack
extends Mage_Task_TaskAbstract
{
private $_name = 'SCM Changing branch Back [built-in]';
public function getName()
{
return $this->_name;
}
public function init()
{
switch ($this->getConfig()->scm('type')) {
case 'git':
$this->_name = 'SCM Changing branch Back (GIT) [built-in]';
break;
case 'svn':
$this->_name = 'SCM Changing branch Back (Subversion) [built-in]';
break;
}
}
public function run()
{
switch ($this->getConfig()->scm('type')) {
case 'git':
$oldBranchFile = '.mage/' . $this->getConfig()->getEnvironment() . '.oldBranch';
$currentBranch = trim(file_get_contents($oldBranchFile));
$command = 'git checkout ' . $currentBranch;
$result = $this->_runLocalCommand($command);
@unlink($oldBranchFile);
break;
default:
return false;
break;
}
$this->getConfig()->reload();
return $result;
}
}

View file

@ -43,7 +43,7 @@ class Mage_Task_BuiltIn_Scm_Clone
break; break;
case 'svn': case 'svn':
return false; throw new Mage_Task_SkipException;
break; break;
} }

View file

@ -11,7 +11,7 @@ class Mage_Task_BuiltIn_Scm_Update
public function init() public function init()
{ {
switch ($this->getConfig()->scm('type')) { switch ($this->getConfig()->general('scm')) {
case 'git': case 'git':
$this->_name = 'SCM Update (GIT) [built-in]'; $this->_name = 'SCM Update (GIT) [built-in]';
break; break;
@ -34,7 +34,7 @@ class Mage_Task_BuiltIn_Scm_Update
break; break;
default: default:
return false; throw new Mage_Task_SkipException;
break; break;
} }