/** * Execute a the appropriate set of plugins for a given build stage. * @param array $config PHPCI configuration * @param string $stage * @return bool */ public function executePlugins(&$config, $stage) { $success = true; // Ignore any stages for which we don't have plugins set: if (!array_key_exists($stage, $config) || !is_array($config[$stage])) { return $success; } foreach ($config[$stage] as $plugin => $options) { $this->logger->log(Lang::get('running_plugin', $plugin)); // Try and execute it: if ($this->executePlugin($plugin, $options)) { // Execution was successful: $this->logger->logSuccess(Lang::get('plugin_success')); } elseif ($stage == 'setup') { // If we're in the "setup" stage, execution should not continue after // a plugin has failed: throw new \Exception('Plugin failed: ' . $plugin); } else { // If we're in the "test" stage and the plugin is not allowed to fail, // then mark the build as failed: if ($stage == 'test' && (!isset($options['allow_failures']) || !$options['allow_failures'])) { $success = false; } $this->logger->logFailure(Lang::get('plugin_failed')); } } return $success; }
/** * Execute a the appropriate set of plugins for a given build stage. * @param array $config PHPCI configuration * @param string $stage * @return bool */ public function executePlugins(&$config, $stage) { $success = true; // Ignore any stages for which we don't have plugins set: if (!array_key_exists($stage, $config) || !is_array($config[$stage])) { return $success; } foreach ($config[$stage] as $plugin => $options) { $this->logger->log('RUNNING PLUGIN: ' . $plugin); // Is this plugin allowed to fail? if ($stage == 'test' && !isset($options['allow_failures'])) { $options['allow_failures'] = false; } // Try and execute it: if ($this->executePlugin($plugin, $options)) { // Execution was successful: $this->logger->logSuccess('PLUGIN STATUS: SUCCESS!'); } else { // If we're in the "test" stage and the plugin is not allowed to fail, // then mark the build as failed: if ($stage == 'test' && !$options['allow_failures']) { $success = false; } $this->logger->logFailure('PLUGIN STATUS: FAILED'); } } return $success; }
public function testLog_AddsBuildToContext() { $level = LogLevel::NOTICE; $message = "Testing"; $contextIn = array(); $expectedContext = array('build' => $this->mockBuild->reveal()); $this->mockLogger->log($level, $message, $expectedContext)->shouldBeCalledTimes(1); $this->testedBuildLogger->log($message, $level, $contextIn); }
/** * Execute the list of plugins found for a given testing stage. * @param $plugins * @param $stage * @return bool * @throws \Exception */ protected function doExecutePlugins(&$plugins, $stage) { $success = true; foreach ($plugins as $plugin => $options) { $this->logger->log(Lang::get('running_plugin', $plugin)); $this->setPluginStatus($stage, $plugin, Build::STATUS_RUNNING); // Try and execute it if ($this->executePlugin($plugin, $options)) { // Execution was successful $this->logger->logSuccess(Lang::get('plugin_success')); $this->setPluginStatus($stage, $plugin, Build::STATUS_SUCCESS); } else { // Execution failed $this->logger->logFailure(Lang::get('plugin_failed')); $this->setPluginStatus($stage, $plugin, Build::STATUS_FAILED); if ($stage === 'setup') { // If we're in the "setup" stage, execution should not continue after // a plugin has failed: throw new Exception('Plugin failed: ' . $plugin); } elseif ($stage === 'test') { // If we're in the "test" stage and the plugin is not allowed to fail, // then mark the build as failed: if (empty($options['allow_failures'])) { $success = false; } } } } return $success; }
/** * Find a binary required by a plugin. * @param string $binary * @param null $buildPath * @return null|string */ public function findBinary($binary, $buildPath = null) { $binaryPath = null; $composerBin = $this->getComposerBinDir(realpath($buildPath)); if (is_string($binary)) { $binary = array($binary); } foreach ($binary as $bin) { $this->logger->log("Looking for binary: " . $bin, LogLevel::DEBUG); if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) { $this->logger->log("Found in " . $composerBin . ": " . $bin, LogLevel::DEBUG); $binaryPath = $composerBin . '/' . $bin; break; } if (is_file($this->rootDir . $bin)) { $this->logger->log("Found in root: " . $bin, LogLevel::DEBUG); $binaryPath = $this->rootDir . $bin; break; } if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { $this->logger->log("Found in vendor/bin: " . $bin, LogLevel::DEBUG); $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; break; } $findCmdResult = $this->findGlobalBinary($bin); if (is_file($findCmdResult)) { $this->logger->log("Found in " . $findCmdResult, LogLevel::DEBUG); $binaryPath = $findCmdResult; break; } } return $binaryPath; }
/** * Find a binary required by a plugin. * @param string $binary * @param null $buildPath * @return null|string */ public function findBinary($binary, $buildPath = null) { $binaryPath = null; $composerBin = $this->getComposerBinDir(realpath($buildPath)); if (is_string($binary)) { $binary = array($binary); } foreach ($binary as $bin) { $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG); if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) { $this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG); $binaryPath = $composerBin . '/' . $bin; break; } if (is_file($this->rootDir . $bin)) { $this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG); $binaryPath = $this->rootDir . $bin; break; } if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { $this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG); $binaryPath = $this->rootDir . 'vendor/bin/' . $bin; break; } $findCmdResult = $this->findGlobalBinary($bin); if (is_file($findCmdResult)) { $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG); $binaryPath = $findCmdResult; break; } } return $binaryPath; }
/** * Find a binary required by a plugin. * @param string $binary * @param bool $quiet * @return null|string */ public function findBinary($binary, $quiet = false, $options = array()) { $composerBin = $this->getComposerBinDir(realpath($this->buildPath)); if (is_string($binary)) { $binary = array($binary); } //Set default binary paths $binPaths = array($composerBin . '/', $this->rootDir, $this->rootDir . 'vendor/bin/'); if (!empty($options['path'])) { $binPaths[] = $options['path'] . '/'; $binPaths[] = $this->rootDir . $options['path'] . '/'; $binPaths[] = $this->buildPath . $options['path'] . '/'; } foreach ($binary as $bin) { $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG); foreach ($binPaths as $path) { if (is_dir($path) && is_file($path . $bin)) { $this->logger->log(Lang::get('found_in_path', $path, $bin), LogLevel::DEBUG); return $path . $bin; } } $findCmdResult = $this->findGlobalBinary($bin); if (is_file($findCmdResult)) { $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG); return $findCmdResult; } } if ($quiet) { return; } throw new Exception(Lang::get('could_not_find', implode('/', $binary))); }
/** * Find a binary required by a plugin. * @param string $binary * @param bool $quiet * @return null|string */ public function findBinary($binary, $quiet = false) { $composerBin = $this->getComposerBinDir(realpath($this->buildPath)); if (is_string($binary)) { $binary = array($binary); } foreach ($binary as $bin) { $this->logger->log(Lang::get('looking_for_binary', $bin), LogLevel::DEBUG); if (is_dir($composerBin) && is_file($composerBin . '/' . $bin)) { $this->logger->log(Lang::get('found_in_path', $composerBin, $bin), LogLevel::DEBUG); return $composerBin . '/' . $bin; } if (is_file($this->rootDir . $bin)) { $this->logger->log(Lang::get('found_in_path', 'root', $bin), LogLevel::DEBUG); return $this->rootDir . $bin; } if (is_file($this->rootDir . 'vendor/bin/' . $bin)) { $this->logger->log(Lang::get('found_in_path', 'vendor/bin', $bin), LogLevel::DEBUG); return $this->rootDir . 'vendor/bin/' . $bin; } $findCmdResult = $this->findGlobalBinary($bin); if (is_file($findCmdResult)) { $this->logger->log(Lang::get('found_in_path', '', $bin), LogLevel::DEBUG); return $findCmdResult; } } if ($quiet) { return; } throw new Exception(Lang::get('could_not_find', implode('/', $binary))); }
/** * Write to the build log. * @param $message * @param string $level * @param array $context */ public function log($message, $level = LogLevel::INFO, $context = array()) { $this->buildLogger->log($message, $level, $context); }