-
Notifications
You must be signed in to change notification settings - Fork 164
/
PrepareTask.php
70 lines (57 loc) · 2 KB
/
PrepareTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Task\BuiltIn\Deploy\Tar;
use Mage\Task\Exception\ErrorException;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
/**
* Tar Task - Create temporal Tar
*
* @author Andrés Montañez <andresmontanez@gmail.com>
*/
class PrepareTask extends AbstractTask
{
public function getName()
{
return 'deploy/tar/prepare';
}
public function getDescription()
{
return '[Deploy] Preparing Tar file';
}
public function execute()
{
if (!$this->runtime->getEnvOption('releases', false)) {
throw new ErrorException('This task is only available with releases enabled', 40);
}
$tarLocal = $this->runtime->getTempFile();
$this->runtime->setVar('tar_local', $tarLocal);
$excludes = $this->getExcludes();
$tarPath = $this->runtime->getEnvOption('tar_create_path', 'tar');
$flags = $this->runtime->getEnvOption('tar_create', $this->runtime->isWindows() ? '--force-local -c -z -p -f' : 'cfzp');
$from = $this->runtime->getEnvOption('from', './');
if ($this->runtime->getEnvOption('copyDirectory', false)) {
$from = sprintf('-C %s ./', $from);
}
$cmdTar = sprintf('%s %s %s %s %s', $tarPath, $flags, $tarLocal, $excludes, $from);
/** @var Process $process */
$process = $this->runtime->runLocalCommand($cmdTar, 300);
return $process->isSuccessful();
}
protected function getExcludes()
{
$excludes = $this->runtime->getMergedOption('exclude', []);
$excludes = array_merge(['.git'], array_filter($excludes));
foreach ($excludes as &$exclude) {
$exclude = '--exclude="' . $exclude . '"';
}
return implode(' ', $excludes);
}
}