2013-05-15 19:27:13 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://www.phptesting.org/
|
|
|
|
*/
|
2013-05-15 19:27:13 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Command;
|
|
|
|
|
2013-10-26 17:11:46 +02:00
|
|
|
use Monolog\Logger;
|
|
|
|
use PHPCI\Helper\BuildDBLogHandler;
|
2013-10-27 15:25:43 +01:00
|
|
|
use PHPCI\Helper\LoggedBuildContextTidier;
|
2013-10-26 17:11:46 +02:00
|
|
|
use PHPCI\Helper\OutputLogHandler;
|
|
|
|
use Psr\Log\LoggerAwareInterface;
|
2013-05-15 19:27:13 +02:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use b8\Store\Factory;
|
2013-05-16 16:14:10 +02:00
|
|
|
use PHPCI\Builder;
|
|
|
|
use PHPCI\BuildFactory;
|
2013-05-15 19:27:13 +02:00
|
|
|
|
2013-05-16 03:30:48 +02:00
|
|
|
/**
|
|
|
|
* Run console command - Runs any pending builds.
|
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Console
|
|
|
|
*/
|
2013-05-15 19:27:13 +02:00
|
|
|
class RunCommand extends Command
|
|
|
|
{
|
2013-10-27 15:26:37 +01:00
|
|
|
/**
|
|
|
|
* @var OutputInterface
|
|
|
|
*/
|
|
|
|
protected $output;
|
2013-10-26 17:11:46 +02:00
|
|
|
|
2013-05-15 19:27:13 +02:00
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('phpci:run-builds')
|
|
|
|
->setDescription('Run all pending PHPCI builds.');
|
|
|
|
}
|
|
|
|
|
2013-05-16 18:17:29 +02:00
|
|
|
/**
|
2013-10-27 15:26:37 +01:00
|
|
|
* Pulls all pending builds from the database and runs them.
|
|
|
|
*/
|
2013-05-15 19:27:13 +02:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$this->output = $output;
|
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
$logger = new Logger("BuildLog");
|
2013-10-26 17:11:46 +02:00
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
$store = Factory::getStore('Build');
|
2013-05-15 19:27:13 +02:00
|
|
|
$result = $store->getByStatus(0);
|
2013-06-09 18:42:50 +02:00
|
|
|
$builds = 0;
|
2013-05-15 19:27:13 +02:00
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
// For verbose mode we want to output all informational and above
|
|
|
|
// messages to the symphony output interface.
|
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
$logger->pushHandler(
|
|
|
|
new OutputLogHandler($this->output, Logger::INFO)
|
|
|
|
);
|
|
|
|
}
|
2013-10-26 17:11:46 +02:00
|
|
|
|
2013-10-27 15:25:43 +01:00
|
|
|
$logger->pushProcessor(new LoggedBuildContextTidier());
|
|
|
|
|
2013-05-16 16:14:10 +02:00
|
|
|
foreach ($result['items'] as $build) {
|
2013-06-09 18:42:50 +02:00
|
|
|
$builds++;
|
|
|
|
|
2013-05-16 00:47:37 +02:00
|
|
|
$build = BuildFactory::getBuild($build);
|
2013-06-09 18:42:50 +02:00
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
// Logging relevant to this build should be stored
|
|
|
|
// against the build itself.
|
|
|
|
$buildDbLog = new BuildDBLogHandler($build, Logger::INFO);
|
|
|
|
$logger->pushHandler($buildDbLog);
|
2013-06-09 18:42:50 +02:00
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
$builder = new Builder($build, $logger);
|
2013-05-15 19:27:13 +02:00
|
|
|
$builder->execute();
|
2013-10-26 17:11:46 +02:00
|
|
|
|
2013-10-27 15:26:37 +01:00
|
|
|
// After execution we no longer want to record the information
|
|
|
|
// back to this specific build so the handler should be removed.
|
|
|
|
$logger->popHandler($buildDbLog);
|
2013-05-15 19:27:13 +02:00
|
|
|
}
|
2013-06-09 18:42:50 +02:00
|
|
|
|
|
|
|
return $builds;
|
2013-05-15 19:27:13 +02:00
|
|
|
}
|
2013-05-16 16:14:10 +02:00
|
|
|
}
|