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') {
// Change Branch Back
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

View file

@ -8,7 +8,6 @@ class Mage_Config
private $_releaseId = null;
private $_config = array(
'general' => array(),
'scm' => array(),
'environment' => array(),
);
@ -78,6 +77,16 @@ class Mage_Config
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
*
@ -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
*
@ -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
*

View file

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

View file

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