mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-09-13 12:40:18 +02:00
Implement releases in git-rebase
Note: the parameter repository needs to be set to make this work.
This commit is contained in:
parent
ec29aa37b8
commit
014d98bc96
@ -214,4 +214,22 @@ abstract class AbstractTask
|
|||||||
return $this->runCommandLocal($command, $output);
|
return $this->runCommandLocal($command, $output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* adds a cd to the needed release if we work with releases.
|
||||||
|
*
|
||||||
|
* @param string $command
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getReleasesAwareCommand($command)
|
||||||
|
{
|
||||||
|
if ($this->getConfig()->release('enabled', false) == true) {
|
||||||
|
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
|
||||||
|
|
||||||
|
$deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
|
||||||
|
return 'cd ' . $deployToDirectory . ' && ' . $command;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $command;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ use Mage\Task\Releases\IsReleaseAware;
|
|||||||
*
|
*
|
||||||
* @author Oscar Reales <oreales@gmail.com>
|
* @author Oscar Reales <oreales@gmail.com>
|
||||||
*/
|
*/
|
||||||
class GitRebaseTask extends AbstractTask implements IsReleaseAware
|
class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* (non-PHPdoc)
|
* (non-PHPdoc)
|
||||||
* @see \Mage\Task\AbstractTask::getName()
|
* @see \Mage\Task\AbstractTask::getName()
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return 'Deploy via Git Rebase [built-in]';
|
return 'Deploy via Git Rebase [built-in]';
|
||||||
@ -35,41 +35,66 @@ class GitRebaseTask extends AbstractTask implements IsReleaseAware
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$branch = $this->getParameter('branch', 'master');
|
$this->checkOverrideRelease();
|
||||||
$remote = $this->getParameter('remote', 'origin');
|
$excludes = $this->getExcludes();
|
||||||
|
|
||||||
// Fetch Remote
|
// If we are working with releases
|
||||||
$command = 'git fetch ' . $remote;
|
$deployToDirectory = $this->getConfig()->deployment('to');
|
||||||
|
if ($this->getConfig()->release('enabled', false) == true) {
|
||||||
|
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
|
||||||
|
|
||||||
|
$deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
|
||||||
|
. '/' . $releasesDirectory
|
||||||
|
. '/' . $this->getConfig()->getReleaseId();
|
||||||
|
$this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$branch = $this->getParameter('branch', 'master');
|
||||||
|
$remote = $this->getParameter('remote', 'origin');
|
||||||
|
|
||||||
|
// Fetch Remote
|
||||||
|
$command = $this->getReleasesAwareCommand('git fetch ' . $remote);
|
||||||
$result = $this->runCommandRemote($command);
|
$result = $this->runCommandRemote($command);
|
||||||
|
|
||||||
|
if ($result === false) {
|
||||||
|
$repository = $this->getConfig()->deployment('repository');
|
||||||
|
if ($repository) {
|
||||||
|
$command = $this->getReleasesAwareCommand('git clone ' . $repository . ' .');
|
||||||
|
$result = $this->runCommandRemote($command);
|
||||||
|
|
||||||
|
$command = $this->getReleasesAwareCommand('git fetch ' . $remote);
|
||||||
|
$result = $this->runCommandRemote($command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checkout
|
// Checkout
|
||||||
$command = 'git checkout ' . $branch;
|
$command = $this->getReleasesAwareCommand('git checkout ' . $branch);
|
||||||
$result = $this->runCommandRemote($command) && $result;
|
$result = $this->runCommandRemote($command) && $result;
|
||||||
|
|
||||||
// Check Working Copy status
|
// Check Working Copy status
|
||||||
$stashed = false;
|
$stashed = false;
|
||||||
$status = '';
|
$status = '';
|
||||||
$command = 'git checkout ' . $branch;
|
$command = $this->getReleasesAwareCommand('git checkout ' . $branch);
|
||||||
$result = $this->runCommandRemote($command) && $result;
|
$result = $this->runCommandRemote($command) && $result;
|
||||||
|
|
||||||
// Stash if Working Copy is not clean
|
// Stash if Working Copy is not clean
|
||||||
if(!$status) {
|
if(!$status) {
|
||||||
$stashResult = '';
|
$stashResult = '';
|
||||||
$command = 'git stash';
|
$command = $this->getReleasesAwareCommand('git stash');
|
||||||
$result = $this->runCommandRemote($command, $stashResult) && $result;
|
$result = $this->runCommandRemote($command, $stashResult) && $result;
|
||||||
if($stashResult != "No local changes to save") {
|
if($stashResult != "No local changes to save") {
|
||||||
$stashed = true;
|
$stashed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebase
|
// Rebase
|
||||||
$command = 'git rebase ' . $remote . '/' . $branch;
|
$command = $this->getReleasesAwareCommand('git rebase ' . $remote . '/' . $branch);
|
||||||
$result = $this->runCommandRemote($command) && $result;
|
$result = $this->runCommandRemote($command) && $result;
|
||||||
|
|
||||||
// If Stashed, restore.
|
// If Stashed, restore.
|
||||||
if ($stashed) {
|
if ($stashed) {
|
||||||
$command = 'git stash pop';
|
$command = $this->getReleasesAwareCommand('git stash pop');
|
||||||
$result = $this->runCommandRemote($command) && $result;
|
$result = $this->runCommandRemote($command) && $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
Loading…
Reference in New Issue
Block a user