|
1
|
|
|
<?php |
|
2
|
|
|
/* (c) Anton Medvedev <[email protected]> |
|
3
|
|
|
* |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Deployer\Console; |
|
9
|
|
|
|
|
10
|
|
|
use Deployer\Deployer; |
|
11
|
|
|
use Deployer\Executor\ExecutorInterface; |
|
12
|
|
|
use Deployer\Executor\ParallelExecutor; |
|
13
|
|
|
use Deployer\Executor\SeriesExecutor; |
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface as Input; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption as Option; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface as Output; |
|
18
|
|
|
|
|
19
|
|
|
class TaskCommand extends Command |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Deployer |
|
23
|
|
|
*/ |
|
24
|
|
|
private $deployer; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ExecutorInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
public $executor; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $name |
|
33
|
|
|
* @param string $description |
|
34
|
|
|
* @param Deployer $deployer |
|
35
|
|
|
*/ |
|
36
|
14 |
|
public function __construct($name, $description, Deployer $deployer) |
|
37
|
|
|
{ |
|
38
|
14 |
|
parent::__construct($name); |
|
39
|
14 |
|
$this->setDescription($description); |
|
40
|
14 |
|
$this->deployer = $deployer; |
|
41
|
14 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Configures the command |
|
45
|
|
|
*/ |
|
46
|
14 |
|
protected function configure() |
|
47
|
|
|
{ |
|
48
|
14 |
|
$this->addOption( |
|
49
|
14 |
|
'parallel', |
|
50
|
14 |
|
'p', |
|
51
|
14 |
|
Option::VALUE_NONE, |
|
52
|
|
|
'Run tests in parallel.' |
|
53
|
14 |
|
); |
|
54
|
14 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
14 |
|
protected function execute(Input $input, Output $output) |
|
60
|
|
|
{ |
|
61
|
14 |
|
$tasks = []; |
|
62
|
14 |
|
foreach ($this->deployer->scenarios->get($this->getName())->getTasks() as $taskName) { |
|
63
|
14 |
|
$tasks[] = $this->deployer->tasks->get($taskName); |
|
64
|
14 |
|
} |
|
65
|
|
|
|
|
66
|
14 |
|
$stage = $input->hasArgument('stage') ? $input->getArgument('stage') : null; |
|
67
|
|
|
|
|
68
|
14 |
|
$servers = $this->deployer->getStageStrategy()->getServers($stage); |
|
69
|
|
|
|
|
70
|
14 |
|
$environments = iterator_to_array($this->deployer->environments); |
|
71
|
|
|
|
|
72
|
14 |
|
if (isset($this->executor)) { |
|
73
|
1 |
|
$executor = $this->executor; |
|
74
|
1 |
|
} else { |
|
75
|
14 |
|
if ($input->getOption('parallel')) { |
|
76
|
2 |
|
$executor = new ParallelExecutor($this->deployer->getConsole()->getUserDefinition()); |
|
77
|
2 |
|
} else { |
|
78
|
11 |
|
$executor = new SeriesExecutor(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
14 |
|
$executor->run($tasks, $servers, $environments, $input, $output); |
|
83
|
14 |
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|