mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-10 01:36:38 +02:00
Change Branch on pre-deployment.
This commit is contained in:
parent
c2a9bf0d62
commit
ca12e74a6d
|
@ -49,7 +49,7 @@ class Mage_Command_BuiltIn_Deploy
|
|||
|
||||
if (count($tasksToRun) == 0) {
|
||||
Mage_Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $config->getHost() . '</dark_gray> skipped!', 1, 3);
|
||||
Mage_Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> skipped!', 1, 3);
|
||||
|
||||
} else {
|
||||
foreach ($tasksToRun as $taskData) {
|
||||
|
@ -150,12 +150,29 @@ class Mage_Command_BuiltIn_Deploy
|
|||
{
|
||||
$tasksToRun = $config->getTasks($stage);
|
||||
|
||||
// Look for Remote Source
|
||||
if (is_array($this->_config->deployment('source', null))) {
|
||||
if ($stage == 'pre-deploy') {
|
||||
array_unshift($tasksToRun, 'scm/clone');
|
||||
} elseif ($stage == 'post-deploy') {
|
||||
array_unshift($tasksToRun, 'scm/remove-clone');
|
||||
// PreDeployment Hook
|
||||
if ($stage == 'pre-deploy') {
|
||||
// Look for Remote Source
|
||||
if (is_array($this->_config->deployment('source', null))) {
|
||||
array_unshift($tasksToRun, 'scm/clone');
|
||||
}
|
||||
|
||||
// Change Branch
|
||||
if ($this->getConfig()->deployment('scm', false)) {
|
||||
array_unshift($tasksToRun, 'scm/change-branch');
|
||||
}
|
||||
}
|
||||
|
||||
// PostDeployment Hook
|
||||
if ($stage == 'post-deploy') {
|
||||
// Change Branch Back
|
||||
if ($this->getConfig()->deployment('scm', false)) {
|
||||
array_unshift($tasksToRun, 'scm/change-branch-back');
|
||||
}
|
||||
|
||||
// Remove Remote Source
|
||||
if (is_array($this->_config->deployment('source', null))) {
|
||||
array_push($tasksToRun, 'scm/remove-clone');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
58
Mage/Task/BuiltIn/Scm/ChangeBranch.php
Normal file
58
Mage/Task/BuiltIn/Scm/ChangeBranch.php
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
class Mage_Task_BuiltIn_Scm_ChangeBranch
|
||||
extends Mage_Task_TaskAbstract
|
||||
{
|
||||
private $_name = 'SCM Changing branch [built-in]';
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
switch ($this->getConfig()->scm('type')) {
|
||||
case 'git':
|
||||
$this->_name = 'SCM Changing branch (GIT) [built-in]';
|
||||
break;
|
||||
|
||||
case 'svn':
|
||||
$this->_name = 'SCM Changing branch (Subversion) [built-in]';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
switch ($this->getConfig()->scm('type')) {
|
||||
case 'git':
|
||||
$command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
|
||||
$currentBranch = 'master';
|
||||
$result = $this->_runLocalCommand($command, $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);
|
||||
|
||||
$oldBranchFile = '.mage/' . $this->getConfig()->getEnvironment() . '.oldBranch';
|
||||
file_put_contents($oldBranchFile, $currentBranch);
|
||||
|
||||
} else {
|
||||
throw new Mage_Task_SkipException;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$this->getConfig()->reload();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
47
Mage/Task/BuiltIn/Scm/ChangeBranchBack.php
Normal file
47
Mage/Task/BuiltIn/Scm/ChangeBranchBack.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
|
@ -3,18 +3,20 @@ deployment:
|
|||
user: root
|
||||
from: ./
|
||||
to: /var/www/
|
||||
scm:
|
||||
branch: master
|
||||
releases:
|
||||
enabled: true
|
||||
max: 5
|
||||
symlink: current
|
||||
directory: releases
|
||||
hosts:
|
||||
- localhost
|
||||
- dbserver
|
||||
# - localhost
|
||||
# - dbserver
|
||||
tasks:
|
||||
pre-deploy:
|
||||
- sampleTask
|
||||
# - scm/update
|
||||
- scm/update
|
||||
on-deploy:
|
||||
- privileges
|
||||
- sampleTask
|
||||
|
|
Loading…
Reference in a new issue