|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHPCI - Continuous Integration for PHP. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright 2014, Block 8 Limited. |
|
6
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md |
|
7
|
|
|
* |
|
8
|
|
|
* @link https://www.phptesting.org/ |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace PHPCI\Command; |
|
12
|
|
|
|
|
13
|
|
|
use b8\Store\Factory; |
|
14
|
|
|
use Monolog\Logger; |
|
15
|
|
|
use PHPCI\Service\BuildService; |
|
16
|
|
|
use Symfony\Component\Console\Command\Command; |
|
17
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Re-runs the last run build. |
|
23
|
|
|
* |
|
24
|
|
|
* @author Dan Cryer <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class RebuildCommand extends Command |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var Logger |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $logger; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var OutputInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $output; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var bool |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $run; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var int |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $sleep; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param \Monolog\Logger $logger |
|
50
|
|
|
* @param string $name |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(Logger $logger, $name = null) |
|
53
|
|
|
{ |
|
54
|
|
|
parent::__construct($name); |
|
55
|
|
|
$this->logger = $logger; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function configure() |
|
59
|
|
|
{ |
|
60
|
|
|
$this |
|
61
|
|
|
->setName('phpci:rebuild') |
|
62
|
|
|
->setDescription('Re-runs the last run build.'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Loops through running. |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
69
|
|
|
{ |
|
70
|
|
|
$runner = new RunCommand($this->logger); |
|
71
|
|
|
$runner->setMaxBuilds(1); |
|
72
|
|
|
$runner->setDaemon(false); |
|
73
|
|
|
|
|
74
|
|
|
/** @var \PHPCI\Store\BuildStore $store */ |
|
75
|
|
|
$store = Factory::getStore('Build'); |
|
76
|
|
|
$service = new BuildService($store); |
|
77
|
|
|
|
|
78
|
|
|
$builds = $store->getLatestBuilds(null, 1); |
|
79
|
|
|
$lastBuild = array_shift($builds); |
|
80
|
|
|
$service->createDuplicateBuild($lastBuild); |
|
81
|
|
|
|
|
82
|
|
|
$runner->run(new ArgvInput(array()), $output); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Called when log entries are made in Builder / the plugins. |
|
87
|
|
|
* |
|
88
|
|
|
* @see \PHPCI\Builder::log() |
|
89
|
|
|
*/ |
|
90
|
|
|
public function logCallback($log) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->output->writeln($log); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|